Advertisement
TableSalt

minimum_vert

Aug 12th, 2023
1,796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 120
  2.  
  3. // Varying.
  4. varying vec3 worldNormal;
  5. varying vec3 worldPos;
  6.  
  7. // Misc uniforms.
  8. uniform vec3 camPos;
  9. uniform mat4 obj2World;
  10. uniform mat4 world2Cam;
  11.  
  12. // Surface calculations, including specular power.
  13. varying vec2 texCoord;
  14. vec4 viewDelta;
  15.  
  16. // Fogging.
  17. uniform vec4 fogBaseColor;
  18. uniform vec4 fogConsts;
  19. uniform sampler2D fogTex;
  20. varying vec2 fogCoords;
  21.  
  22. void main()
  23. {
  24.     // Bricks always in world space.
  25.     worldPos = (obj2World * vec4(gl_Vertex.xyz, 1.0f)).xyz;
  26.     worldNormal = ((obj2World * vec4(gl_Normal.xyz, 0.0f)).xyz);
  27.  
  28.     if(length(gl_Normal.xyz) < 1.1f)
  29.         worldNormal.xyz = normalize(worldNormal.xyz);
  30.  
  31.     // Do some camera delta math.
  32.     viewDelta.xyz = worldPos - camPos;
  33.     viewDelta.w   = length(viewDelta.xyz);
  34.     viewDelta.xyz = -normalize(viewDelta.xyz);
  35.  
  36.     // Fog can be done per-vertex.
  37.     fogCoords.x = clamp((fogConsts.y - viewDelta.w) * fogConsts.x, 0.0f, 1.0f);
  38.     fogCoords.y = clamp((worldPos.z - fogConsts.z) * fogConsts.w, 0.0f, 1.0f);
  39.  
  40.     // Project the brick pos and normal.
  41.     gl_Position = gl_ProjectionMatrix * world2Cam * vec4(worldPos, 1.0f);
  42.  
  43.     // Pass color through.
  44.     gl_FrontColor = gl_Color;
  45.    
  46.     // Pass texcoords through.
  47.     texCoord = gl_MultiTexCoord0.st;   
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement