forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PixelShaders.hlsli
58 lines (46 loc) · 2.08 KB
/
PixelShaders.hlsli
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
//--------------------------------------------------------------------------------------
// PixelShaders.hlsli
//
// Pixel Shaders for the Dolphin sample
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
struct VSOUT
{
float4 vPosition : SV_POSITION;
float4 vLightAndFog : COLOR0_center; // COLOR0.x = light, COLOR0.y = fog
float4 vTexCoords : TEXCOORD1; // TEXCOORD0.xy = basetex, TEXCOORD0.zw = caustictex
};
//--------------------------------------------------------------------------------------
// Pixel shader constants
//--------------------------------------------------------------------------------------
sampler SamplerSkin;
sampler SamplerCaustics;
cbuffer cb0
{
uniform float3 g_vAmbient : register(c0); // Material ambient color
uniform float4 g_vFogColor : register(c1); // Fog color
}
Texture2D TextureSkin;
Texture2D TextureCaustics;
//--------------------------------------------------------------------------------------
// Name: ShadeCausticsPixel()
// Desc: Pixel shader to add underwater caustics to a lit base texture.
//--------------------------------------------------------------------------------------
float4 ShadeCausticsPixel(VSOUT Input) : SV_Target
{
// Decompress input values
float3 vLightColor = Input.vLightAndFog.xxx;
float fFogValue = Input.vLightAndFog.y;
float2 vBaseTexCoords = Input.vTexCoords.xy;
float2 vCausticTexCoords = Input.vTexCoords.zw;
// Combine lighting, base texture and water caustics texture
float4 vDiffuse = TextureSkin.Sample(SamplerSkin, vBaseTexCoords);
float4 vCaustics = TextureCaustics.Sample(SamplerCaustics, vCausticTexCoords);
// Combine lighting, base texture and water caustics texture
float4 PixelColor0 = vDiffuse * float4(vLightColor + g_vAmbient, 1);
float4 PixelColor1 = vCaustics * float4(vLightColor, 1);
// Return color blended with fog
return lerp(g_vFogColor, PixelColor0 + PixelColor1, fFogValue);
}