No Description

displacement.tese 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (binding = 1) uniform UBO
  5. {
  6. mat4 projection;
  7. mat4 model;
  8. vec4 lightPos;
  9. float tessAlpha;
  10. float tessStrength;
  11. } ubo;
  12. layout (binding = 2) uniform sampler2D displacementMap;
  13. layout(triangles, equal_spacing, ccw) in;
  14. layout (location = 0) in vec3 inNormal[];
  15. layout (location = 1) in vec2 inUV[];
  16. layout (location = 0) out vec3 outNormal;
  17. layout (location = 1) out vec2 outUV;
  18. layout (location = 2) out vec3 outEyesPos;
  19. layout (location = 3) out vec3 outLightVec;
  20. void main()
  21. {
  22. gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position) + (gl_TessCoord.y * gl_in[1].gl_Position) + (gl_TessCoord.z * gl_in[2].gl_Position);
  23. outUV = gl_TessCoord.x * inUV[0] + gl_TessCoord.y * inUV[1] + gl_TessCoord.z * inUV[2];
  24. outNormal = gl_TessCoord.x * inNormal[0] + gl_TessCoord.y * inNormal[1] + gl_TessCoord.z * inNormal[2];
  25. gl_Position.xyz += normalize(outNormal) * (max(textureLod(displacementMap, outUV.st, 0.0).a, 0.0) * ubo.tessStrength);
  26. outEyesPos = (gl_Position).xyz;
  27. outLightVec = normalize(ubo.lightPos.xyz - outEyesPos);
  28. gl_Position = ubo.projection * ubo.model * gl_Position;
  29. }