No Description

multiview.geom 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #version 450
  2. #extension GL_ARB_viewport_array : enable
  3. layout (triangles, invocations = 2) in;
  4. layout (triangle_strip, max_vertices = 3) out;
  5. layout (binding = 0) uniform UBO
  6. {
  7. mat4 projection[2];
  8. mat4 modelview[2];
  9. vec4 lightPos;
  10. } ubo;
  11. layout (location = 0) in vec3 inNormal[];
  12. layout (location = 1) in vec3 inColor[];
  13. layout (location = 0) out vec3 outNormal;
  14. layout (location = 1) out vec3 outColor;
  15. layout (location = 2) out vec3 outViewVec;
  16. layout (location = 3) out vec3 outLightVec;
  17. void main(void)
  18. {
  19. for(int i = 0; i < gl_in.length(); i++)
  20. {
  21. outNormal = mat3(ubo.modelview[gl_InvocationID]) * inNormal[i];
  22. outColor = inColor[i];
  23. vec4 pos = gl_in[i].gl_Position;
  24. vec4 worldPos = (ubo.modelview[gl_InvocationID] * pos);
  25. vec3 lPos = vec3(ubo.modelview[gl_InvocationID] * ubo.lightPos);
  26. outLightVec = lPos - worldPos.xyz;
  27. outViewVec = -worldPos.xyz;
  28. gl_Position = ubo.projection[gl_InvocationID] * worldPos;
  29. // Set the viewport index that the vertex will be emitted to
  30. gl_ViewportIndex = gl_InvocationID;
  31. gl_PrimitiveID = gl_PrimitiveIDIn;
  32. EmitVertex();
  33. }
  34. EndPrimitive();
  35. }