-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostProcess.fx
More file actions
87 lines (61 loc) · 1.7 KB
/
PostProcess.fx
File metadata and controls
87 lines (61 loc) · 1.7 KB
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
const float gamma = 1.0f / 2.2f;
float saturation;
texture albedoMap;
sampler2D textureSampler = sampler_state {
Texture = (albedoMap);
MagFilter = Linear;
MinFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
struct VertexShaderInput
{
float2 vertexTexCoord : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 vertexPosition : POSITION0;
float2 pixelTexCoord : TEXCOORD;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
output.vertexPosition = float4(input.vertexTexCoord, 0.0f, 1.0f);
output.pixelTexCoord = (input.vertexTexCoord + 1.0f) / 2.0f;
output.pixelTexCoord.y = 1.0f - output.pixelTexCoord.y;
return output;
}
float3 ACESToneMap(float3 hdrColor) {
float a = 2.51f;
float b = 0.03f;
float c = 2.43f;
float d = 0.59f;
float e = 0.14f;
return clamp((hdrColor*(a*hdrColor+b))/
(hdrColor*(c*hdrColor+d)+e), 0.0f, 1.0f);
}
float3 ToneMap(float3 hdrColor) {
return float3(1.0f, 1.0f, 1.0f) - exp(-hdrColor);
}
float3 saturate(float3 color, float factor) {
const float3 luma = float3(0.299f, 0.587f, 0.114f);
float luminance = dot(color, luma);
float3 pixelLuminance = float3(luminance, luminance, luminance);
return lerp(pixelLuminance, color, factor);
}
float3 PixelShaderFunction(VertexShaderOutput input) : COLOR
{
float3 outColor = float3(1.0f, 1.0f, 1.0f);
float3 textureColor = tex2D(textureSampler, input.pixelTexCoord).rgb;
outColor = ACESToneMap(textureColor);
outColor = saturate(outColor, saturation);
return outColor;
}
technique Main
{
pass Pass0
{
VertexShader = compile vs_5_0 VertexShaderFunction();
PixelShader = compile ps_5_0 PixelShaderFunction();
}
}