|
The previous two examples allow you to interact with the balance between different aspects of lit images. This example renders more AOV images to capture enough attributes of the surface, so that lighting can be performed at the interaction stage. Unfortunately at this point the system does not have enough information to render shadows. For that some geometry is required - all that is here is images. The hb_plastic.sl shader is modified include outputting all the attributes. output varying color _Cambient = 0; output varying color _Cdiffuse = 0; output varying color _Cspecular = 0; output varying float _roughness = 0; output varying point _P = 0; output varying normal _N = 0; ) { _Cambient = Cs*Ka; _Cdiffuse = Cs*Kd; _Cspecular = specular_color*Ks; _roughness = roughness; _P = transform("world", P); _N = normalize(ntransform("world", N)); It is important that P and N are output in world space. The final Ci is still calculated so that the primary image is still correct, though it will not be used in interaction. The required images are given in prepare.rib: Declare "_P" "varying point" Declare "_N" "varying normal" Declare "_Cambient" "varying color" Declare "_Cdiffuse" "varying color" Declare "_Cspecular" "varying color" Declare "_roughness" "varying float"
Display "+position.tif" "tiff" "_P" Display "+normal.tif" "tiff" "_N" Display "+ambient.tif" "tiff" "_Cambient" "quantize" [0 255 0 255] Display "+diffuse.tif" "tiff" "_Cdiffuse" "quantize" [0 255 0 255] Display "+specular.tif" "tiff" "_Cspecular" "quantize" [0 255 0 255] Display "+roughness.tif" "tiff" "_roughness" "quantize" [0 255 0 255] Display "+position_8bit.tif" "tiff" "_P" "quantize" [128 255 0 255] Display "+normal_8bit.tif" "tiff" "_N" "quantize" [128 255 0 255] The final two eight-bit images allow easier visualisation of the floating point images for documentation and aren't used otherwise. Rendering will now create the following six images:
The interact.sl shader recomputes the lighting given the attributes retrieved from the images. The position and normal are picked up from the images automatically - the remaining attributes need to be specified. surface main( varying color Cambient = 0; varying color Cdiffuse = 0; varying color Cspecular = 0; varying float Froughness = 0; ) { N=normalize(N);
Oi = Os; Ci = Os * (Cambient*ambient() + Cdiffuse*diffuse() + Cspecular*specular(N, -normalize(I), Froughness)); } As before the images are brought together in interact.rib: Attribute "identifier" "string name" ["surface"]
Surface "interact.sl"
Attribute "identifier" "string name" ["geometry"]
Geometry "image" "filename" [ "position.tif:P" "normal.tif:N" "ambient.tif:Cambient" "diffuse.tif:Cdiffuse" "specular.tif:Cspecular" "roughness.tif:Froughness" ] This time we need to specify the lighting as well so the shader can use it: Attribute "identifier" "string name" ["ambient"]
LightSource "ambientlight" 1 "intensity" 1 "lightcolor" [0.15 0.15 0.15]
Attribute "identifier" "string name" ["light1"]
LightSource "spotlight" 2 "from" [0.402 0.227 -0.702] "to" [0.124 -0.422 0.005] "intensity" [1] "coneangle" [0.75] "lightcolor" [1 0.9 0.7]
Attribute "identifier" "string name" ["light2"]
LightSource "spotlight" 3 "from" [-0.602 0.159 -0.162] "to" [-0.309 -0.751 0.130] "intensity" [1] "coneangle" [0.7] "lightcolor" [0.4 0.3 0.6]
Attribute "identifier" "string name" ["light3"]
LightSource "spotlight" 4 "from" [0.214 -0.0148 1.630] "to" [0.113 -0.234 0.660] "intensity" [1.6] "coneangle" [0.8] "lightcolor" [0.6 0.0.3 0.0] Finally, since we are dealing with world coordinates, we need to specify the camera: Transform [ 1 0 0 0 0 1 0 0 0 0 1 0 0 0.3 2 1 ]
Rotate -20 1 0 0 As always typing include ../Makeinclude
run: all ${INTERACT} interact.rib
all: prepare.tif
prepare.tif: hb_plastic.${SLO} prepare.rib ${RENDER} prepare.rib
hb_plastic.${SLO}: hb_plastic.sl ${SHADER} hb_plastic.sl |