SDK: Writing Specular/Diffuse Informations to render elements

Hi,

I am writing an own small shader to do some basic stuff and have one big problem.. I am calculation the diffuse, specular and ambient color in the eval() method and am returning the combined color.

That’s working fine and looks right, but as soon as I add some render-elements to get a specular pass for example, the result of my material looks wrong in this element.

But that’s right too, because how should VRay know about my specular-values? I am not passing them to VRay anywhere.. only the combined result color.

So, how can I tell VRay what color to use for the specular-element-pass?

Thanks,
Aya

V-Ray will automatically add the diffuse and specular results, but you must check the flags passed to BRDFSampler::eval() for the FBRDF_SPECULAR and FBRDF_DIFFUSE options, and just compute the required component.

Best regards,
Vlado

ah okay, thanks :slight_smile:

And is there a way to write something to an own render-element?
For example, create a render-element called “Fancy stuff” and have my material put some fancy stuff in there.. :wink:

Aya~

Yes, you can do that. When you create a V-Ray render element plugin, you need to define an “alias” for it; after that, in the traceForward() method of your BRDF, you can write to this element in the following way:```
VR::Fragment f=(VR::Fragment) rc.mtlresult.fragment;
if (f) {
VR::Color someColor(0.5f, 0.5f, 0.5f);
f->setChannelDataByAlias(myElementAlias, &someColor);
}

Best regards,
Vlado

Thanks a lot :slight_smile:

One last question… there’s an “VRay_SelfIllumination” RenderElement.. how can I write to this one?

Aya~

It should work if, in the code above, you replace “myElementAlias” with “REG_CHAN_VFB_SELFILLUM”.

Best regards,
Vlado

This is how my traceForward looks now:

void MyBaseBSDF::traceForward(VR::VRayContext &rc, int doDiffuse)
{
    VR::Fragment *f = (VR::Fragment*)rc.mtlresult.fragment;
    if (f) {
        VR::Color color(0.5f,0.5f,0.0f);
        f->setChannelDataByAlias(REG_CHAN_VFB_SELFILLUM, &color);
    }
}

But it’s not working.. the VRay_SelfIllumination is still black :frowning:
Do I have to call traceForward myself somewhere?

Aya~

If you put a breakpoint in the code, is it reached?

Best regards,
Vlado

umh, it was my fault.. forgot to assign the material xD

But do I need any special default implementation for the traceForward()?
Because if I just add the traceForward()-function in my code without anything in it:

void MyBaseBSDF::traceForward(VR::VRayContext &rc, int doDiffuse)
{
}

then my material looks a lot lighter (or transparent).. how comes this?

Aya~

Be sure to call the default implementation BRDFSampler::traceForward() before or after your code.

Best regards,
Vlado

Ah okay, it’s working now :slight_smile:
Thansk~