Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ReShade.fxh"
- texture2D texColor : COLOR;
- texture texHDR { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; MipLevels = 5; Format = RGBA16;};
- texture texNormals { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; MipLevels = 2; Format = RGBA16;};
- texture2D texDepth : DEPTH;
- sampler2D SamplerColor
- {
- Texture = texColor;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = Clamp;
- AddressV = Clamp;
- };
- sampler2D SamplerHDR
- {
- Texture = texHDR;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = Clamp;
- AddressV = Clamp;
- };
- sampler2D SamplerNormals
- {
- Texture = texNormals;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = Clamp;
- AddressV = Clamp;
- };
- sampler2D SamplerDepth
- {
- Texture = texDepth;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = Clamp;
- AddressV = Clamp;
- };
- uniform float Timer < source = "timer"; >;
- #define ScreenSize float4(BUFFER_WIDTH, BUFFER_RCP_WIDTH, float(BUFFER_WIDTH) / float(BUFFER_HEIGHT), float(BUFFER_HEIGHT) / float(BUFFER_WIDTH)) //x=Width, y=1/Width, z=ScreenScaleY, w=1/ScreenScaleY
- //#define PixelSize float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT)
- struct VS_OUTPUT_POST
- {
- float4 vpos : POSITION;
- float2 txcoord : TEXCOORD0;
- };
- VS_OUTPUT_POST VS_PostProcess(in uint id : SV_VertexID)
- {
- VS_OUTPUT_POST OUT;
- OUT.txcoord.x = (id == 2) ? 2.0 : 0.0;
- OUT.txcoord.y = (id == 1) ? 2.0 : 0.0;
- OUT.vpos = float4(OUT.txcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
- return OUT;
- }
- float GetLinearDepth(float2 coords)
- {
- return ReShade::GetLinearizedDepth(coords.xy);
- }
- float3 GetPosition(float2 coords)
- {
- return float3(coords.xy*2.0-1.0,1.0)*GetLinearDepth(coords.xy)*RESHADE_DEPTH_LINEARIZATION_FAR_PLANE;
- }
- float3 GetNormalFromDepth(float2 coords)
- {
- float3 offs = float3(ReShade::PixelSize.xy,0);
- float3 f = GetPosition(coords.xy);
- float3 d_dx1 = - f + GetPosition(coords.xy + offs.xz);
- float3 d_dx2 = f - GetPosition(coords.xy - offs.xz);
- float3 d_dy1 = - f + GetPosition(coords.xy + offs.zy);
- float3 d_dy2 = f - GetPosition(coords.xy - offs.zy);
- d_dx1 = lerp(d_dx1, d_dx2, abs(d_dx1.z) > abs(d_dx2.z));
- d_dy1 = lerp(d_dy1, d_dy2, abs(d_dy1.z) > abs(d_dy2.z));
- return -normalize(cross(d_dy1,d_dx1));
- }
- float4 PS_Init(VS_OUTPUT_POST IN) : COLOR
- {
- float4 res = tex2D(SamplerColor, IN.txcoord.xy);
- float lineardepth = GetLinearDepth(IN.txcoord.xy);
- float resgray = dot(res.xyz,0.333);
- res.a = resgray;
- return res;
- }
- float2 ParallaxOcclusionMap(in float2 baseTC, in float3 viewDirNrm, in int numSteps, in float displacement) {
- float step = 1.0 / (float)numSteps;
- float bumpScale = displacement;
- float2 delta = -float2(viewDirNrm.x, viewDirNrm.y) * bumpScale / ( numSteps);
- float NB0 = tex2D(SamplerHDR, baseTC).w;
- float height = 1 - step;
- float4 offset = float4(baseTC + delta, 0, 1);
- float NB1 = tex2D(SamplerHDR, offset.xy).w;
- int i;
- for (i = 0; i < numSteps; i++) {
- [flatten]
- if (NB1 >= height)
- break;
- NB0 = NB1;
- height -= step;
- offset.xy += delta;
- NB1 = tex2Dlod(SamplerHDR, offset).w;
- }
- float4 offsetBest = offset;
- float error = 1.0;
- float t1 = height;
- float t0 = t1 + step;
- float delta1 = t1 - NB1;
- float delta0 = t0 - NB0;
- float4 intersect = float4(delta * numSteps, delta * numSteps + baseTC);
- for (i = 0; i < 10; i++) {
- [flatten]
- if (abs(error) <= 0.01)
- break;
- float denom = delta1 - delta0;
- float t = (t0 * delta1 - t1 * delta0) / denom;
- offsetBest.xy = -t * intersect.xy + intersect.zw;
- float NB = tex2Dlod(SamplerHDR, offsetBest).w;
- error = t - NB;
- if (error < 0) {
- delta1 = error;
- t1 = t;
- }
- else {
- delta0 = error;
- t0 = t;
- }
- }
- return offsetBest.xy;
- }
- float4 PS_Normals(VS_OUTPUT_POST IN) : COLOR
- {
- float3 screenNormals = GetNormalFromDepth(IN.txcoord.xy);
- /* screenNormals.y = -screenNormals.y;*/
- screenNormals.xyz = screenNormals.xyz*0.5+0.5;
- return float4(screenNormals.xyz , 1.0);
- }
- float4 PS_Emboss(VS_OUTPUT_POST IN) : COLOR
- {
- float4 color = tex2D(SamplerHDR, IN.txcoord.xy);
- float2 texcoord = IN.txcoord.xy;
- float3 position = GetPosition(texcoord.xy);
- float3 scenenormals = tex2D(SamplerNormals, IN.txcoord.xy).xyz*2.0-1.0;
- float2 offsetBest = ParallaxOcclusionMap(IN.txcoord.xy, scenenormals.xyz, 20, 0.4/position.z);
- float3 offsetPosition = GetPosition(offsetBest);
- //offsetBest = lerp(offsetBest,texcoord.xy,length(offsetPosition-position) > 0.4);
- color = tex2D(SamplerHDR, offsetBest.xy);
- return color;
- }
- technique Emboss < bool enabled = 1; toggle = 0x20; >
- {
- pass Init
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Init;
- RenderTarget = texHDR;
- }
- pass Normals
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Normals;
- RenderTarget = texNormals;
- }
- pass Emboss
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Emboss;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement