codemonkey
06-23-2005, 08:34 AM
Hi there,
I am new to this forum and don't know whether anyone else has posted this technique, but I have just found it and thought I'd share it to see if anyone else might be able to use it.
Basically this came about from wanting to put life into flat coloured single-textured geometry, but cheaply.
The trick I found is to use the normals as a shading modifier for the vertex colour.
If your model was exported from an Art tool aligned with the Z-axis, you can use the normal.z coord to smoothly bake in colour to your object.
whereas normally in a vertex shader you would write something like
MOV oCol, iCol; or MOV oCol, tConst_Colour
to pass the vertex colour through, or use a constant colour.
The trick does this...
MOV tCol, iNorm.zzzz;
MOV oCol, tCol;
which bakes in smooth lighting and shadows without having to bake the colour into the vertices in the Art package, before export.
You could also multiply the tCol var by a light-colour value to simulate baked in lighting, but just doing the above turns flat geometry into smoothly shaded geometry.
This has probably been done before, and there are probably better ways than this to get baked in shading into flat coloured geometry (since you are just replacing the colour stream with a normal stream), but I thought it was cool for an extra instruction in a vertex shader.
-CodeMonkey(12s)
I am new to this forum and don't know whether anyone else has posted this technique, but I have just found it and thought I'd share it to see if anyone else might be able to use it.
Basically this came about from wanting to put life into flat coloured single-textured geometry, but cheaply.
The trick I found is to use the normals as a shading modifier for the vertex colour.
If your model was exported from an Art tool aligned with the Z-axis, you can use the normal.z coord to smoothly bake in colour to your object.
whereas normally in a vertex shader you would write something like
MOV oCol, iCol; or MOV oCol, tConst_Colour
to pass the vertex colour through, or use a constant colour.
The trick does this...
MOV tCol, iNorm.zzzz;
MOV oCol, tCol;
which bakes in smooth lighting and shadows without having to bake the colour into the vertices in the Art package, before export.
You could also multiply the tCol var by a light-colour value to simulate baked in lighting, but just doing the above turns flat geometry into smoothly shaded geometry.
This has probably been done before, and there are probably better ways than this to get baked in shading into flat coloured geometry (since you are just replacing the colour stream with a normal stream), but I thought it was cool for an extra instruction in a vertex shader.
-CodeMonkey(12s)