Advertisement
expired6978

Untitled

Jul 2nd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. SamplerState SampleType;
  2.  
  3. struct LayerData
  4. {
  5.     uint blendMode;
  6.     uint type;
  7.     float4 color;
  8. };
  9.  
  10. cbuffer PerFrameBuffer
  11. {
  12.     matrix worldMatrix;
  13.     matrix viewMatrix;
  14.     matrix projectionMatrix;
  15.     uint2 numTextures;
  16. };
  17.  
  18. Texture2D textures[126];
  19. StructuredBuffer<LayerData> textureData;
  20.  
  21. struct VertexInputType
  22. {
  23.     float4 position : POSITION;
  24.     float2 tex : TEXCOORD0;
  25. };
  26.  
  27. struct PixelInputType
  28. {
  29.     float4 position : SV_POSITION;
  30.     float2 tex : TEXCOORD0;
  31. };
  32.  
  33. float4 TexturePixelShader(PixelInputType input) : SV_TARGET
  34. {
  35.     float4 source = textures[0].Sample(SampleType, input.tex);
  36.     uint count = numTextures.x;
  37.     for(uint i = 0; i < count; ++i)
  38.     {
  39.         float4 layer = textures[i+1].Sample(SampleType, input.tex);
  40.  
  41.         switch(textureData[i].type)
  42.         {
  43.             case 0:
  44.             source = source + source.a * layer;
  45.             break;
  46.             case 1:
  47.             source = source + source.a * layer.r * textureData[i].color;
  48.             break;
  49.         }
  50.     }
  51.  
  52.     return source;
  53. }
  54.  
  55. PixelInputType TextureVertexShader(VertexInputType input)
  56. {
  57.     PixelInputType output;
  58.  
  59.     // Change the position vector to be 4 units for proper matrix calculations.
  60.     input.position.w = 1.0f;
  61.  
  62.     // Calculate the position of the vertex against the world, view, and projection matrices.
  63.     output.position = mul(input.position, worldMatrix);
  64.     output.position = mul(output.position, viewMatrix);
  65.     output.position = mul(output.position, projectionMatrix);
  66.    
  67.     // Store the texture coordinates for the pixel shader.
  68.     output.tex = input.tex;
  69.    
  70.     return output;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement