Advertisement
baryonSasuke

Mesh Shader

Jan 7th, 2021
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 460
  2. #extension GL_NV_mesh_shader : require
  3.  
  4. layout(local_size_x=1) in;
  5. layout(triangles, max_vertices=4, max_primitives=2) out;
  6.  
  7.  
  8. layout (binding = 0) uniform Rectangle {
  9.     mat4 projectionViewMatrix;
  10.     vec4 radius;
  11.     vec4 color;
  12.     vec2 dimensions;
  13.     float hasTexture;
  14. } rectangle;
  15.  
  16. // Custom vertex output block
  17. layout (location = 0) out PerVertexData{
  18.     vec2 tex;
  19. } v_out[];
  20.  
  21. out uint gl_PrimitiveCountNV;
  22. out uint gl_PrimitiveIndicesNV[];
  23.  
  24. const vec4 v1 = vec4(-0.5,-0.5,0,1);
  25. const vec4 v2 = vec4(0.5,-0.5,0,1);
  26. const vec4 v3 = vec4(-0.5,0.5,0,1);
  27. const vec4 v4 = vec4(0.5,0.5,0,1);
  28.  
  29. const vec2 t1 = vec2(0,1);
  30. const vec2 t2 = vec2(1,1);
  31. const vec2 t3 = vec2(0,0);
  32. const vec2 t4 = vec2(1,0);
  33.  
  34. void main() {
  35.  
  36.     gl_MeshVerticesNV[0].gl_Position = rectangle.projectionViewMatrix*v1;
  37.     gl_MeshVerticesNV[1].gl_Position = rectangle.projectionViewMatrix*v2;
  38.     gl_MeshVerticesNV[2].gl_Position = rectangle.projectionViewMatrix*v3;
  39.     gl_MeshVerticesNV[3].gl_Position = rectangle.projectionViewMatrix*v4;
  40.  
  41.     v_out[0].tex = t1;
  42.     v_out[1].tex = t2;
  43.     v_out[2].tex = t3;
  44.     v_out[3].tex = t4;
  45.  
  46.     gl_PrimitiveIndicesNV[0] = 0;
  47.     gl_PrimitiveIndicesNV[1] = 1;
  48.     gl_PrimitiveIndicesNV[2] = 2;
  49.     gl_PrimitiveIndicesNV[3] = 2;
  50.     gl_PrimitiveIndicesNV[4] = 1;
  51.     gl_PrimitiveIndicesNV[5] = 3;
  52.  
  53.     gl_PrimitiveCountNV += 2;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement