Jump to content

Adding vertex shader


Tomster
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...