xKamuna

HLSL/GLSL Example 1

May 6th, 2019
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //These HLSL/GLSL pastes is "HLSL" that Diligent Engine "converts" into GLSL (it's actually GLSL with a bunch of defines and includes on top).
  2. cbuffer Constants
  3. {
  4.     float4x4 g_WorldViewProj;
  5.     float4x4 g_JointModels[255];
  6.     float4x4 g_LinkMatrix;
  7.     //int boneIndex;
  8. };
  9.  
  10. struct PSInput
  11. {
  12.     float4 Pos : SV_POSITION;
  13.     float4 Normal : NORMAL0;
  14.     float4 Color : COLOR0;
  15.     float2 Uv : TEXCOORD0;
  16. };
  17.  
  18. // Vertex shader takes two inputs: vertex position and color.
  19. // By convention, Diligent Engine expects vertex shader inputs to
  20. // be labeled as ATTRIBn, where n is the attribute number
  21. PSInput main(   float3 pos : ATTRIB0, float3 normal : ATTRIB1,uint color : ATTRIB2,float2 uv : ATTRIB3, //Vertex
  22.                 int vertexNumDummy : ATTRIB4, int index0 : ATTRIB5, float boneWeight : ATTRIB6, int index1 : ATTRIB7, float3 weldPos : ATTRIB8, float3 weldNormal : ATTRIB9) //Welding
  23. {
  24.     /*CONST FLOAT f = 1.0f / 255.0f;
  25.     r = f * (FLOAT)(unsigned char) (dw >> 16);
  26.     g = f * (FLOAT)(unsigned char) (dw >> 8);
  27.     b = f * (FLOAT)(unsigned char) (dw >> 0);
  28.     a = f * (FLOAT)(unsigned char) (dw >> 24);*/
  29.     PSInput ps;
  30.     //TODO: Remove conditional and optimize everything
  31.     if (index0 != -1)
  32.     {
  33.         ps.Pos = mul(mul(float4(pos, 1.0), mul(g_LinkMatrix, g_JointModels[index0])), boneWeight);
  34.         ps.Normal = mul(mul(float4(normal, 1.0), mul(g_LinkMatrix, g_JointModels[index0])), boneWeight);
  35.         ps.Pos += mul(mul(float4(weldPos, 1.0), g_JointModels[index1]), 1.0f - boneWeight);
  36.         //else ps.Pos += mul(mul(float4(pos, 1.0), mul(g_LinkMatrix, g_JointModels[index0])), 1.0f - boneWeight);
  37.         ps.Normal += mul(mul(float4(weldNormal, 1.0), g_JointModels[index1]), 1.0f - boneWeight);
  38.         ps.Pos = mul(ps.Pos, g_WorldViewProj);
  39.         ps.Normal = mul(ps.Normal, g_WorldViewProj);
  40.         /*if (vertexNumDummy == -1)
  41.         {
  42.             ps.Color = float4(1.0, 0.0, 0.0, 1.0);
  43.  
  44.         }
  45.         else
  46.         {
  47.             ps.Color = float4(boneWeight, boneWeight, boneWeight, 1.0);
  48.             if (index0 == index1)
  49.             {
  50.                 ps.Color = float4(0.0, 0.0, 1.0, 1.0);
  51.             }
  52.         }*/
  53.     }
  54.     else
  55.     {
  56.         ps.Pos = mul(float4(pos, 1.0), g_WorldViewProj);
  57.         ps.Normal = mul(float4(normal, 1.0), g_WorldViewProj);
  58.         ps.Color = float4(float3(0.0, 1.0, 0.0), 1.0);
  59.     }
  60.     float a = ((color & 0xff000000) >> 24);
  61.     float r = ((color & 0xff0000) >> 16);
  62.     float g = ((color & 0xff00) >> 8);
  63.     float b = ((color & 0xff));
  64.     /*if(vertexNumDummy == -1) */ps.Color = float4(r, g, b, a) / 255.0;
  65.     //else ps.Color = float4(float3(boneWeight, 0.0, 0.0), 1.0);
  66.    
  67.     ps.Uv = uv;
  68.     return ps;
  69. }
Add Comment
Please, Sign In to add comment