Advertisement
Guest User

GLSL

a guest
Jan 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #if COMPILING_VS
  2.  
  3. uniform TransformBlock {
  4.     mat4 Projection;
  5.     mat4 View;
  6. } Transform;
  7.  
  8. uniform MaterialBlock {
  9.     vec4 Color;
  10. } Material;
  11.  
  12. out Vertex {
  13.     vec2 Position;
  14.     vec2 TexCoord;
  15.     vec4 Color;
  16. } Out;
  17.  
  18. void main()
  19. {
  20.     Out.Position = gl_Vertex.xy;
  21.     Out.TexCoord = gl_MultiTexCoord0.st;
  22.     Out.Color = Material.Color;
  23.     gl_Position = Transform.Projection * Transform.View * gl_Vertex;
  24. }
  25.  
  26. #elif COMPILING_FS
  27.  
  28. in Vertex {
  29.     vec2 Position;
  30.     vec2 TexCoord;
  31.     vec4 Color;
  32. } In;
  33.  
  34. /*
  35. uniform unsigned int LightCount;
  36. uniform Lights {
  37.     vec2 Pos;
  38.     vec2 Dir;
  39.     vec2 Threshold;
  40.     vec3 Color;
  41. } Light[];
  42. */
  43.  
  44. void main()
  45. {
  46.     vec2 LightPos = vec2(0, 350);
  47.     vec2 LightDir = vec2(0, -1);
  48.     float Threshold1 = cos(3.1415 * 0.20);
  49.     float Threshold2 = cos(3.1415 * 0.21);
  50.     vec3 LightColor = vec3(1.0, 0.2, 0.8);
  51.     float Attenuation = 0.2;
  52.    
  53.     vec2 L = In.Position - LightPos;
  54.     float SqrDistance = dot(L, L);
  55.     vec2 LightVec = normalize(L);
  56.     float CosPhi = dot(LightDir, LightVec);
  57.     float Brightness = smoothstep(Threshold2, Threshold1, CosPhi) / (1 + SqrDistance/75000);
  58.     vec3 Color = (Attenuation + (1 - Attenuation) * Brightness * LightColor) * In.Color.rgb;
  59.     gl_FragColor = vec4(Color, In.Color.a);
  60. }
  61.  
  62. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement