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)
Nice Vertex Shader trick
Started by codemonkey, Jun 23 2005 03:34 PM
3 replies to this topic
#1
Posted 23 June 2005 - 03:34 PM
#2
Posted 23 June 2005 - 03:41 PM
This is just ordinary diffuse lighting, with directional light coming from the positive Z-axis.
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 23 June 2005 - 03:53 PM
Maybe, but you don't need a light direction vector uploaded to the constants or to do the N.L in the shader, you can kind of get it for free.
Obviously you cannot change the direction of the lighting at real-time, but if you have loads of mid to far distant objects and you orient them to be facing a supposed sun-light source when you export them, you can get the sun-light effect for free, without having to setup & bake the light into the vertices for all objects before you export.
-CodeMonkey(12s)
Obviously you cannot change the direction of the lighting at real-time, but if you have loads of mid to far distant objects and you orient them to be facing a supposed sun-light source when you export them, you can get the sun-light effect for free, without having to setup & bake the light into the vertices for all objects before you export.
-CodeMonkey(12s)
#4
Posted 23 June 2005 - 10:50 PM
As reedbeta says, this is kind of like a hard-coded directional light.
If you are going to do a hard-coded light like this why not just bake it into vertex colors, and really get it for free? And have arbitrary numbers, colors, and orientations of lights to boot? And even do simple self-shadowing by ray-casting from vertices?
If you are going to do a hard-coded light like this why not just bake it into vertex colors, and really get it for free? And have arbitrary numbers, colors, and orientations of lights to boot? And even do simple self-shadowing by ray-casting from vertices?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











