From c0c11cbe92637e7150f54173fe31b411d1d2b563 Mon Sep 17 00:00:00 2001 From: Mikulas Florek Date: Fri, 20 Sep 2024 17:24:44 +0200 Subject: [PATCH] shader refactor wpos -> pos_ws --- data/pipelines/common.hlsli | 16 ++++++------- data/pipelines/curve_decal.hlsl | 4 ++-- data/pipelines/editor_icon.hlsl | 8 +++---- data/pipelines/impostor.hlsl | 18 +++++++-------- data/pipelines/particles.hlsl | 4 ++-- data/pipelines/procedural_geom.hlsl | 6 ++--- data/pipelines/surface_base.hlsli | 36 ++++++++++++++--------------- data/pipelines/terrain.hlsl | 12 +++++----- data/pipelines/water.hlsl | 36 ++++++++++++++--------------- data/pipelines/world_grid.hlsl | 2 +- src/renderer/pipeline.cpp | 1 - 11 files changed, 71 insertions(+), 72 deletions(-) diff --git a/data/pipelines/common.hlsli b/data/pipelines/common.hlsli index 5e5bbfd282..2561adcf7d 100644 --- a/data/pipelines/common.hlsli +++ b/data/pipelines/common.hlsli @@ -100,7 +100,7 @@ struct Surface { float shadow; float3 N; float3 V; - float3 wpos; + float3 pos_ws; float2 motion; }; @@ -250,8 +250,8 @@ Surface unpackSurface(float2 uv, uint gbuffer0, uint gbuffer1, uint gbuffer2, ui surface.roughness = gb0.a; surface.metallic = gb2.z; surface.emission = unpackEmission(gb2.x); - surface.wpos = getPositionWS(gbuffer_depth, uv, ndc_depth); - surface.V = normalize(-surface.wpos); + surface.pos_ws = getPositionWS(gbuffer_depth, uv, ndc_depth); + surface.V = normalize(-surface.pos_ws); surface.translucency = gb2.y; surface.ao = gb1.w; surface.shadow = gb2.w; @@ -491,7 +491,7 @@ float3 pointLightsLighting(Cluster cluster, Surface surface, uint shadow_atlas, float3 res = 0; for (int i = cluster.offset; i < cluster.offset + cluster.lights_count; ++i) { Light light = b_lights[b_cluster_map[i]]; - float3 lpos = surface.wpos.xyz - light.pos_radius.xyz; + float3 lpos = surface.pos_ws.xyz - light.pos_radius.xyz; float dist = length(lpos); float attn = pow(max(0, 1 - dist / light.pos_radius.w), light.color_attn.w); float3 L = -lpos / dist; @@ -569,7 +569,7 @@ float3 envProbesLighting(Cluster cluster, Surface surface) { int to = from + cluster.env_probes_count; for (int i = from; i < to; ++i) { int probe_idx = b_cluster_map[i]; - float3 lpos = b_env_probes[probe_idx].pos.xyz - surface.wpos.xyz; + float3 lpos = b_env_probes[probe_idx].pos.xyz - surface.pos_ws.xyz; float4 rot = b_env_probes[probe_idx].rot; float3 outer_range = b_env_probes[probe_idx].outer_range.xyz; float3 inner_range = b_env_probes[probe_idx].inner_range.xyz; @@ -618,7 +618,7 @@ float3 reflProbesLighting(Cluster cluster, Surface surface, uint reflection_prob int probe_idx = b_cluster_map[i]; ReflectionProbe probe = b_refl_probes[probe_idx]; float4 rot = probe.rot; - float3 lpos = probe.pos_layer.xyz - surface.wpos; + float3 lpos = probe.pos_layer.xyz - surface.pos_ws; uint layer = asuint(probe.pos_layer.w); float4 radiance_rgbm = sampleCubeArrayBindlessLod(LinearSamplerClamp, reflection_probes, float4(RV, layer), lod); float3 radiance = radiance_rgbm.rgb * radiance_rgbm.a * 4; @@ -656,9 +656,9 @@ float distanceInFog(float3 a, float3 b) { } float3 computeLighting(Cluster cluster, Surface surface, float3 light_direction, float3 light, uint shadowmap, uint shadow_atlas, uint reflection_probes, float2 frag_coord) { - float shadow = min(surface.shadow, getShadow(shadowmap, surface.wpos, surface.N, frag_coord)); + float shadow = min(surface.shadow, getShadow(shadowmap, surface.pos_ws, surface.N, frag_coord)); - float dist = max(0, (Global_fog_top - surface.wpos.y - Global_camera_world_pos.y) * Global_light_dir.y); + float dist = max(0, (Global_fog_top - surface.pos_ws.y - Global_camera_world_pos.y) * Global_light_dir.y); float3 fog_transmittance = Global_fog_enabled > 0 ? exp(-dist * Global_fog_scattering.rgb * 10) : 1; float3 res = computeDirectLight(surface, light_direction, light * shadow * fog_transmittance); diff --git a/data/pipelines/curve_decal.hlsl b/data/pipelines/curve_decal.hlsl index 7565e59de8..275337ab3a 100644 --- a/data/pipelines/curve_decal.hlsl +++ b/data/pipelines/curve_decal.hlsl @@ -97,11 +97,11 @@ cbuffer Dc : register(b4) { GBufferOutput mainPS(VSOutput input) { float2 screen_uv = input.position.xy / Global_framebuffer_size; - float3 wpos = getPositionWS(u_gbuffer_depth, screen_uv); + float3 pos_ws = getPositionWS(u_gbuffer_depth, screen_uv); float4 r = input.rot; r.w = -r.w; - float3 lpos = rotateByQuat(r, wpos - input.pos); + float3 lpos = rotateByQuat(r, pos_ws - input.pos); if (any(abs(lpos) > input.half_extents)) discard; float2 bezier_dist = sdBezier(lpos.xz, input.bezier.xy, 0, input.bezier.zw); diff --git a/data/pipelines/editor_icon.hlsl b/data/pipelines/editor_icon.hlsl index 69b72e31c8..5cb88753f3 100644 --- a/data/pipelines/editor_icon.hlsl +++ b/data/pipelines/editor_icon.hlsl @@ -4,7 +4,7 @@ struct VSOutput { float2 uv : TEXCOORD0; - float3 wpos : TEXCOORD1; + float3 pos_ws : TEXCOORD1; float3 normal : TEXCOORD2; float4 position : SV_POSITION; }; @@ -34,7 +34,7 @@ VSOutput mainVS(Input input) { output.uv = 0; #endif float4 p = mul(float4(input.position, 1), mul(u_model, Global_view)); - output.wpos = p.xyz; + output.pos_ws = p.xyz; output.normal = input.normal; output.position = mul(p, Global_projection_no_jitter); return output; @@ -42,7 +42,7 @@ VSOutput mainVS(Input input) { float4 mainPS(VSOutput input) : SV_TARGET { float2 screen_uv = input.position.xy / Global_framebuffer_size; - float3 wpos = getPositionWS(u_gbuffer_depth, screen_uv); + float3 pos_ws = getPositionWS(u_gbuffer_depth, screen_uv); float4 albedo = sampleBindless(LinearSampler, t_albedo, input.uv); #ifdef ALPHA_CUTOUT if (albedo.a < 0.5) discard; @@ -51,6 +51,6 @@ float4 mainPS(VSOutput input) : SV_TARGET { float4 o_color; o_color.rgb = albedo.rgb * saturate(max(0, -d) + 0.25 * max(0, d) + 0.25); o_color.a = 1; - if(length(wpos) < length(input.wpos)) o_color.rgb *= 0.25; + if(length(pos_ws) < length(input.pos_ws)) o_color.rgb *= 0.25; return o_color; } \ No newline at end of file diff --git a/data/pipelines/impostor.hlsl b/data/pipelines/impostor.hlsl index 2f43ad18cc..51da451588 100644 --- a/data/pipelines/impostor.hlsl +++ b/data/pipelines/impostor.hlsl @@ -20,7 +20,7 @@ struct VSOutput { float2 uv : TEXCOORD0; float3 normal : TEXCOORD1; float3 tangent : TEXCOORD2; - float4 wpos : TEXCOORD3; + float4 pos_ws : TEXCOORD3; #if !defined DEPTH && defined HAS_SELFSHADOW float4 shadow_coefs : TEXCOORD4; #endif @@ -95,9 +95,9 @@ float2 dirToGrid(float3 vec) { output.lod = 1; output.tangent = tangent_space[0]; output.normal = tangent_space[2]; - output.wpos = float4(p, 1); + output.pos_ws = float4(p, 1); - output.position = mul(output.wpos, Pass_view_projection); + output.position = mul(output.pos_ws, Pass_view_projection); return output; } #else @@ -145,9 +145,9 @@ float2 dirToGrid(float3 vec) { p *= scale; output.tangent = tangent_space[0]; output.normal = tangent_space[2]; - output.wpos = float4(instance_pos + p, 1); + output.pos_ws = float4(instance_pos + p, 1); - output.position = mul(output.wpos, Pass_view_projection); + output.position = mul(output.pos_ws, Pass_view_projection); return output; } #endif @@ -166,8 +166,8 @@ Surface getSurface(VSOutput input) { normalize(cross(input.normal, input.tangent)) ); - data.wpos = input.wpos.xyz; - data.V = normalize(-data.wpos); + data.pos_ws = input.pos_ws.xyz; + data.V = normalize(-data.pos_ws); data.roughness = u_roughness; data.metallic = u_metallic; #ifdef HAS_NORMAL @@ -180,7 +180,7 @@ Surface getSurface(VSOutput input) { data.emission = u_emission; data.translucency = u_translucency; data.ao = 1; - data.motion = computeStaticObjectMotionVector(input.wpos.xyz); + data.motion = computeStaticObjectMotionVector(input.pos_ws.xyz); #if !defined DEPTH && defined HAS_SELFSHADOW float4 self_shadow = sampleBindless(LinearSampler, t_self_shadow, input.uv); @@ -242,7 +242,7 @@ Surface getSurface(VSOutput input) { , Global_light_color.rgb * Global_light_intensity * surface.shadow); res += surface.emission * surface.albedo; - float linear_depth = dot(surface.wpos.xyz, Pass_view_dir.xyz); + float linear_depth = dot(surface.pos_ws.xyz, Pass_view_dir.xyz); Cluster cluster = getClusterLinearDepth(linear_depth); //res += pointLightsLighting(cluster, surface, shadow_atlas); res += envProbesLighting(cluster, surface); diff --git a/data/pipelines/particles.hlsl b/data/pipelines/particles.hlsl index 5bc228e38c..a17e748fd6 100644 --- a/data/pipelines/particles.hlsl +++ b/data/pipelines/particles.hlsl @@ -48,7 +48,7 @@ float4 mainPS(VSOutput input) : SV_TARGET { float4 c = sampleBindless(LinearSampler, t_texture, input.uv) * saturate(input.color); data.N = 0; data.V = 0; - data.wpos = 0; + data.pos_ws = 0; data.albedo = c.rgb; data.alpha = c.a; data.emission = input.emission; @@ -58,7 +58,7 @@ float4 mainPS(VSOutput input) : SV_TARGET { data.metallic = 0; data.translucency = 0; - float linear_depth = dot(data.wpos.xyz, Pass_view_dir.xyz); + float linear_depth = dot(data.pos_ws.xyz, Pass_view_dir.xyz); Cluster cluster = getClusterLinearDepth(linear_depth, input.position.xy); float4 o_color; o_color.rgb = computeLighting(cluster, data, Global_light_dir.xyz, Global_light_color.rgb * Global_light_intensity, Global_shadowmap, Global_shadow_atlas, Global_reflection_probes, input.position.xy); diff --git a/data/pipelines/procedural_geom.hlsl b/data/pipelines/procedural_geom.hlsl index 3ff441c3e8..a06ce21024 100644 --- a/data/pipelines/procedural_geom.hlsl +++ b/data/pipelines/procedural_geom.hlsl @@ -66,8 +66,8 @@ Surface getSurface(VSOutput input) { surface.alpha = 1; surface.emission = u_emission; surface.translucency = u_translucency; - surface.wpos = input.pos_ws.xyz; - surface.V = normalize(-surface.wpos); + surface.pos_ws = input.pos_ws.xyz; + surface.V = normalize(-surface.pos_ws); surface.motion = computeStaticObjectMotionVector(input.pos_ws.xyz); return surface; } @@ -85,7 +85,7 @@ Surface getSurface(VSOutput input) { float4 mainPS(VSOutput input) : SV_TARGET { Surface surface = getSurface(); - float linear_depth = dot(surface.wpos.xyz, Pass_view_dir.xyz); + float linear_depth = dot(surface.pos_ws.xyz, Pass_view_dir.xyz); Cluster cluster = getClusterLinearDepth(linear_depth, input.position.xy); float4 result; result.rgb = computeLighting(cluster, surface, Global_light_dir.xyz, Global_light_color.rgb * Global_light_intensity, u_shadowmap, u_shadow_atlas, u_reflection_probes, input.position.xy); diff --git a/data/pipelines/surface_base.hlsli b/data/pipelines/surface_base.hlsli index cac8c8a573..3577bcbb8e 100644 --- a/data/pipelines/surface_base.hlsli +++ b/data/pipelines/surface_base.hlsli @@ -5,7 +5,7 @@ #endif struct VSOutput { - float4 wpos : TEXCOORD0; + float4 pos_ws : TEXCOORD0; float3 normal : TEXCOORD1; #ifdef UV0_ATTR float2 uv : TEXCOORD2; @@ -109,8 +109,8 @@ VSOutput mainVS(VSInput input) { #endif #ifdef AUTOINSTANCED float3 p = input.position.xyz * input.i_scale.xyz; - output.wpos = float4(input.i_pos_lod.xyz + rotateByQuat(input.i_rot, p), 1); - output.position = mul(output.wpos, Pass_view_projection); + output.pos_ws = float4(input.i_pos_lod.xyz + rotateByQuat(input.i_rot, p), 1); + output.position = mul(output.pos_ws, Pass_view_projection); output.normal = rotateByQuat(input.i_rot, input.normal); #ifdef HAS_LOD output.lod = input.i_pos_lod.w; @@ -123,8 +123,8 @@ VSOutput mainVS(VSInput input) { output.tangent = rotateByQuat(rot_quat, input.tangent); #endif float3 p = input.position * input.i_pos_scale.w; - output.wpos = float4(input.i_pos_scale.xyz + rotateByQuat(rot_quat, p), 1); - output.position = mul(output.wpos, Pass_view_projection); + output.pos_ws = float4(input.i_pos_scale.xyz + rotateByQuat(rot_quat, p), 1); + output.position = mul(output.pos_ws, Pass_view_projection); #elif defined GRASS output.normal = rotateByQuat(input.i_rot, input.normal); #ifdef TANGENT_ATTR @@ -132,19 +132,19 @@ VSOutput mainVS(VSInput input) { #endif float3 p = input.position; output.pos_y = p.y; - output.wpos = float4(input.i_pos_scale.xyz + rotateByQuat(input.i_rot, input.position * input.i_pos_scale.w), 1); - output.wpos.xyz += u_grass_origin; + output.pos_ws = float4(input.i_pos_scale.xyz + rotateByQuat(input.i_rot, input.position * input.i_pos_scale.w), 1); + output.pos_ws.xyz += u_grass_origin; #ifdef COLOR0_ATTR //output.color = input.color; #endif - output.position = mul(output.wpos, Pass_view_projection); + output.position = mul(output.pos_ws, Pass_view_projection); #elif defined DYNAMIC output.normal = rotateByQuat(input.i_rot, input.normal); #ifdef TANGENT_ATTR output.tangent = rotateByQuat(input.i_rot, input.tangent); #endif - output.wpos = float4(input.i_pos_lod.xyz + rotateByQuat(input.i_rot, input.position * input.i_scale.xyz), 1); - output.position = mul(output.wpos, Pass_view_projection); + output.pos_ws = float4(input.i_pos_lod.xyz + rotateByQuat(input.i_rot, input.position * input.i_scale.xyz), 1); + output.position = mul(output.pos_ws, Pass_view_projection); output.prev_ndcpos_no_jitter = float4(input.i_prev_pos_lod.xyz + rotateByQuat(input.i_prev_rot, input.position * input.i_prev_scale.xyz), 1); output.prev_ndcpos_no_jitter = mul(output.prev_ndcpos_no_jitter, mul(Global_view_projection_no_jitter, Global_reprojection)); #elif defined SKINNED @@ -170,8 +170,8 @@ VSOutput mainVS(VSInput input) { #else mpos = input.position; #endif - output.wpos = mul(float4(transformByDualQuat(dq, mpos), 1), mtx); - output.position = mul(output.wpos, Pass_view_projection); + output.pos_ws = mul(float4(transformByDualQuat(dq, mpos), 1), mtx); + output.position = mul(output.pos_ws, Pass_view_projection); // TODO previous frame bone positions output.prev_ndcpos_no_jitter = mul(float4(transformByDualQuat(dq, mpos), 1), prev_matrix); output.prev_ndcpos_no_jitter = mul(output.prev_ndcpos_no_jitter, mul(Global_view_projection_no_jitter, Global_reprojection)); @@ -181,22 +181,22 @@ VSOutput mainVS(VSInput input) { #ifdef TANGENT_ATTR output.tangent = mul(input.tangent, rot_mtx); #endif - output.wpos = mul(float4(input.position, 1), model_mtx); - output.position = mul(output.wpos, Pass_view_projection); + output.pos_ws = mul(float4(input.position, 1), model_mtx); + output.position = mul(output.pos_ws, Pass_view_projection); #endif return output; } Surface getSurfaceEx(VSOutput input) { Surface data = getSurface(input); - float4 p = mul(input.wpos, Global_view_projection_no_jitter); + float4 p = mul(input.pos_ws, Global_view_projection_no_jitter); #if defined DYNAMIC || defined SKINNED float2 prev_pos_projected = input.prev_ndcpos_no_jitter.xy / input.prev_ndcpos_no_jitter.w; data.motion = prev_pos_projected.xy - p.xy / p.w; #else - data.motion = computeStaticObjectMotionVector(input.wpos.xyz); + data.motion = computeStaticObjectMotionVector(input.pos_ws.xyz); #endif - data.V = normalize(-data.wpos); + data.V = normalize(-data.pos_ws); return data; } @@ -228,7 +228,7 @@ Surface getSurfaceEx(VSOutput input) { Surface data = getSurfaceEx(input); - float linear_depth = dot(data.wpos.xyz, Pass_view_dir.xyz); + float linear_depth = dot(data.pos_ws.xyz, Pass_view_dir.xyz); Cluster cluster = getClusterLinearDepth(linear_depth, frag_coord.xy); float4 result; result.rgb = computeLighting(cluster, data, Global_light_dir.xyz, Global_light_color.rgb * Global_light_intensity, u_shadowmap, u_shadow_atlas, u_reflection_probes, frag_coord); diff --git a/data/pipelines/terrain.hlsl b/data/pipelines/terrain.hlsl index 0a0a96da24..9e5e220544 100644 --- a/data/pipelines/terrain.hlsl +++ b/data/pipelines/terrain.hlsl @@ -30,7 +30,7 @@ struct VSOutput { #ifndef DEPTH float2 uv : TEXCOORD0; float dist2 : TEXCOORD1; - float3 wpos : TEXCOORD2; + float3 pos_ws : TEXCOORD2; #endif float4 position : SV_POSITION; }; @@ -61,11 +61,11 @@ VSOutput mainVS(uint vertex_id : SV_VertexID, uint instance_id : SV_InstanceID) float h = sampleBindlessLod(LinearSamplerClamp, t_heightmap, hm_uv, 0).x * u_terrain_scale.y; #endif - float3 wpos = u_position.xyz + v + float3(0, h, 0); + float3 pos_ws = u_position.xyz + v + float3(0, h, 0); #ifndef DEPTH - output.wpos = wpos; + output.pos_ws = pos_ws; #endif - float4 p = mul(float4(wpos, 1), Pass_view); + float4 p = mul(float4(pos_ws, 1), Pass_view); #ifndef DEPTH output.dist2 = dot(p.xyz, p.xyz); #endif @@ -202,10 +202,10 @@ VSOutput mainVS(uint vertex_id : SV_VertexID, uint instance_id : SV_InstanceID) } #ifndef DEPTH - surface.motion = computeStaticObjectMotionVector(input.wpos); + surface.motion = computeStaticObjectMotionVector(input.pos_ws); #endif - surface.wpos = 0; + surface.pos_ws = 0; surface.roughness = u_roughness; surface.metallic = u_metallic; surface.emission = u_emission; diff --git a/data/pipelines/water.hlsl b/data/pipelines/water.hlsl index 706156a65a..853c335e6a 100644 --- a/data/pipelines/water.hlsl +++ b/data/pipelines/water.hlsl @@ -39,7 +39,7 @@ struct VSOutput { float2 uv : TEXCOORD0; float3 normal : TEXCOORD1; float3 tangent : TEXCOORD2; - float4 wpos : TEXCOORD3; + float4 pos_ws : TEXCOORD3; #ifdef _HAS_ATTR2 //float2 masks : TEXCOORD4; #endif @@ -62,20 +62,20 @@ VSOutput mainVS(VSInput input) { output.normal = rotateByQuat(input.i_rot, normal); output.tangent = rotateByQuat(input.i_rot, tangent); float3 p = input.position * input.i_scale.xyz; - output.wpos = float4(input.i_pos_lod.xyz + rotateByQuat(input.i_rot, p), 1); + output.pos_ws = float4(input.i_pos_lod.xyz + rotateByQuat(input.i_rot, p), 1); #elif defined GRASS #error TODO #else float4x4 model_mtx = u_model; output.normal = float3x3(model_mtx) * normal; output.tangent = float3x3(model_mtx) * tangent; - output.wpos = mul(float4(input.position, 1), model_mtx); + output.pos_ws = mul(float4(input.position, 1), model_mtx); #endif #ifdef _HAS_ATTR2 //output.masks = a_masks; #endif - output.position = mul(output.wpos, Pass_view_projection); + output.position = mul(output.pos_ws, Pass_view_projection); return output; } @@ -142,12 +142,12 @@ float2 raycast(float3 csOrig, float3 csDir, float stride, float jitter) { return -1.0f.xx; } -float3 getReflectionColor(float3 view, float3 normal, float dist, float3 wpos) +float3 getReflectionColor(float3 view, float3 normal, float dist, float3 pos_ws) { #ifdef SSR - float4 o = mul(float4(wpos, 1), Global_view); + float4 o = mul(float4(pos_ws, 1), Global_view); float3 d = mul(reflect(-view, normal), float3x3(Global_view)); - float2 hit = raycast(o.xyz, d, 4, hash(wpos.xy + Global_time)); + float2 hit = raycast(o.xyz, d, 4, hash(pos_ws.xy + Global_time)); if (hit.x >= 0) { return sampleBindless(LinearSamplerClamp, u_bg, hit.xy / Global_framebuffer_size.xy).rgb; } @@ -158,17 +158,17 @@ float3 getReflectionColor(float3 view, float3 normal, float dist, float3 wpos) return radiance_rgbm.rgb * radiance_rgbm.a * 4; } -float getWaterDepth(float3 wpos, float3 view, float3 normal) +float getWaterDepth(float3 pos_ws, float3 view, float3 normal) { - float4 screen_pos = mul(float4(wpos, 1), Global_view_projection); + float4 screen_pos = mul(float4(pos_ws, 1), Global_view_projection); screen_pos /= screen_pos.w; float depth = sampleBindless(LinearSamplerClamp, u_depthbuffer, toScreenUV(screen_pos.xy * 0.5 + 0.5)).x; return toLinearDepth(depth) - toLinearDepth(screen_pos.z); } -float4 getRefraction(float3 wpos) +float4 getRefraction(float3 pos_ws) { - float4 screen_pos = mul(float4(wpos, 1), Global_view_projection); + float4 screen_pos = mul(float4(pos_ws, 1), Global_view_projection); screen_pos /= screen_pos.w; return sampleBindless(LinearSamplerClamp, u_bg, toScreenUV(screen_pos.xy * 0.5 + 0.5)); } @@ -201,7 +201,7 @@ float3 getSurfaceNormal(float2 uv, float normal_strength, out float h00) float4 mainPS(VSOutput input) : SV_TARGET { - float3 V = normalize(-input.wpos.xyz); + float3 V = normalize(-input.pos_ws.xyz); float3 L = Global_light_dir.xyz; float3x3 tbn = float3x3( @@ -219,12 +219,12 @@ float4 mainPS(VSOutput input) : SV_TARGET float3 wnormal = getSurfaceNormal(input.uv, normal_strength, h); wnormal = normalize(mul(wnormal, tbn)); - //float shadow = getShadow(u_shadowmap, input.wpos.xyz, wnormal); + //float shadow = getShadow(u_shadowmap, input.pos_ws.xyz, wnormal); - float dist = length(input.wpos.xyz); - float3 view = normalize(-input.wpos.xyz); - float3 refl_color = getReflectionColor(view, wnormal, dist * normal_strength, input.wpos.xyz) * u_reflection_multiplier; - float water_depth = getWaterDepth(input.wpos.xyz, view, wnormal)- saturate(h * 0.4); + float dist = length(input.pos_ws.xyz); + float3 view = normalize(-input.pos_ws.xyz); + float3 refl_color = getReflectionColor(view, wnormal, dist * normal_strength, input.pos_ws.xyz) * u_reflection_multiplier; + float water_depth = getWaterDepth(input.pos_ws.xyz, view, wnormal)- saturate(h * 0.4); float3 halfvec = normalize(view + Global_light_dir.xyz); @@ -243,7 +243,7 @@ float4 mainPS(VSOutput input) : SV_TARGET float refraction_distortion = u_refraction_distortion; - float3 refraction = getRefraction(input.wpos.xyz + float3(wnormal.xz, 0) * u_refraction_distortion * t).rgb; + float3 refraction = getRefraction(input.pos_ws.xyz + float3(wnormal.xz, 0) * u_refraction_distortion * t).rgb; refraction *= lerp(1.0f.xxx, u_ground_tint.rgb, t); refraction *= transmittance; diff --git a/data/pipelines/world_grid.hlsl b/data/pipelines/world_grid.hlsl index 9dbbd2d6b4..ee071d09cd 100644 --- a/data/pipelines/world_grid.hlsl +++ b/data/pipelines/world_grid.hlsl @@ -9,7 +9,7 @@ //@uniform "Translucency", "normalized_float", 0 Surface getSurface(VSOutput input) { - float3 t = fmod(abs(input.wpos.xyz + Global_camera_world_pos.xyz + 0.5), 2.0f.xxx); + float3 t = fmod(abs(input.pos_ws.xyz + Global_camera_world_pos.xyz + 0.5), 2.0f.xxx); float ff = dot(floor(t), 1.0f.xxx); ff = fmod(ff, 2); float4 c = float4(u_material_color.xyzw); diff --git a/src/renderer/pipeline.cpp b/src/renderer/pipeline.cpp index 16a4ce3e89..5f6c93d234 100644 --- a/src/renderer/pipeline.cpp +++ b/src/renderer/pipeline.cpp @@ -33,7 +33,6 @@ #include "terrain.h" #include "texture.h" -// TODO remaining .shd shaders // TODO vsync // TODO env probe lighting is off // TODO temporal upsample