RenderMan Light Shader
From K-3D
Global Variables
The following table lists the set of global variables that can be used by light source shaders.
Name | Type | Storage | Description |
Cl | color | varying | Outgoing light ray color (output) |
Ol | color | varying | Outgoing light ray opacity (output) |
P | point | varying | Surface position on the light |
dPdu | vector | varying | Derivitive of surface position along u |
dPdv | vector | varying | Derivitive of surface position along v |
N | normal | varying | Surface shading normal on the light |
Ng | normal | varying | Surface geometric normal on the light |
u,v | float | varying | Surface parameters |
du,dv | float | varying | Change in surface parameters |
s,t | float | varying | Surface texture coordinates |
L | vector | varying | Outgoing light ray direction* |
Ps | point | varying | Position being illuminated |
E | point | uniform | Position of the eye |
ncomps | float | uniform | Number of color components |
time | float | uniform | Current shutter time |
dtime | float | uniform | The amount of time covered by this shading sample |
Geometry of Shading
A light source shader computes the amount of light cast along the direction L which arrives at some point in space Ps. The color of the light is Cl while the opacity is Ol. The geometric parameters described above (P, du, N, etc.) are available in light source shaders; however, they are the parameters of the light emitting surface (e.g., the surface of an area light source) not the parameters of any primitive being illuminated. If the light source is a point light, P is the origin of the light source shader space and the other geometric parameters are zero. If either Cl or Ol are not set, they default to black and opaque, respectively.
Example
Standard ambient light source
light ambientlight (float intensity = 1; color lightcolor = 1; ) { Cl = intensity * lightcolor; }
The simplest light is only defined by an intensity and a color. It's the same everywhere.
Directional properties
From the RenderMan Interface Specification :
The directional properties of light sources depend on whether the sources execute a solar or an illuminate statement. Light source shaders without explicit illuminate or solar statements are assumed to be non-directional, or ambient.
Examples
Standard point light source
light pointlight (float intensity = 1; color lightcolor = 1; point from = point "shader" (0,0,0);) { illuminate (from) Cl = intensity * lightcolor / (L . L); }
The illuminate statement defines a local light source (one with a position). Here, the length of L is the distance from the light source to the surface being shaded. The / (L . L) operation simulates the light falloff.
Standard distant light source
light distantlight(float intensity = 1; color lightcolor = 1; point from = point "shader"(0, 0, 0); point to = point "shader"(0, 0, 1);) { solar (to - from, 0) Cl = intensity * lightcolor; }
The solar statement defines a directional light source. The light direction is defined by the (to - from) vector.