   help needed with a cel-shading shader!
  (i dont know if im in the correct forum..)hello im the author of jolt3d engine,and i need a bit of help with a cartoon shader.The problem is that while i managed to apply a light point to it (instead ofdirectional lighting which i dont want) my edge texture (the black 'pencil' like) seems to be totally wrong placed.Actually, the problem occurs when objects -doesnt- use an identity matrix.The problem is only with edge texture, not with shade one (which works correctly, even in transformed objects)Here is the tiny cartoon shader: (only this is used)const char* strVertexShader = "struct VS_INPUT\n""{\n""float4 position : POSITION;\n""float3 normal   : NORMAL;\n""float3 diffuse : COLOR;\n""float2 tex0   : TEXCOORD0;\n""};\n""struct VS_OUTPUT\n""{\n""float4 position : POSITION;\n""float3 diffuse : COLOR;\n""float2 tex0   : TEXCOORD0;\n""float2 tex1   : TEXCOORD1;\n""};\n""\n""vector eyePos:   register(c4);\n""vector lightPos: register(c5);\n""vector lightDir: register(c6);\n""\n""VS_OUTPUT main(const VS_INPUT input, uniform matrix matWorldViewProj : c0)\n""{\n""VS_OUTPUT output;\n""output.position = mul(matWorldViewProj, input.position);\n""vector vNormVertexToEye = normalize(eyePos - input.position);\n""output.tex0 = dot(input.normal, -lightDir);\n""output.tex1 = dot(input.normal, vNormVertexToEye);\n""output.diffuse = input.diffuse;\n""return output;\n""}\n""";what im using to set vertex costants & transform things:// get the current cameraJVEC3 EyePos=PROGRAM.Last_Camera.Position;JVEC3 LightPos=PROGRAM.Cartoon_Shading_Light_Position;// NEW: correct lightpos against eyepos (only), also in transformed object// correct against transformed object (inverse object transform & transform lightpos with it)D3DXMATRIX inv_out;J_D3DXMatrixInverse(&inv_out,NULL,&JMTX_to_DMTX(Matrix));LightPos=Transform_Point(LightPos,DMTX_to_JMTX(inv_out));// Create orbiting lightD3DXVECTOR4 eyePos(EyePos.x,EyePos.y,EyePos.z, 0.0f);D3DXVECTOR4 lightPos(LightPos.x,LightPos.y,LightPos.z,0.0);D3DXVECTOR4 lightDir = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f) - lightPos;// Must normalize LightDir for accurate N * L calcsD3DXVec4Normalize(&lightDir, &lightDir);// shader constantsm_pD3DDEVICE->SetVertexShaderConstantF(4, (float*)&eyePos, 1);m_pD3DDEVICE->SetVertexShaderConstantF(5, (float*)&lightPos, 1);m_pD3DDEVICE->SetVertexShaderConstantF(6, (float*)&lightDir, 1);// set object positionD3DXMATRIX matWVP,m_pMainMeshMat,m_matView,m_matProj,m_matWorld;m_pMainMeshMat=JMTX_to_DMTX(Matrix);matWVP = m_pMainMeshMat * PROGRAM.matViewProj;m_pD3DDEVICE->SetVertexShaderConstantF( 0, (float*)&matWVP, 4 );for rendering it:// set the texturem_pD3DDEVICE->SetTexture(0, CartoonTexture[ PROGRAM.Cartoon_Shading_Index ].Texture);m_pD3DDEVICE->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);   // needed, remove the repeated-texturing issue.m_pD3DDEVICE->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);m_pD3DDEVICE->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);m_pD3DDEVICE->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);m_pD3DDEVICE->SetTexture(1, EdgeTexture.Texture);m_pD3DDEVICE->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);   // needed, remove the repeated-texturing issue.m_pD3DDEVICE->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);m_pD3DDEVICE->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);m_pD3DDEVICE->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);//Set texture stages to output tex0*col0*tex1m_pD3DDEVICE->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);m_pD3DDEVICE->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);m_pD3DDEVICE->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);m_pD3DDEVICE->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);    m_pD3DDEVICE->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);m_pD3DDEVICE->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);the whole code is able to show cartoon shaded objects, transformed or not, with 'shades' texture reacting well with point light but no the same with the 'edges' one. If you need something else let me post it here..thanx in advance & sorry for message's size   
"vector vNormVertexToEye = normalize(eyePos - input.position)"eyePos is [very likely to be] in world space. input.position is in object space (a.k.a. model space).So your vNormVertexToEye vector makes no sense when any transformation is applied to the model.You need to either transform eyePos into model space (transform it with the inverse of the object to world matrix) OR you need to transform both the "input.position" used to compute vNormVertexToEye and the "input.normal" used to "compute output.tex1" into world space first (transform by the object to world matrix).2. Your main lighting looks wrong for a similar reason: "output.tex0 = dot(input.normal, -lightDir)". lightDir is in world space and input.normal is in model space.3. NOTE: when transforming vectors that only represent directions and not positions, such as normals or vNormVertexToEye, remember to only transform by the top left 3x3 part of the matrix so that no translations or projections are applied to the vectors. In HLSL you can cast a matrix to float3x3 before use to do this.;  i knew it was something like that, now works great! thanx!!About the '-lightDir' you pointed i think is being normalized before passed to shader (via D3DXVec4Normalize) because i get, visually, correct results, in other words the effect works as i want it, point lit & with transforming ability.Thanx again my friend & for your tip   