Jump to content

Mantra - per light exports


Recommended Posts

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.

image_planes.jpg

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)

obj_blue_spec.jpg

and red, which seems to also incorporate my blue light.... why is this?

obj_red_spec.jpg

Also, it looks like my specular image plane is missing all of my specular contribution.

specular_color.jpg

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

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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 by Alanw
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...