forked from stuntrally/stuntrally3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlanarReflections_piece_ps.any
74 lines (62 loc) · 3.38 KB
/
PlanarReflections_piece_ps.any
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
//#include "SyntaxHighlightingMisc.h"
@property( use_planar_reflections )
@property( syntax == glsl || syntax == glsles || syntax == glslvk )
@piece( DeclPlanarReflTextures )
vulkan_layout( ogre_t@value(planarReflectionTex) ) uniform texture2D planarReflectionTex;
vulkan( layout( ogre_s@value(planarReflectionTex) ) uniform sampler planarReflectionSampler );
@end
@end
@property( syntax == hlsl )
@piece( DeclPlanarReflTextures )
Texture2D<float4> planarReflectionTex : register(t@value(planarReflectionTex));
SamplerState planarReflectionSampler : register(s@value(planarReflectionTex));
@end
@end
@property( syntax == metal )
@piece( DeclPlanarReflTextures )
, texture2d<float> planarReflectionTex [[texture(@value(planarReflectionTex))]]
, sampler planarReflectionSampler [[sampler(@value(planarReflectionTex))]]
@end
@end
@piece( DoPlanarReflectionsPS )
@property( syntax == metal || lower_gpu_overhead )
ushort planarReflectionIdx = inPs.planarReflectionIdx;
@else
uint planarReflectionIdx = worldMaterialIdx[inPs.drawId].w;
@end
float4 planarReflection = passBuf.planarReflections[planarReflectionIdx];
float distanceToPlanarReflPlane = dot( planarReflection.xyz, inPs.pos.xyz ) + planarReflection.w;
//org: float3 pointInPlane = inPs.pos.xyz - pixelData.normal * distanceToPlanarReflPlane;
float planarWeight = max( 1.0 - abs( distanceToPlanarReflPlane ) * passBuf.invMaxDistanceToPlanarRefl.x, 0.0 );
// float arbitraryDistortion = 5.0f;
float3 pointInPlane = inPs.pos.xyz - pixelData.normal * distanceToPlanarReflPlane
- pixelData.normal * float3(3.0, 0.0, 3.0);
// * planarWeight;
float3 projPointInPlane = mul( float4( pointInPlane.xyz, 1.0 ), passBuf.planarReflProjectionMat ).xyw;
float2 planarReflUVs = projPointInPlane.xy / projPointInPlane.z;
float3 planarReflectionS = OGRE_SampleLevel( planarReflectionTex, planarReflectionSampler,
planarReflUVs.xy,
pixelData.perceptualRoughness * passBuf.planarReflNumMips ).xyz;
//Fade out as our surface gets away from the reflection plane (planarWeight = 0 means fully faded out)
//org: float planarWeight = max( 1.0 - abs( distanceToPlanarReflPlane ) * passBuf.invMaxDistanceToPlanarRefl.x, 0.0 );
planarWeight = sqrt( planarWeight );
planarWeight = smoothstep( 0.0, 1.0, planarWeight );
//Fade out if projecting pointInPlane failed (we landed outside the screen, we have no information)
float2 boundary = abs( planarReflUVs.xy - float2(0.5, 0.5) ) * 2.0;
float fadeOnBorder = 1.0 - saturate( (boundary.x - 0.975) * 40 );
fadeOnBorder *= 1.0 - saturate( (boundary.y - 0.975) * 40 );
fadeOnBorder = smoothstep( 0.0, 1.0, fadeOnBorder );
planarWeight *= lerp( fadeOnBorder, 1.0, 1.0 - min( abs(distanceToPlanarReflPlane) * 1000.0, 1.0 ) );
//Fade out across a 20° tolerance between surface normal and reflection plane.
// (x - cos20) / (1-cos20);
// x/(1-cos20) - cos20/(1-cos20);
// x * 16.581718739 - 15.581718739;
planarWeight *= saturate( dot( planarReflection.xyz, pixelData.normal.xyz ) * 16.581718739 - 15.581718739 );
// planarWeight *= pixelData.normal.z; //-
@property( hlms_use_ssr || vct_num_probes || ((envprobe_map && envprobe_map != target_envprobe_map) || parallax_correct_cubemaps) )
pixelData.envColourS = lerp( pixelData.envColourS, planarReflectionS, planarWeight );
@else
pixelData.envColourS += planarReflectionS * planarWeight;
@end
@end
@end ///use_planar_reflections