Artur

Blurry pointcloud refractions with 3Delight

Rate this Entry

While debugging some of my occlusion shaders, I've put together simple RIB and SL demonstrating two pass pointcloud based refractions using indirectdiffuse shadeop. It's a pretty old trick but never officially documented for some reason. First off, pointcloud baking shader:

Code:
surface simple_bake
(
	uniform float bake = 0;
	uniform string ptc_file = "mybake.ptc";
	uniform float ptc_interpolate = 0;
	uniform float ptc_radiusscale = 1 
)
{
  normal Nn = normalize( N );
  if( bake != 0 )
  {
     bake3d( ptc_file, "", P, Nn, "_radiosity", Cs, "coordsystem", "world", "interpolate", ptc_interpolate, "radiusscale", ptc_radiusscale );
  }
  Ci = Cs;
}
Refraction shader
Code:
surface refractive
(
	uniform float  pointbased = 1;
	uniform string ptc_file = "";
	uniform string envmap = "";
	uniform float  blur = 0.1;
	uniform float  ior = 1.1
)
{
  vector In = normalize( I );
  normal Nn = normalize( N );
  vector Refr = refract ( In, Nn, ior );
  Ci = indirectdiffuse( P, Refr, 0, 
			"pointbased", pointbased,
			"filename", ptc_file,
			"environmentmap", envmap,
			"coneangle", blur,
			"clamp", 1,
			"sortbleeding", 1
			);
}
Two pass RIB:
Code:
Option "searchpath" "shader" [ "&:.:${RIBDIR}" ] 
Option "trace" "maxdepth" [1]

Projection  "perspective" "fov" [ 40 ]
Translate  0 -1 8
Rotate 95 1 0 0 Rotate 180 0 1 0

ArchiveBegin "screen"
  AttributeBegin
  Translate 0 -3 2.5
  Color [ 0.9 0.1 0.1 ]
  Patch "bilinear"
    "P" [ -2 0 -2 2 0 -2 -2 0 2 2 0 2]
  AttributeEnd
ArchiveEnd

ArchiveBegin "teapot"
  AttributeBegin
  Color [ 0.1 0.5 0.9 ]
   Geometry "teapot"
  AttributeEnd
ArchiveEnd

## Bake Pass
Display "none" "null" "rgb"
WorldBegin
  AttributeBegin
    Surface "simple_bake" "float bake" [1] "string ptc_file" ["teapot.ptc"]
    Attribute "cull" "hidden" [0] "backfacing" [0]
    Attribute "dice" "rasterorient" [0]
    ReadArchive "teapot"
  AttributeEnd
WorldEnd

## Main Pass
Display "ip" "framebuffer" "rgba"
Quantize "rgba" 0 0 0 0.5
WorldBegin
  AttributeBegin
    Surface "simple_bake" "float bake" [0]
    Attribute "visibility" "integer trace" [1] "integer diffuse" [1]
    ReadArchive "teapot"
  AttributeEnd
  AttributeBegin
    Surface "refractive" "float pointbased" [1] "string ptc_file" ["teapot.ptc"] "string envmap" ["daylight.tdl"]
    ReadArchive "screen"
  AttributeEnd
WorldEnd
Before rendering it, you might want to generate environment map using tdlmake. In fact, why not put together bash script:
Code:
tdlmake -skymap 42,74,5,10,12.5,4 daylight.tdl 
shaderdl simple_bake.sl
shaderdl refractive.sl
renderdl render.rib
If you want to test it against raytraced refractions, find "pointbased" surface attribute in your RIB and set it to "0".

Next time I'd like to show how to do it with lights and volume shaders. This will allow you to use any existing shaders.
Have fun.

Submit "Blurry pointcloud refractions with 3Delight" to Digg Submit "Blurry pointcloud refractions with 3Delight" to del.icio.us Submit "Blurry pointcloud refractions with 3Delight" to StumbleUpon Submit "Blurry pointcloud refractions with 3Delight" to Google

Comments