forked from doodlum/skyrim-community-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISRefraction.hlsl
57 lines (43 loc) · 1.77 KB
/
ISRefraction.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
57
#include "Common/Color.hlsli"
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/FrameBuffer.hlsli"
typedef VS_OUTPUT PS_INPUT;
struct PS_OUTPUT
{
float4 Color : SV_Target0;
};
#if defined(PSHADER)
SamplerState Src0Sampler : register(s0);
SamplerState Src1Sampler : register(s1);
Texture2D<float4> Src0Tex : register(t0);
Texture2D<float4> Src1Tex : register(t1);
cbuffer PerGeometry : register(b2)
{
float4 Tint : packoffset(c0);
};
float2 GetRefractedTexCoord(float2 texCoordOriginal, float3 normalOriginal)
{
float2 texCoord = texCoordOriginal + float2(-1, 1) * (2 * (0.05 * normalOriginal.z) * (normalOriginal.xy - 0.5));
float2 texCoordClamped = texCoord > 0.85 ? lerp(0.85, texCoord, 0.78) : texCoord;
texCoordClamped = texCoord < 0.15 ? lerp(0.15, texCoord, 0.78) : texCoordClamped;
return FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(lerp(texCoord, texCoordClamped, normalOriginal.z));
}
PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;
float2 texCoordOriginal = FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(input.TexCoord);
float4 normalOriginal = Src1Tex.Sample(Src1Sampler, texCoordOriginal);
float4 colorOriginal = Src0Tex.Sample(Src0Sampler, texCoordOriginal);
float2 texCoordRefracted = GetRefractedTexCoord(input.TexCoord, normalOriginal.xyz);
float refractedMask = Src1Tex.Sample(Src1Sampler, texCoordRefracted).w;
float4 colorRefracted = Src0Tex.Sample(Src0Sampler, texCoordRefracted);
float4 colorResulting = refractedMask != 0 ? colorRefracted : colorOriginal;
if (normalOriginal.w > 0.8 && normalOriginal.w < 1) {
psout.Color.xyz = lerp(colorResulting.xyz, Tint.xyz * Color::RGBToLuminance2(colorRefracted.xyz), Tint.w);
} else {
psout.Color.xyz = colorResulting.xyz;
}
psout.Color.w = colorResulting.w;
return psout;
}
#endif