Texture lookup with uv on non bitmap textures?

Hello,

I am trying to write a BRDF, that depends on the uv coordinates. There is one case where the shader must be able to lookup the value for a certain parameter/attribute at a uv coordinate different from the uv coordinates of the point currently being evaluated.

I have seen the thread here on being able to sample a texture with uv coordinates as inputs, but, as I understand it, these textures must be bitmaps. But I would like to do this with any texture, is this possible?

Here is some more context.

In Maya, connecting an attribute to a checker texture gives the following in a .vrscene file


...
BRDFMyShader VRayMyShaderMtl1 {
  specular_strength=checker1@color::alpha;
}

TexChecker checker1 {
  compatibility_with=1;
  alpha_from_intensity=0;
  invert=0;
  color_mult=AColor(1, 1, 1, 1);
  color_offset=AColor(0, 0, 0, 1);
  alpha_mult=1;
  alpha_offset=0;
  nouvw_color=AColor(0.5, 0.5, 0.5, 1);
  uvwgen=place2dTexture1;
  white_color=AColor(1, 1, 1, 1);
  black_color=AColor(0, 0, 0, 1);
  contrast=1;
}
...

I currently get the texture and sample it at the current point like this.


...        

PluginBase *newPlug=param->getObject(i);
TextureInterface *newSub=static_cast<TextureInterface *>(GET_INTERFACE(newPlug, EXT_TEXTURE));

VR::VRayContext *rc = (VR::VRayContext *)context;

AColor col = newSub->getTexColor(*rc);

...

But getting an EXT_BITMAP interface for this texture does not work, presumably because it is not a bitmap… But that means I can not access the getFilteredColor function.
Is there perhaps a way to alter or create your own VRayContext instance and set its ShadingData to have a certain uv coordinate, which can then be passed to getTexColor?
(I have done something similar in VRay for 3dsmax where I created an instance of 3dsmax’s ShadeContext and modifying the uv coordinates. Then passing it to Texmap::EvalMono.)

Thank you very much for any help!
Kind Regards
Peter

Hello. I have still not been able to resolve this.
I thought I would just ask again in case there any tips or hints on where I could look.

Again, I want to be able to get a texture color at a uv coordinate different from the current point being evaluated, using the V-Ray API.

Thanks again for any help with this!

The way to do this is to replace temporarily the rc.rayresult.sd member of the ray context with a custom implementation that returns different UVs, like this:```
struct MyShadeData: public VRayShadeData, public MappedSurface {
VRayContext *rcc;
VRayShadeData *oldShadeData;
Vector uvw;

MyShadeData(const VRayContext &rc, const Vector &uvw):uvw(uvw) {
    oldShadeData=rc.rayresult.sd;
    rcc=const_cast<VRayContext*>(&rc);
    rcc->rayresult.sd=static_cast<VRayShadeData*>(this);
}

~MyShadeData() {
    rcc->rayresult.sd=oldShadeData;
}

PluginBase* getPlugin(void) VRAY_OVERRIDE { return (PluginBase*) this; }
PluginInterface* newInterface(InterfaceID id) VRAY_OVERRIDE {
    if (id==EXT_MAPPED_SURFACE) return static_cast<MappedSurface*>(this);
    return oldShadeData? oldShadeData->newInterface(id) : VRayShadeData::newInterface(id);
}

// From MappedSurface
Transform getLocalUVWTransform(const VR::VRayContext &rc, int channel) VRAY_OVERRIDE {
    bool valid=true;

    // Note that here we initialize the matrix to zero. This will effectively kill any
    // texture filtering. If you want texture filtering, you will need to come up with
    // a suitable way to initialize the Matrix portion of the transform to a matrix that
    // converts world-space changes in the shading point to changes in UVWs.
    Transform res(0);

    // Set the explicit UVWs
    res.offs=uvw;
    return res;
}

};

AColor MyTexture::getTexColor(const VRayContext &rc) {
// Compute some UVWs
Vector uvw=…;

// Replace the shade data in the ray context
{
    MyShadeData myShadeData(rc, uvw);

    // Evaluate any textures here; they will use the computed UVWs
    AColor texColor=(myTexture!=NULL)? myTexture->getTexColor(rc) : defaultTexColor;

    // Going out of this scope will call the destructor of myShadeData and
    // will restore the original shade data pointer in the ray context.
}

}


Best regards,
Vlado

Thank you very much! Exactly what I am after. Very helpful.

Best regards
Peter