forked from vixorien/D3D11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPS_DiffuseSpecular.hlsl
56 lines (48 loc) · 1.62 KB
/
PS_DiffuseSpecular.hlsl
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
#include "ShaderStructs.hlsli"
#include "ShaderLighting.hlsli"
// Data from our primary constant buffer
cbuffer PrimaryBuffer : register(b0)
{
float4 colorTint;
float roughness;
float3 cameraPosition;
float2 uvPosition;
float2 uvScale;
Light lights[LIGHT_COUNT];
float3 lightAmbient;
}
Texture2D MapDiffuseSpecular : register(t0); // "t" registers for textures
SamplerState BasicSampler : register(s0); // "s" registers for samplers
// --------------------------------------------------------
// The entry point (main method) for our pixel shader
//
// - Input is the data coming down the pipeline (defined by the struct)
// - Output is a single color (float4)
// - Has a special semantic (SV_TARGET), which means
// "put the output of this into the current render target"
// - Named "main" because that's the default the shader compiler looks for
// --------------------------------------------------------
float4 main(VertexToPixel input) : SV_TARGET
{
// Renormalize the normal
input.normal = normalize(input.normal);
// Sample the texture at this pixel
float4 sampleDS = MapDiffuseSpecular.Sample(BasicSampler, input.uv * uvScale + uvPosition);
float3 sampleDiffuse = pow(sampleDS.rgb, 2.2f); // Gamma uncorrected so it gets the expected value after end correction
float sampleSpecular = sampleDS.a;
float3 surfaceColor = sampleDiffuse * colorTint.rgb;
// Return the result of our lighting equations
return float4(
pow(CalculateLightingLambertPhong(
lights,
lightAmbient,
input.normal,
surfaceColor,
roughness,
sampleSpecular,
input.worldPosition,
cameraPosition
), 1.0f / 2.2f),
1.0f
);
}