Tomster Posted July 2, 2010 Share Posted July 2, 2010 Hi everyone, I am currently trying to add a toonshading effect to my project. The Frag shader is working but the vertexshader is not kicking in. I created the shader usung TShader Toonshader = LoadShader("abstract::Toon.vert", "abstract::Toon.frag"); and calling SetShader(Toonshader); before DrawImage(...); This is the vert code uniform vec3 lightDir; varying float intensity; void main() { vec3 ld; intensity = dot(lightDir,gl_Normal); gl_Position = ftransform(); } and this is the frag code varying float intensity; void main() { vec4 color; if (intensity > 0.95) color = vec4(1.0,0.5,0.5,1.0); else if (intensity > 0.5) color = vec4(0.6,0.3,0.3,1.0); else if (intensity > 0.25) color = vec4(0.4,0.2,0.2,1.0); else color = vec4(0.2,0.1,0.1,1.0); gl_FragColor = color; } any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
Laurens Posted July 2, 2010 Share Posted July 2, 2010 I do not think that 2D images are affected by shaders. Nevermind, you stated that the vertex shader does work. Quote Link to comment Share on other sites More sharing options...
Masterxilo Posted July 2, 2010 Share Posted July 2, 2010 How do you mean it's not kicking in? Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
Tomster Posted July 3, 2010 Author Share Posted July 3, 2010 by not kicking in i mean not working. at least not the way it should. It won't calculate the normals of the vertexes so the objects can be rendered correctly. all i get right now is a screen with a redish color, the one the frag shader is producing, bot no signs of geometry in the scene. just a solid redish overlay, depending on what i pass to the shader as the lightDir variable Quote Link to comment Share on other sites More sharing options...
paramecij Posted July 4, 2010 Share Posted July 4, 2010 and calling SetShader(Toonshader); before DrawImage(...); If I understand you correctly you're trying to implement toon shader as a post-processing effect - in that case it's probably because the vertex shader is fed 4 vertices from the DrawImage quad and they all have the same normal orientation. You would need to look-up the normal and do the dot3 in the pixel shader (add BUFFER_NORMAL flag when you create the buffer), .. that's my guess anyway Quote Link to comment Share on other sites More sharing options...
Tomster Posted July 4, 2010 Author Share Posted July 4, 2010 nice idea, but as far as i know and searched the net there is no way of getting normals information from within a fragshader, since the gl_normal command is meant to be used in vertex-shaders only. so that won't work. (I did try it out by the way ) Is there any other way of implementing toon shading? I mean not as a post-processing effect? I tried adding my shaders to the modell .mat file, but the engine crashes on load and doesn't throw any specific error messages in the log file. the last line in there is the fragment-shader loading and then: crash! Quote Link to comment Share on other sites More sharing options...
Tomster Posted July 4, 2010 Author Share Posted July 4, 2010 on another note: how come u can only apply post-processing shaders before a DrawImage command? Is there any way of running a Vert and Frag shader when or while rendering to the normal buffer? How would someone write his/her own rendering code with leadwerks? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.