PDA

View Full Version : Programatically Baking Textures



lukegeldart
06-05-2006, 04:49 AM
Does anyone have any ideas on baking a shader to a texture?

I have a model of some structure/object and a shader that defines a surface colour for all polygons based upon its distance from some reference point in the world. Shader is easy etc. but i would like to calculate some statistics from the shader output on the model surfaces.

Currently i am looking at the following:-

1) take each polygon that makes up each object. Somehow orientate the camera to look at each polygon face on.

2) Switch off all other polygons when rendering.

3) Render this polgon and save output to a bitmap.

4) Process this bitmap for stats.

This is a bit of a pain as i cant use many of the scene apis that are available as i need to know about every polygon in every object to orientate correctly.

If there is an easier way that someone out there knows then can they give me a few hints please.

Pentagram
06-05-2006, 05:15 AM
Just render with the uv's as vertex positions. This will basically render the model as an unwrap. The other parts of the shader of course would need to make sure they use the proper verex positions (i.e. the distance calculation).
Then set up your projection matrix as an ortogonal projection that renders everything in the 0-1 range.
This of course requires the model is unwrapped uniquely (as you just want the data you could use a tool to generate these unique mappings) frame buffer is high res enough not to cause sampling artefacts,...
But it means you could render the whole thing with one batch+readback instead of loads and loads of changes for every face.

lukegeldart
06-05-2006, 06:19 AM
Thanks Pentagram,
i will more than likely come back with more questions as i progress as i am new to shaders.
thanks
Luke