Example 4: Surface Attribute Mesh

The obvious limitation with the image-based techniques is that it isn't possible to move the camera. This example uses a surface attribute mesh to store the surface attributes on the surface of a mesh instead of in images. This will mean we are free to move the camera.

The image on the right shows the effect of zooming close to the geometry, where you start to see the individual grids.

Preparation

The hb_plastic.sl shader is modified include outputting all the attributes. As there is no renderer support for a mesh equivalent of an AOV image, we need to use some DSO shadeops to output the attributes. Still, it can be seen that it is the same basic process.

varying color Cambient = Cs*Ka;

varying color Cdiffuse = Cs*Kd;

varying color Cspecular = specular_color*Ks;

varying float Froughness = roughness;

 

uniform float stream_start = hb_interact_stream();

 

varying float stream_control = 0;

varying float stream_point = hb_interact_stream("control",

gridpattern("concentric",stream_control));

 

stream_point += hb_interact_stream("P",transform("world",P));

stream_point += hb_interact_stream("N",normalize(ntransform("world",N)));

stream_point += hb_interact_stream("Cambient",Cambient);

stream_point += hb_interact_stream("Cdiffuse",Cdiffuse);

stream_point += hb_interact_stream("Cspecular",Cspecular);

stream_point += hb_interact_stream("Froughness",Froughness);

The output filename for the attribute data is given as an option in prepare.rib:

Option "user" "uniform string interact_stream_filename" [ "scene.hbsas" ]

Also, the following options need to be set, similar to a bake3d render:

Attribute "cull" "hidden" 0

Attribute "cull" "backfacing" 0

Attribute "dice" "rasterorient" 0

The shading rate has a large effect on the quality of the mesh generated, the file size, and the time taken to render. When experimenting, start high (e.g. 10) and work downwards. A value of 1 is suitable for this scene.

ShadingRate 1

Rendering will create a unstructured surface attribute stream file, scene.hbsas , containing the surfaces as they are encountered by the renderer. This is converted into a structured dataset by the Makefile.

hb_interact_sas_to_sam scene.hbsas scene.hbsam

Interaction

The interact.sl is exactly the same as the previous example - it makes no difference that the attributes are coming from geometry rather than images.

The interact.rib needs to include the camera and the lights as before, and refer to the surface attribute mesh:

Attribute "identifier" "string name" ["geometry"]

 

Geometry "surface_attribute_mesh" "filename" ["scene.hbsam"]

Run

As always typing make run in the example directory will process the Makefile to build the mesh and start the application.

include ../Makeinclude

 

 

run: all

${INTERACT} interact.rib

 

all: scene.hbsam

 

 

scene.hbsam: scene.hbsas

hb_interact_sas_to_sam scene.hbsas scene.hbsam

 

scene.hbsas: hb_plastic.${SLO} prepare.rib

${RENDER} prepare.rib

 

 

hb_plastic.${SLO}: hb_plastic.sl

${SHADER} ${SHADER_DSO_OPTIONS} hb_plastic.sl