Alanw Posted June 1, 2009 Share Posted June 1, 2009 Hello, I've written a surface shader with various exports in an attempt to learn VEX / Mantra a little better. I feel like I'm very close to figuring this out, but I need your help. I want specular contribution written into an image plane for each individual light. (My HIP contains 1 red and 1 blue light) I incorporated the glossy spec function found in voplib.h to do this. // glossy specular float w = sharp / 2.0; float NdotL, spec; float NdotI = dot(Nn, V); vector illum = 0; if(NdotI > 0.0 && w < 0.5) { illuminance(PP, Nn, M_PI/2, LIGHT_SPECULAR) { vector Nl = normalize(L); NdotL = dot(Nn, Nl); if(NdotL > 0.0) { shadow(Cl); spec = specularBRDF(Nl, Nn, V, rough); if(w <= 0) illum += Cl * spec; else illum += Cl * smooth(w, 1-w, spec); } // assign specular export exp_spec = illum; } } This is what my Mantra ROP settings look like for this particular variable. In Houdini versions previous to 10.0 the Mantra ROP had 1 field with "Light Export" and an object selection widget. Now we have "light mask" and "light selection" to fill out which confuses me a bit. I looked through the docs, but this change wasn't recorded as they still only mention the "light export" field which no longer exists leaving the settings as they are above gives me 2 image planes. blue light (which looks as expected) and red, which seems to also incorporate my blue light.... why is this? Also, it looks like my specular image plane is missing all of my specular contribution. And finally, if I wanted to isolate the specular from within reflections. Is there a way to do this? I've attached my HIP with VFL source for my shader. Thanks! Alan images_planes.zip Quote Link to comment Share on other sites More sharing options...
crunch Posted June 1, 2009 Share Posted June 1, 2009 You are setting exp_spec to illum. illum is the summed illuminance. What you probably want is something like: // glossy specular illuminance(PP, Nn, M_PI/2, LIGHT_SPECULAR) { vector Nl = normalize(L); vector Cspec; NdotL = dot(Nn, Nl); if(NdotL > 0.0) { shadow(Cl); spec = specularBRDF(Nl, Nn, V, rough); if(w <= 0) Cspec = Cl * spec; else Cspec = Cl * smooth(w, 1-w, spec); illum += Cspec; } else Cspec = 0; // Make sure it's 0 when condition isn't true // assign specular export exp_spec = Cspec; } Quote Link to comment Share on other sites More sharing options...
Alanw Posted June 1, 2009 Author Share Posted June 1, 2009 (edited) You are setting exp_spec to illum. illum is the summed illuminance.What you probably want is something like: // glossy specular illuminance(PP, Nn, M_PI/2, LIGHT_SPECULAR) { vector Nl = normalize(L); vector Cspec; NdotL = dot(Nn, Nl); if(NdotL > 0.0) { shadow(Cl); spec = specularBRDF(Nl, Nn, V, rough); if(w <= 0) Cspec = Cl * spec; else Cspec = Cl * smooth(w, 1-w, spec); illum += Cspec; } else Cspec = 0; // Make sure it's 0 when condition isn't true // assign specular export exp_spec = Cspec; } Thanks Crunch, that fixes it. I see whats going on here now. The only part I'm having a little trouble wrapping my head around is why you must set Cpec to 0 if NdotL < 0.0. Isn't Cspec assumed zero since it wasn't assigned a value when declared? Edited June 2, 2009 by Alanw Quote Link to comment Share on other sites More sharing options...
Wolfwood Posted June 2, 2009 Share Posted June 2, 2009 Thanks Crunch, that fixes it. I see whats going on here now. The only part I'm having a little trouble wrapping my head around is why you must set Cpec to 0 if NdotL < 0.0. Isn't Cspec assumed zero since it wasn't assigned a value when declared? Nope. Uninitialize variables can be any value. I've been bit so many times by this I always explicitly set a value when declaring variables. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.