Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SamplerState SampleType;
- struct LayerData
- {
- uint blendMode;
- uint type;
- float4 color;
- };
- cbuffer PerFrameBuffer
- {
- matrix worldMatrix;
- matrix viewMatrix;
- matrix projectionMatrix;
- uint2 numTextures;
- };
- Texture2D textures[126];
- StructuredBuffer<LayerData> textureData;
- struct VertexInputType
- {
- float4 position : POSITION;
- float2 tex : TEXCOORD0;
- };
- struct PixelInputType
- {
- float4 position : SV_POSITION;
- float2 tex : TEXCOORD0;
- };
- float4 TexturePixelShader(PixelInputType input) : SV_TARGET
- {
- float4 source = textures[0].Sample(SampleType, input.tex);
- uint count = numTextures.x;
- for(uint i = 0; i < count; ++i)
- {
- float4 layer = textures[i+1].Sample(SampleType, input.tex);
- switch(textureData[i].type)
- {
- case 0:
- source = source + source.a * layer;
- break;
- case 1:
- source = source + source.a * layer.r * textureData[i].color;
- break;
- }
- }
- return source;
- }
- PixelInputType TextureVertexShader(VertexInputType input)
- {
- PixelInputType output;
- // Change the position vector to be 4 units for proper matrix calculations.
- input.position.w = 1.0f;
- // Calculate the position of the vertex against the world, view, and projection matrices.
- output.position = mul(input.position, worldMatrix);
- output.position = mul(output.position, viewMatrix);
- output.position = mul(output.position, projectionMatrix);
- // Store the texture coordinates for the pixel shader.
- output.tex = input.tex;
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement