Programatically Baking Textures

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.

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.

Thanks Pentagram,
i will more than likely come back with more questions as i progress as i am new to shaders.
thanks
Luke

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.