Accessing light shader parameters from a surface shader

Accessing light shader parameters from a surface shader

Post by Adam Buchbinde » Sat, 17 Feb 2001 08:38:05



How do I access a parameter (e.g., 'from') in a light source shader from my
surface shader? I'm manually ray-tracing some of my shadows, sort of, and
this
came up. Right now I'm just dropping it in as a parameter to the surface
shader, but this is cumbersome and... well, dumb. Does the answer involve an
illuminance loop?

My project is at

http://grendel.dyndns.org/before.jpg

and

http://grendel.dyndns.org/after.jpg

A note: The code for drawing the star on the ball is my own guess as to how
Pixar did it. Looking at the way they did, I see that my way is *completely*
different. But it still works remarkably closely...

Thanks for answering.

-adam buchbinder

 
 
 

Accessing light shader parameters from a surface shader

Post by Kevin Bjork » Sat, 17 Feb 2001 17:36:36


Leave "from" at the shader's (0,0,0) location to make this easier.

Pass a named CoordinateSystem that matches the light, and pass the name
of that CoordinateSystem as a light parameter, called, say, "CoordName"

TransformBegin
LightSource 1 "myLight" "string CoordName" "blah"
CoordinateSystem "blah"
TransformEnd

In the surface shader's illuminance loop, you can extract the value (if
any) if "CoordName," then use transform() to convert (0,0,0) from the
"CoordName" coordinate system into "current" or any other convenient
coordinate system. That will be the light's "from" point.

Now you can trace a vector from there to anywhere.....

---

Alternatively, you could do this in the light shader instead of the
surface, and the origin of "shader" space would suffice, while the
surface point will be called "Ps" (this is the method used in
"uberlight," as described in "Advanced Renderman")

 
 
 

Accessing light shader parameters from a surface shader

Post by Alex Sega » Sat, 17 Feb 2001 17:03:43


SL variable L can give you the "from" locaton...

--
Alex Segal. RMC Advertising
+7(3472) 52 59 66, 53 3133

SMS: http://www.r-m-c.ru/sms.asp?alex


Quote:> How do I access a parameter (e.g., 'from') in a light source shader from
my
> surface shader? I'm manually ray-tracing some of my shadows, sort of, and
> this
> came up. Right now I'm just dropping it in as a parameter to the surface
> shader, but this is cumbersome and... well, dumb. Does the answer involve
an
> illuminance loop?

> My project is at

> http://grendel.dyndns.org/before.jpg

> and

> http://grendel.dyndns.org/after.jpg

> A note: The code for drawing the star on the ball is my own guess as to
how
> Pixar did it. Looking at the way they did, I see that my way is
*completely*
> different. But it still works remarkably closely...

> Thanks for answering.

> -adam buchbinder

 
 
 

Accessing light shader parameters from a surface shader

Post by Adam Buchbinde » Sun, 18 Feb 2001 02:22:45


Quote:>SL variable L can give you the "from" locaton...

Hmm. Isn't L the vector from the light to the surface? But we know both in
the
shader... Hmm.

What I want to do is attenuate a value for every light *not* shining on it.

Pseudocode:

for (each light)
  if (!visibility(light_origin,P))
    C*=0.75;

So how do I do this in the illuminance loop? Should I just replace the 'for'
with the illuminance() loop? Is that how an illuminance() loop works?

-adam

------------------------------------------------------------
 Get your FREE web-based e-mail and newsgroup access at:
                http://MailAndNews.com

 Create a new mailbox, or access your existing IMAP4 or
 POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------

 
 
 

Accessing light shader parameters from a surface shader

Post by Larry Gri » Sun, 18 Feb 2001 02:32:45




Quote:

>What I want to do is attenuate a value for every light *not* shining on it.

>Pseudocode:

>for (each light)
>  if (!visibility(light_origin,P))
>    C*=0.75;

>So how do I do this in the illuminance loop? Should I just replace the 'for'
>with the illuminance() loop? Is that how an illuminance() loop works?

There's no reason to calculate shadows in the surface shader.  That
already happens in the light shader.  You just need to make that
information available.

Look at the uberlight source code.  I believe that it sets an output
variable called "inshadow" or some such.  If not, at least you can see
where such a factor is computed (and is used to mix between the lit
color and the "shadow color"), and you could easily add your own
inshadow output variable.

Then, in the surface shader, have an illuminance loop that looks
up the value of that output parameter using the lightsource()
function.  It's actually fairly straightforward.

           -- lg

--
Larry Gritz                                     Exluna

 
 
 

Accessing light shader parameters from a surface shader

Post by Kevin Bjork » Sun, 18 Feb 2001 03:09:52




> >SL variable L can give you the "from" locaton...

> Hmm. Isn't L the vector from the light to the surface? But we know both
> in
> the
> shader... Hmm.

It is, but I don't think L's magnitude is guaranteed.

Quote:> What I want to do is attenuate a value for every light *not* shining on
> it.

> Pseudocode:

> for (each light)
>   if (!visibility(light_origin,P))
>     C*=0.75;

> So how do I do this in the illuminance loop? Should I just replace the
> 'for'
> with the illuminance() loop? Is that how an illuminance() loop works?

normally, the implicit illuminance loop would exclude lights not FACING
the surface -- they never even get called. So you'd need to have an
illuminace loop with 360-degree (err, 2*PI) coverage.

As for direct visibility, just have the light shaders pass an
"__inShadow" value back to the surface shader, a la "uberlight" -- if
"__inShadow" is nonzero, then the light is obscured and you can do
whatever you like to it.

The surface shader may not be the best place for these operations,
however.

 
 
 

Accessing light shader parameters from a surface shader

Post by T. Burg » Sun, 18 Feb 2001 05:49:39



> for (each light)
>   if (!visibility(light_origin,P))
>     C*=0.75;

> So how do I do this in the illuminance loop? Should I just replace the 'for'
> with the illuminance() loop? Is that how an illuminance() loop works?

From your original post it sounds like you wanted to know how to do basic
message passing.  Refer to http://www.affine.org/lensflare.html which shows
how an include file can be setup in a light shader to give a surface shader
parameters sent from the light.  

Inside your illuminance loop do the following as shown in the shader example
link mentioned above:

   illuminance( P, vector "NDC" (0,0,1), PI ) {
.
.
.
      if ( lightsource( "GlowIntensity", GlowIntensity )!=0
           && GlowIntensity!=0.0 )
.
.
.

The lightsource() call gets you the data.  As for what you are trying to do
with light to surface messaging, Kevin Bjorke's note probably provides some
better alternatives.  

Hope that helps,
T. Burge

 
 
 

1. Light shader parameters in BMRT.

        Greetings!

                I've gotten the very good book "Texturing and Modeling, A Procedural
Approach" by Ebert et al, and I'm working my way through it. I'm
currently using the Blue Moon Rendering Tools, and there seems to be
some slight descrepency between Pixar's product and this one.  For the
most part, I can see these and work around them, but the following is
driving me nuts, mainly because it seems it is not documented anywhere:

                It would appear that in a light shader using BMRT, there are only certain
token names which are permissible to use as shader parameters.  For
example, given the following light shader:

  light sayhello(varying float hasSpoken;) {
      if (hasSpoken > 0) {
         hasSpoken = 0;
         printf("Hello!\n");
         }
      Cl = 0.0;
      }

the RIB which follows generates an error, saying "Invalid token.
Undelcared token 'hasSpoken'."

WorldBegin
  AttributeBegin
   Translate 5 5 0
   LightSource "sayhello" 1 "hasSpoken" [1]
   AttributeEnd
  Illuminate 1 1
  AttributeBegin
   Translate 0 0 1
   Surface "brick"
   Polygon "P" [-3 -3 1 -3 3 1 3 3 1 3 -3 1]
  AttributeEnd
WorldEnd

However, if I change it to:
  light sayhello(varying float intensity;) {
    if (intensity > 0) {
    intensity = 0;
    printf("Hello!");
    }
   Cl = 0.0;
   }

and make the approriate change also in the RIB, it works as it should.

What gives?  Why this restriction?  Why is it undocumented?  What is the
list of magical allowed-token-names for light shaders?

    much confused,
                dj trombley

2. Regarding the "free" computer (SPAM !!!)

3. ANN: new shader article, Using Vertex Shaders, Part III: Optimizing the Tweening Vertex Shader, is live

4. jpg viewer??

5. Image-based lighting with surface shaders?

6. endereco

7. RIB lib, varying shader parameters

8. Missing .DLL in WinXP . . . ?

9. Sending Parameters into Shaders

10. Shader parameters passing through arrays - Help

11. Toon shaders or shader ideas

12. Converting Maya Shader to a Renderman Shader