Advertisement
Guest User

final.fsh

a guest
Dec 4th, 2011
12,031
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. //Shaders 2.0 port of Yourself's Cell Shader
  2.  
  3. #version 120
  4.  
  5. #define CELL_SHADING
  6. #define THRESHOLD 0.4
  7. #define THICKNESS 0.0025
  8.  
  9. uniform sampler2D texture;
  10. uniform sampler2D gdepth;
  11. uniform float near;
  12. uniform float far;
  13. varying vec4 texcoord;
  14.  
  15. #ifdef CELL_SHADING
  16. float getDepth(vec2 coord) {
  17.         float depth = texture2D(gdepth, coord).x;
  18.         return 2.0 * near * far / ( far + near - ( 2.0 * depth - 1.0 ) * ( far - near ) );
  19. }
  20. float getCellShaderFactor(vec2 coord) {
  21.     float d=getDepth(coord);
  22.     vec3 n=normalize(vec3(getDepth(coord+vec2(THICKNESS,0.0))-d,getDepth(coord+vec2(0.0,THICKNESS))-d ,THRESHOLD));
  23.     return n.z;//clamp(n.z*3.0,0.0,1.0);
  24. }
  25. #endif
  26. void main()
  27. {
  28.     vec4 color = texture2D(texture, texcoord.st);
  29.     #ifdef CELL_SHADING
  30.     color.rgb *= (getCellShaderFactor(texcoord.st));
  31.     #endif
  32.     gl_FragColor = color;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement