Debian Codegraph @

tests/manual/rhi/displacement/material_domain.hlsl

raw
1 struct Input
2 {
3 float edges[3] : SV_TessFactor;
4 float inside : SV_InsideTessFactor;
5 };
6
7 struct PatchInput
8 {
9 float3 position : POSITION;
10 float2 uv : TEXCOORD0;
11 float3 normal : TEXCOORD1;
12 };
13
14 struct PixelInput
15 {
16 //float2 uv : TEXCOORD0;
17 float3 normal : TEXCOORD1;
18 float4 position : SV_POSITION;
19 };
20
21 cbuffer buf : register(b0)
22 {
23 row_major float4x4 mvp : packoffset(c0);
24 float displacementAmount : packoffset(c4);
25 float tessInner : packoffset(c4.y);
26 float tessOuter : packoffset(c4.z);
27 int useTex : packoffset(c4.w);
28 };
29
30 Texture2D<float4> tex : register(t1);
31 SamplerState texsampler : register(s1);
32
33 [domain("tri")]
34 PixelInput main(Input input, float3 uvwCoord : SV_DomainLocation, const OutputPatch<PatchInput, 3> patch)
35 {
36 PixelInput output;
37
38 float3 pos = uvwCoord.x * patch[0].position + uvwCoord.y * patch[1].position + uvwCoord.z * patch[2].position;
39 float2 uv = uvwCoord.x * patch[0].uv + uvwCoord.y * patch[1].uv;
40 float3 normal = normalize(uvwCoord.x * patch[0].normal + uvwCoord.y * patch[1].normal + uvwCoord.z * patch[2].normal);
41
42 float4 c = tex.SampleLevel(texsampler, uv, 0.0);
43 const float3 yCoeff_709 = float3(0.2126, 0.7152, 0.0722);
44 float df = dot(c.rgb, yCoeff_709);
45 if (useTex == 0)
46 df = 1.0;
47 float3 displacedPos = pos + normal * df * displacementAmount;
48
49 output.position = mul(float4(displacedPos, 1.0), mvp);
50 //output.uv = uv;
51 output.normal = normal;
52
53 return output;
54 }