xKamuna

HLSL/GLSL Example 4

May 6th, 2019
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Joint
  2. {
  3.     float4x4 local;
  4.     uint parentIndex;
  5. };
  6.  
  7. cbuffer Constants
  8. {
  9.     float4x4 g_WorldViewProj;
  10.     Joint g_Joints[255];
  11.     uint count;
  12. };
  13.  
  14. struct PSInput
  15. {
  16.     float4 Pos : SV_POSITION;
  17. };
  18.  
  19. [maxvertexcount(256)]
  20. void main(
  21.     line PSInput points[2],
  22.     inout LineStream< PSInput > stream
  23. )
  24. {
  25.     PSInput v[2];
  26.  
  27.     uint i, j;
  28.     for (i = 0; i < count; ++i)
  29.     {
  30.         j = g_Joints[i].parentIndex;
  31.         if (j != 255)
  32.         {
  33.             v[0].Pos = mul(float4(g_Joints[i].local[0][3], g_Joints[i].local[1][3], g_Joints[i].local[2][3], g_Joints[i].local[3][3]), g_WorldViewProj);
  34.             v[1].Pos = mul(float4(g_Joints[j].local[0][3], g_Joints[j].local[1][3], g_Joints[j].local[2][3], g_Joints[j].local[3][3]), g_WorldViewProj);
  35.             stream.Append(v[0]); //EmitVertex
  36.             stream.Append(v[1]); //EmitVertex
  37.             stream.RestartStrip(); //EndPrimitive
  38.         }
  39.         else
  40.         {
  41.             v[0].Pos = mul(float4(g_Joints[i].local[0][3], g_Joints[i].local[1][3], g_Joints[i].local[2][3], g_Joints[i].local[3][3]), g_WorldViewProj);
  42.             v[1].Pos = mul(float4(g_Joints[i].local[0][3], g_Joints[i].local[1][3], g_Joints[i].local[2][3], g_Joints[i].local[3][3]) + float4(0.0, 1.0, 0.0, 0.0), g_WorldViewProj);
  43.             stream.Append(v[0]); //EmitVertex
  44.             stream.Append(v[1]); //EmitVertex
  45.             stream.RestartStrip(); //EndPrimitive
  46.         }
  47.     }
  48.  
  49.  
  50. }
Add Comment
Please, Sign In to add comment