1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
struct Camera {
float4x4 view_proj;
float3 position;
};
cbuffer camera_CB : register(b0, space0) {
Camera camera;
};
struct Lighting {
float3 direction;
float3 color;
float intensity;
};
cbuffer lighting_CB : register(b1, space0) {
Lighting lighting;
};
Texture2D diffuse_tex_tex : register(t0, space1);
SamplerState diffuse_tex_samp : register(s1, space1);
Texture2D normal_tex_tex : register(t2, space1);
SamplerState normal_tex_samp : register(s3, space1);
struct VertexOutput {
float4 _sv_position : SV_Position;
float4 position : SV_Position;
float2 uv : TEXCOORD0;
};
struct FragmentOutput {
float4 color : SV_Target0;
};
FragmentOutput fs_main(VertexOutput input) {
FragmentOutput __luma_output;
float4 diffuse = diffuse_tex_tex.Sample(diffuse_tex_samp, input.uv);
float4 normal_sample = normal_tex_tex.Sample(normal_tex_samp, input.uv);
float3 n = normalize(((normal_sample.xyz * 2.0) - float3(1.0, 1.0, 1.0)));
float3 l = normalize(lighting.direction);
float ndotl = max(dot(n, l), 0.0);
float3 lit = (((diffuse.rgb * lighting.color) * ndotl) * lighting.intensity);
__luma_output.color = float4(lit, diffuse.a);
return __luma_output;
}