Jump to content

Ambient light shader


rob

Recommended Posts

Hi Mario,

you used vector n = normalize(N); in the occlusion shader and then in the hemisphere color shader you altered vector n to equal vector n = normalize(ntransform( "space:world",N)); . why does this have to change from the original vector n = normalize(N);. Now want to combine the occlusion with grnd /sky colors of course now n has a different value.

Edited by rob
Link to comment
Share on other sites

  • Replies 43
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

you used vector n = normalize(N); in the occlusion shader and then in the hemisphere color shader you altered vector n to equal vector n = normalize(ntransform( "space:world",N)); . why does this have to change from the original vector n = normalize(N);

It doesn't have to change. As I mentioned earlier, I just hijacked 'n' for my own evil purposes when computing the horizon stuff, without thinking, really. It was there, looking lonely; I was in a rush, so I used it. My bad. Apologies.

I'm tempted to just give you the two-line fix for that, but I get the feeling that doing so will just cause more confusion, so here's the whole horizon thing again, minus that goof.

#include <math.h>

#pragma label  htype "Horizon Type"
#pragma choice htype "lramp" "Linear Ramp"
#pragma choice htype "sramp" "Smooth Ramp"
#pragma choice htype "hard"  "Hard"
#pragma choice htype "soft"  "Soft"
#pragma label  hsoft "Horizon Softness"
#pragma range  hsoft 1e-4! 1!
#pragma disable hsoft htype "lramp"
#pragma disable hsoft htype "sramp"
#pragma disable hsoft htype "hard"

light rs_ambient_v02 (
         vector skycolor   = {1,0,0};
         vector grndcolor  = {0,0,1};
         string htype      = "soft";
         float  hsoft      = 0.2;
         float intensity   = 1;
         string env_map    = "Mandril.rat";
         string env_space  = "space:world";

   )
{
   vector n  = normalize(N);
   vector nw = ntransform("space:world",n); // <--- NEW WORLD-SPACE VERSION OF n

   float weight = 1.0 - acos(nw.y)/M_PI; // <--- WORLD-SPACE VERSION USED HERE
   float hw = weight;
   if(htype   == "sramp") {     // Smooth ramp
      hw = smooth(0,1,weight);
   } else if(htype   == "hard") {      // Hard edge
      hw = filterstep(0.5,weight);
   } else if(htype   == "soft") {      // Soft edge
      float halfinterval= clamp(hsoft*0.5,1e-4,0.5);
      hw = smooth(0.5-halfinterval,0.5+halfinterval,weight);
   }

   vector lightcolor = lerp(grndcolor,skycolor,hw);

   vector Cenv = 1;
   if(env_map!="") {
      string space = env_space=="" ? "space:world" : env_space;
      Cenv = environment(env_map,n,"envobject",space);
   }

   Cl = lightcolor*intensity*Cenv;
   L  = n; // <--- AS BEFORE
}

Now it leaves 'n' as it used to be, and uses a new variable 'nw' wherever a world-space version of 'n' is needed.

Untested... but it should work... I hope.

HTH.

Link to comment
Share on other sites

Hi Mario,

I have taken everything covered by you and expanded on the interface using the " pragma " operation and included custom icons and help. I guess the final thing to top off this shader would be to somehow implement a way of being able to export various parameters for use in compositing

As ever thanks so much for taking the time to expand everyones skills ..

Rob

rs_void_occlusion_hemis.otl

post-1566-1213880344_thumb.jpg

Edited by rob
Link to comment
Share on other sites

  • 3 weeks later...

It worked just great but now I m getting this error when I try to render it through mantra

Couldn't add library C:/Documents and Settings/ZOHAIB/ROBAO.otl

to Current HIP File.

Check that C:/Documents and Settings/ZOHAIB/ROBAO.otl is a valid operator type library.

Unable to get VEX code from:

opdef:/Shop/rs_void_occlusion_hemis

mantra: VEX error: Unable to load opdef:/Shop/rs_void_occlusion_hemis Path not found

Unable to get VEX code from:

opdef:/Shop/rs_void_occlusion_hemis

mantra: VEX error: Unable to load opdef:/Shop/rs_void_occlusion_hemis Path not found

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...