I tried to use PerPixelLighting with the following shader (GLSL):
Vertex:
Code: Select all
const stringc vertToonShader =
"varying vec3 normal;"
"void main()"
"{"
" normal = gl_Normal;"//gl_NormalMatrix *
" gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;"
" gl_Position = ftransform();"
"}";
Code: Select all
const stringc fragToonShader =
"uniform sampler2D tex;"
"uniform float texintensity;"
"uniform float fcolorr;"
"uniform float fcolorg;"
"uniform float fcolorb;"
"uniform float lightposx;"
"uniform float lightposy;"
"uniform float lightposz;"
"varying vec3 normal;"
"void main()"
"{"
" float intensity;"
" vec4 color;"
" vec3 n = normalize(-normal);"
""
" intensity = dot(vec3(lightposx,lightposy,lightposz),n);"
""
" gl_FragColor = vec4(intensity*fcolorr,intensity*fcolorg,intensity*fcolorb,1.0) + texture2D(tex,gl_TexCoord[0].st) * texintensity;"
"}";
Code: Select all
class Shader_Toon_callback: public video::IShaderConstantSetCallBack
{
public:
float texintensity;
float fcolorr;
float fcolorg;
float fcolorb;
float lightposx;
float lightposy;
float lightposz;
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
services->setPixelShaderConstant("texintensity", (float*)(&texintensity), 1);
services->setPixelShaderConstant("fcolorr", (float*)(&fcolorr), 1);
services->setPixelShaderConstant("fcolorg", (float*)(&fcolorg), 1);
services->setPixelShaderConstant("fcolorb", (float*)(&fcolorb), 1);
services->setPixelShaderConstant("lightposx", (float*)(&lightposx), 1);
services->setPixelShaderConstant("lightposy", (float*)(&lightposy), 1);
services->setPixelShaderConstant("lightposz", (float*)(&lightposz), 1);
}
};
[...]
Shader_Toon_callback *callback= new Shader_Toon_callback;
callback->texintensity=0;
callback->fcolorr=1;
callback->fcolorg=1;
callback->fcolorb=1;
callback->lightposx=10;
callback->lightposy=10;
callback->lightposz=10;
mtlToonShader = gpu->addHighLevelShaderMaterial(
vertToonShader.c_str(), "main", video::EVST_VS_1_1,
fragToonShader.c_str(), "main", video::EPST_PS_1_1,
callback, video::EMT_SOLID);
node->setMaterialType((video::E_MATERIAL_TYPE)mtlToonShader);
I wasted already hours of time and I have finally no idea why it looks like flat shading.
I also tried TGM's NormalMapping shader and I get the same artifacts, so I guess it's maybe not
a problem with my code.
I hope someone can help.
greetings,
porcus