I am trying to get some basic toon shading working, I am using the game engine + editor.
I wrote my own pipeline :
Code:
<Pipeline>
<CommandQueue>
<Stage id="FirstStage" link="globalSettings.material.xml">
<ClearTarget depthBuf="true" colBuf0="true" />
<DrawGeometry context="AMBIENT" class="~TRANSLUCTENT" />
</Stage>
<Stage id="Overlays">
<DrawOverlays context="OVERLAY" />
</Stage>
</CommandQueue>
</Pipeline>
and this is my shader :
Code:
[[FX]]
sampler2D albedoMap;
// Contexts
context AMBIENT
{
VertexShader = compile GLSL VS_OVERLAY;
PixelShader = compile GLSL FS_OVERLAY;
}
[[VS_OVERLAY]]
#include "shaders/utilityLib/vertCommon.glsl"
#include "shaders/utilityLib/vertSkinning.glsl"
uniform mat4 viewProjMat;
uniform vec3 viewerPos;
attribute vec3 vertPos;
attribute vec2 texCoords0;
attribute vec3 normal;
varying vec4 pos, vsPos;
varying vec2 texCoords;
varying vec3 tsbNormal;
void main( void )
{
mat4 skinningMat = calcSkinningMat();
mat3 skinningMatVec = getSkinningMatVec( skinningMat );
pos = calcWorldPos( skinPos( vec4( vertPos, 1.0 ), skinningMat ) );
vsPos = calcViewPos( pos );
tsbNormal = normal;
texCoords = texCoords0;
gl_Position = viewProjMat * pos;
}
[[FS_OVERLAY]]
uniform sampler2D albedoMap;
varying vec2 texCoords;
varying vec3 tsbNormal;
void main( void )
{
//Flip coords for glsl
vec3 newCoords = vec3( texCoords, 0 );
newCoords.t *= -1.0;
//Calculate shading
vec3 textColour = texture2D( albedoMap, newCoords ).rgb;
float light = min(dot(tsbNormal, vec3(1,0,0)), 1);
//Thresholds for cell shading
if(light < 0.3)
light = 0.3;
else if(light < 0.7)
light = 0.7;
else
light = 1;
gl_FragColor.rgb = textColour * light;
}
Currently I am trying to use a global lightning direction but that doesn't seem to work, the lightning always stays on the same side of the model. Lets say I have a model who I light from the back and I am looking at the front, then its all oke since the front is dark and the back is light, then if I turn the model 180 degrees and the back faces the camera its still light instead of going dark as it should be.
Anyone got any clue why this is happening / how to fix it.