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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// raster-simple.slang
struct AssembledVertex
{
float3 position : POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD;
};
struct RasterVertex
{
float3 worldPosition;
float3 worldNormal;
float2 uv;
};
struct Model
{
float3x4 modelToWorld;
float3x4 modelToWorld_inverseTranspose;
}
struct Material
{
Texture2D<float3> albedoMap;
Texture2D<float3> normalMap;
Texture2D<float> glossMap;
SamplerState sampler;
float2 uvScale;
float2 uvBias;
}
struct Camera
{
float3x4 worldToView;
float3x4 worldToView_inverseTranspose;
float4x4 viewToProj;
}
struct DirectionalLight
{
float3 intensity;
float3 direction;
}
struct Environment
{
TextureCube environmentMap;
DirectionalLight light;
}
uniform Model model;
uniform ParameterBlock<Material> material;
uniform ConstantBuffer<Camera> camera;
uniform ParameterBlock<Environment> environment;
[shader("vertex")]
[require(sm_6_0)]
void vertexMain(
in AssembledVertex assembledVertex : A,
out RasterVertex rasterVertex : R,
in uint vertexID : SV_VertexID,
out float4 projPosition : SV_Position)
{
float3 worldPosition = mul(model.modelToWorld, float4(assembledVertex.position,1));
rasterVertex.worldPosition = worldPosition;
rasterVertex.worldNormal = mul(model.modelToWorld_inverseTranspose, float4(assembledVertex.normal,0));
rasterVertex.uv = assembledVertex.uv;
float3 viewPosition = mul(camera.worldToView, float4(worldPosition,1));
projPosition = mul(camera.viewToProj, float4(viewPosition,1));
}
[shader("fragment")]
[require(sm_6_0)]
float4 fragmentMain(
in RasterVertex vertex : R)
: SV_Target0
{
float3 normal = vertex.worldNormal;
float3 albedo = material.albedoMap.Sample(material.sampler, vertex.uv);
float3 color = albedo * max(0, dot(normal, environment.light.direction));
return float4(color, 1);
}
|