diff --git a/engine/rend/shaders/lit_mesh.frag.hlsl b/engine/rend/shaders/lit_mesh.frag.hlsl index 2a6f215..941b278 100644 --- a/engine/rend/shaders/lit_mesh.frag.hlsl +++ b/engine/rend/shaders/lit_mesh.frag.hlsl @@ -188,7 +188,8 @@ PixelOutput main( float3 WorldPos: TEXCOORD1, float3 Normal: TEXCOORD2, float4 DirectionalShadowFragPos: TEXCOORD3, - uint Instance: TEXCOORD4 + uint Instance: TEXCOORD4, + float3 ScreenNormal: TEXCOORD5 ) { float4 s; @@ -254,7 +255,7 @@ PixelOutput main( PixelOutput o; o.Position = float4(WorldPos, 1.0); - o.Normal = float4(Normal, 1.0); + o.Normal = float4(ScreenNormal, 1.0); o.Color = float4(c2, alpha); o.Emissive = float4(0.0, 0.0, 0.0, 1.0); diff --git a/engine/rend/shaders/lit_mesh.frag.json b/engine/rend/shaders/lit_mesh.frag.json index a619351..c88358d 100644 --- a/engine/rend/shaders/lit_mesh.frag.json +++ b/engine/rend/shaders/lit_mesh.frag.json @@ -6,7 +6,7 @@ } ], "types" : { - "_22" : { + "_23" : { "name" : "type.Uniforms", "members" : [ { @@ -46,7 +46,7 @@ } ] }, - "_25" : { + "_26" : { "name" : "Scene", "members" : [ { @@ -78,12 +78,12 @@ } ] }, - "_24" : { + "_25" : { "name" : "type.StructuredBuffer.Scene", "members" : [ { "name" : "_m0", - "type" : "_25", + "type" : "_26", "array" : [ 0 ], @@ -121,6 +121,11 @@ "type" : "uint", "name" : "in.var.TEXCOORD4", "location" : 4 + }, + { + "type" : "vec3", + "name" : "in.var.TEXCOORD5", + "location" : 5 } ], "outputs" : [ @@ -199,7 +204,7 @@ ], "ssbos" : [ { - "type" : "_24", + "type" : "_25", "name" : "scene", "readonly" : true, "block_size" : 0, @@ -209,7 +214,7 @@ ], "ubos" : [ { - "type" : "_22", + "type" : "_23", "name" : "type.Uniforms", "block_size" : 80, "set" : 3, diff --git a/engine/rend/shaders/meshes.vert.hlsl b/engine/rend/shaders/meshes.vert.hlsl index 970779d..4dbf89d 100644 --- a/engine/rend/shaders/meshes.vert.hlsl +++ b/engine/rend/shaders/meshes.vert.hlsl @@ -19,6 +19,7 @@ struct Output float3 Normal: TEXCOORD2; float4 DirectionalShadowFragPos: TEXCOORD3; uint Instance: TEXCOORD4; + float3 ScreenNormal: TEXCOORD5; float4 Position : SV_Position; }; @@ -40,6 +41,7 @@ StructuredBuffer scene: register(t0, space0); cbuffer Uniforms : register(b0, space1) { float4x4 ViewProjection; + float4x4 NoTranslateView; float4x4 ShadowMapProjection; float time; }; @@ -82,6 +84,10 @@ Output main(Input input) float4x4 noTranslate = ExtractRotation(scene[input.Instance].Model); output.Normal = normalize(mul(noTranslate, float4(input.Normal, 1.0))).xyz; + + float4x4 noTranslateScreen = mul(NoTranslateView, noTranslate); + output.ScreenNormal = mul(noTranslateScreen, float4(input.Normal, 1.0)).xyz; + output.DirectionalShadowFragPos = mul(ShadowMapProjection, WorldPos); output.Instance = input.Instance; diff --git a/engine/rend/shaders/meshes.vert.json b/engine/rend/shaders/meshes.vert.json index ab8acfa..218501d 100644 --- a/engine/rend/shaders/meshes.vert.json +++ b/engine/rend/shaders/meshes.vert.json @@ -6,7 +6,7 @@ } ], "types" : { - "_14" : { + "_15" : { "name" : "Scene", "members" : [ { @@ -38,12 +38,12 @@ } ] }, - "_13" : { + "_14" : { "name" : "type.StructuredBuffer.Scene", "members" : [ { "name" : "_m0", - "type" : "_14", + "type" : "_15", "array" : [ 0 ], @@ -55,7 +55,7 @@ } ] }, - "_16" : { + "_17" : { "name" : "type.Uniforms", "members" : [ { @@ -66,16 +66,23 @@ "row_major" : true }, { - "name" : "ShadowMapProjection", + "name" : "NoTranslateView", "type" : "mat4", "offset" : 64, "matrix_stride" : 16, "row_major" : true }, + { + "name" : "ShadowMapProjection", + "type" : "mat4", + "offset" : 128, + "matrix_stride" : 16, + "row_major" : true + }, { "name" : "time", "type" : "float", - "offset" : 128 + "offset" : 192 } ] } @@ -122,11 +129,16 @@ "type" : "uint", "name" : "out.var.TEXCOORD4", "location" : 4 + }, + { + "type" : "vec3", + "name" : "out.var.TEXCOORD5", + "location" : 5 } ], "ssbos" : [ { - "type" : "_13", + "type" : "_14", "name" : "scene", "readonly" : true, "block_size" : 0, @@ -136,9 +148,9 @@ ], "ubos" : [ { - "type" : "_16", + "type" : "_17", "name" : "type.Uniforms", - "block_size" : 132, + "block_size" : 196, "set" : 1, "binding" : 0 } diff --git a/engine/rend/shaders/postProc.frag.hlsl b/engine/rend/shaders/postProc.frag.hlsl index 4344326..e8c0680 100644 --- a/engine/rend/shaders/postProc.frag.hlsl +++ b/engine/rend/shaders/postProc.frag.hlsl @@ -130,10 +130,15 @@ float4 main(float2 UV : TEXCOORD0) : SV_Target0 // c = float3(uv.x, uv.y, 0.0); // c = SsaoTexture.Sample(Sampler2, uv).x; - // float ssao = SsaoTexture.Sample(Sampler2, uv).x; + // float4 ssao = SsaoTexture.Sample(Sampler2, uv); float ssao = blurSSAO(uv); c = c * ssao; + + // float4 x = SsaoTexture.Sample(Sampler2, uv); + // c = x; + + // c = ssao.xyz; c.x *= 1.0 + 0.000001 * EmissiveTexture.Sample(Sampler1, uv).x; c.x *= 1.0 + 0.000001 * ColorTexture.Sample(Sampler0, uv).x; diff --git a/engine/rend/shaders/ssao.frag.hlsl b/engine/rend/shaders/ssao.frag.hlsl index adea668..8f5f099 100644 --- a/engine/rend/shaders/ssao.frag.hlsl +++ b/engine/rend/shaders/ssao.frag.hlsl @@ -34,46 +34,66 @@ float4 main(float2 UV: TEXCOORD0) : SV_Target0 { return 1.0; } - float3 normal = normalize(mul(View, NormalTexture.Sample(Sampler1, uv)).xyz); + + float3 normal = NormalTexture.Sample(Sampler1, uv).xyz; float3 randomVec = normalize(NoiseTexture.Sample(Sampler2, uv * scale).xyz); + // randomVec = normalize(float3(1.0, 1.0, 0.0) + randomVec * 0.00001); + + float3 x = normal; float3 tangent = normalize(randomVec - normal * dot(randomVec, normal)); float3 bitangent = cross(normal, tangent); - float3x3 TBN = float3x3(tangent, bitangent, normal); + float3x3 TBN = transpose(float3x3(tangent, bitangent, normal)); + + x = tangent; float occlusion = 0.0; + x = float3(0.0,0.0,0.0); for(int i = 0; i < numSamples; i += 1) { - float3 samplePos = mul(TBN, SamplingKernel[i]); // from tangent to view-space + float3 samplePos = mul(TBN, SamplingKernel[i] + float3(0.0, 0.0, 0.01)); //float3(0.0, 0.0, 1.0)); // from tangent to view-space samplePos = position + samplePos * radius; // project sample position (to sample texture) (to get position on screen/texture) float4 offset = float4(samplePos, 1.0); + // c = offset - float4(position, 1.0); + offset = mul(Projection, offset); // from view to clip-space offset.xyz /= offset.w; // perspective divide offset.xyz = offset.xyz * 0.5 + 0.5; // transform to range 0.0 - 1.0 offset.y *= -1; + offset.y += 1.0; + + // x += (float3(offset.xy - uv, 0.0) * 0.5 + 0.5) / numSamples; // get sample depth float sampleDepth = mul(View, PositionTexture.Sample(Sampler0, offset.xy)).z; // texture(gPosition, offset.xy).z; // get depth value of kernel sample + x += float3(sampleDepth, sampleDepth, sampleDepth) / numSamples; + x -= float3(samplePos.z, samplePos.z, samplePos.z) / numSamples; // c = float4(sampleDepth, sampleDepth, sampleDepth, 1.0) / 100; // c = float4(offset) * 2.0 - 0.6 ; // range check & accumulate float rangeCheck = smoothstep(0.0, 1.0, radius / abs(position.z - sampleDepth)); - occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck; + occlusion += (sampleDepth <= samplePos.z - bias ? 1.0 : 0.0) * rangeCheck; + + if (samplePos.z > 30) + { + occlusion *= max(0.0, 1.0 - ((samplePos.z - 30) / 300)); + } } + x.z = 0; occlusion = 1.0 - (occlusion / numSamples); - + // occlusion = 1.0 - occlusion; // c += PositionTexture.Sample(Sampler0, uv).x * 0.00001; // c += NormalTexture.Sample(Sampler1, uv).x * 0.00001; // c += NoiseTexture.Sample(Sampler2, uv).x * 0.00001; // float x = length(c); // c = float4(x, x, x, 1.0); - - c = occlusion; + //c = float4(x, 1.0); + return c + occlusion * 0.00001; } diff --git a/engine/rend/src/sgpu/renderer.zig b/engine/rend/src/sgpu/renderer.zig index c1f29c7..62d8fb2 100644 --- a/engine/rend/src/sgpu/renderer.zig +++ b/engine/rend/src/sgpu/renderer.zig @@ -585,6 +585,7 @@ pub const Renderer = struct { const ptr: *meshes_vert.Uniforms = @ptrCast(@alignCast(&data)); if (self.activeCamera) |camera| { ptr.ViewProjection = @bitCast(camera.final); + ptr.NoTranslateView = @bitCast(camera.noTranslate); } ptr.ShadowMapProjection = @bitCast(self.shadowMapProjection); // ptr.ViewProjection = @bitCast(self.shadowMapProjection); diff --git a/projects/content/_shaders/dxil/lit_mesh.frag.dxil b/projects/content/_shaders/dxil/lit_mesh.frag.dxil index ab723e7..9dced69 100644 Binary files a/projects/content/_shaders/dxil/lit_mesh.frag.dxil and b/projects/content/_shaders/dxil/lit_mesh.frag.dxil differ diff --git a/projects/content/_shaders/dxil/meshes.vert.dxil b/projects/content/_shaders/dxil/meshes.vert.dxil index 817386d..147b51a 100644 Binary files a/projects/content/_shaders/dxil/meshes.vert.dxil and b/projects/content/_shaders/dxil/meshes.vert.dxil differ diff --git a/projects/content/_shaders/dxil/ssao.frag.dxil b/projects/content/_shaders/dxil/ssao.frag.dxil index 12b73f9..6eeb13b 100644 Binary files a/projects/content/_shaders/dxil/ssao.frag.dxil and b/projects/content/_shaders/dxil/ssao.frag.dxil differ diff --git a/projects/content/_shaders/msl/lit_mesh.frag.msl b/projects/content/_shaders/msl/lit_mesh.frag.msl index 5a036d0..bafc6ec 100644 --- a/projects/content/_shaders/msl/lit_mesh.frag.msl +++ b/projects/content/_shaders/msl/lit_mesh.frag.msl @@ -28,8 +28,8 @@ struct type_StructuredBuffer_Scene Scene _m0[1]; }; -constant float4 _90 = {}; -constant float3 _92 = {}; +constant float4 _91 = {}; +constant float3 _93 = {}; struct main0_out { @@ -46,152 +46,153 @@ struct main0_in float3 in_var_TEXCOORD2 [[user(locn2)]]; float4 in_var_TEXCOORD3 [[user(locn3)]]; uint in_var_TEXCOORD4 [[user(locn4)]]; + float3 in_var_TEXCOORD5 [[user(locn5)]]; }; fragment main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniforms [[buffer(0)]], const device type_StructuredBuffer_Scene& scene [[buffer(1)]], texture2d Texture0 [[texture(0)]], texture2d Texture1 [[texture(1)]], texture2d Texture2 [[texture(2)]], texture2d DirectionalShadowDepthMap [[texture(3)]], sampler Sampler0 [[sampler(0)]], sampler Sampler1 [[sampler(1)]], sampler Sampler2 [[sampler(2)]], sampler DirectionalShadowSampler [[sampler(3)]]) { main0_out out = {}; - int _101 = int(scene._m0[in.in_var_TEXCOORD4].textureMode); - int _102 = _101 & 240; - float4 _136; - if (_102 == 16) + int _103 = int(scene._m0[in.in_var_TEXCOORD4].textureMode); + int _104 = _103 & 240; + float4 _138; + if (_104 == 16) { - float3 _123 = float3(Texture0.sample(Sampler0, in.in_var_TEXCOORD0).x, Texture1.sample(Sampler1, in.in_var_TEXCOORD0).x, Texture2.sample(Sampler2, in.in_var_TEXCOORD0).x) + float3(-0.0625, -0.5, -0.5); - _136 = float4(dot(_123, float3(1.164000034332275390625, 0.0, 1.7929999828338623046875)), dot(_123, float3(1.164000034332275390625, -0.212999999523162841796875, -0.53299999237060546875)), dot(_123, float3(1.164000034332275390625, 2.111999988555908203125, 0.0)), 1.0); + float3 _125 = float3(Texture0.sample(Sampler0, in.in_var_TEXCOORD0).x, Texture1.sample(Sampler1, in.in_var_TEXCOORD0).x, Texture2.sample(Sampler2, in.in_var_TEXCOORD0).x) + float3(-0.0625, -0.5, -0.5); + _138 = float4(dot(_125, float3(1.164000034332275390625, 0.0, 1.7929999828338623046875)), dot(_125, float3(1.164000034332275390625, -0.212999999523162841796875, -0.53299999237060546875)), dot(_125, float3(1.164000034332275390625, 2.111999988555908203125, 0.0)), 1.0); } else { - float4 _135; - if (_102 == 0) + float4 _137; + if (_104 == 0) { - _135 = Texture0.sample(Sampler0, in.in_var_TEXCOORD0); + _137 = Texture0.sample(Sampler0, in.in_var_TEXCOORD0); } else { - _135 = _90; + _137 = _91; } - _136 = _135; + _138 = _137; } - float4 _142; - if ((_101 & 1) == 1) + float4 _144; + if ((_103 & 1) == 1) { - _142 = powr(_136, float4(2.2000000476837158203125)); + _144 = powr(_138, float4(2.2000000476837158203125)); } else { - _142 = _136; + _144 = _138; } - if (_142.w < 0.00999999977648258209228515625) + if (_144.w < 0.00999999977648258209228515625) { discard_fragment(); } - float3 _152 = float3(0.800000011920928955078125, 0.800000011920928955078125, 0.5) * Uniforms.lightPower; - float3 _199; + float3 _154 = float3(0.800000011920928955078125, 0.800000011920928955078125, 0.5) * Uniforms.lightPower; + float3 _201; do { - float3 _156 = Uniforms.lightPosition.xyz - in.in_var_TEXCOORD1; - float _157 = length(_156); - float _158 = _157 * _157; - float _164; - if (_157 > 2.0) + float3 _158 = Uniforms.lightPosition.xyz - in.in_var_TEXCOORD1; + float _159 = length(_158); + float _160 = _159 * _159; + float _166; + if (_159 > 2.0) { - _164 = 0.5 / _158; + _166 = 0.5 / _160; } else { - _164 = 1.0 / _158; + _166 = 1.0 / _160; } - float _169; - if (_157 > 4.0) + float _171; + if (_159 > 4.0) { - _169 = _164 * 0.5; + _171 = _166 * 0.5; } else { - _169 = _164; + _171 = _166; } - float _171 = (_157 > 15.0) ? 0.0 : _169; - float _173 = (_171 > 1.0) ? 1.0 : _171; + float _173 = (_159 > 15.0) ? 0.0 : _171; + float _175 = (_173 > 1.0) ? 1.0 : _173; if (length(in.in_var_TEXCOORD2) < 0.100000001490116119384765625) { - _199 = (in.in_var_TEXCOORD1 * _152) * _173; + _201 = (in.in_var_TEXCOORD1 * _154) * _175; break; } - float3 _180 = fast::normalize(_156); - _199 = ((_152 * precise::max(dot(_180, in.in_var_TEXCOORD2), 0.0)) * _173) + (((_152 * powr(precise::max(dot(in.in_var_TEXCOORD2, fast::normalize(_180 + fast::normalize(in.in_var_TEXCOORD1 - Uniforms.viewPos.xyz))), 0.0), 30.0)) * 2.0) * _173); + float3 _182 = fast::normalize(_158); + _201 = ((_154 * precise::max(dot(_182, in.in_var_TEXCOORD2), 0.0)) * _175) + (((_154 * powr(precise::max(dot(in.in_var_TEXCOORD2, fast::normalize(_182 + fast::normalize(in.in_var_TEXCOORD1 - Uniforms.viewPos.xyz))), 0.0), 30.0)) * 2.0) * _175); break; } while(false); - float3 _216 = ((in.in_var_TEXCOORD3.xyz / float3(in.in_var_TEXCOORD3.w)) * 0.5) + float3(0.5); - float3 _218; - _218.x = _216.x; - float2 _219 = _218.xy; - _219.y = -_216.y; - float _226; - int _229; + float3 _218 = ((in.in_var_TEXCOORD3.xyz / float3(in.in_var_TEXCOORD3.w)) * 0.5) + float3(0.5); + float3 _220; + _220.x = _218.x; + float2 _221 = _220.xy; + _221.y = -_218.y; + float _228; int _231; - _226 = 0.0; - _229 = 0; - _231 = -4; - float _227; - int _230; - for (; _231 <= 4; _226 = _227, _229 = _230, _231++) + int _233; + _228 = 0.0; + _231 = 0; + _233 = -4; + float _229; + int _232; + for (; _233 <= 4; _228 = _229, _231 = _232, _233++) { - _230 = _229; - _227 = _226; - for (int _240 = -4; _240 <= 4; ) + _232 = _231; + _229 = _228; + for (int _242 = -4; _242 <= 4; ) { - _230++; - _227 += float((in.in_var_TEXCOORD3.z - 0.004999999888241291046142578125) > DirectionalShadowDepthMap.sample(DirectionalShadowSampler, (_219 + float2(float(_240) * 0.000244140625, float(_231) * 0.000244140625))).x); - _240++; + _232++; + _229 += float((in.in_var_TEXCOORD3.z - 0.004999999888241291046142578125) > DirectionalShadowDepthMap.sample(DirectionalShadowSampler, (_221 + float2(float(_242) * 0.000244140625, float(_233) * 0.000244140625))).x); + _242++; continue; } } - float3 _269; - if ((_101 & 2) > 0) + float3 _271; + if ((_103 & 2) > 0) { - _269 = _142.xyz * 2.0; + _271 = _144.xyz * 2.0; } else { - _269 = _142.xyz * ((float3(0.100000001490116119384765625) + _199) + ((Uniforms.directionalLightColor.xyz * precise::max(dot(Uniforms.directionalLight.xyz, in.in_var_TEXCOORD2), 0.0)) * (1.0 - (_226 / float(_229))))); + _271 = _144.xyz * ((float3(0.100000001490116119384765625) + _201) + ((Uniforms.directionalLightColor.xyz * precise::max(dot(Uniforms.directionalLight.xyz, in.in_var_TEXCOORD2), 0.0)) * (1.0 - (_228 / float(_231))))); } - float4 _286; - if (_269.x > 1.0) + float4 _288; + if (_271.x > 1.0) { - float4 _285 = float4(0.0, 0.0, 0.0, 1.0); - _285.x = _269.x; - _286 = _285; + float4 _287 = float4(0.0, 0.0, 0.0, 1.0); + _287.x = _271.x; + _288 = _287; } else { - _286 = float4(0.0, 0.0, 0.0, 1.0); + _288 = float4(0.0, 0.0, 0.0, 1.0); } - float4 _291; - if (_269.y > 1.0) + float4 _293; + if (_271.y > 1.0) { - float4 _290 = _286; - _290.y = _269.y; - _291 = _290; + float4 _292 = _288; + _292.y = _271.y; + _293 = _292; } else { - _291 = _286; + _293 = _288; } - float4 _296; - if (_269.z > 1.0) + float4 _298; + if (_271.z > 1.0) { - float4 _295 = _291; - _295.z = _269.z; - _296 = _295; + float4 _297 = _293; + _297.z = _271.z; + _298 = _297; } else { - _296 = _291; + _298 = _293; } - out.out_var_SV_Target0 = float4(_269, _142.w); - out.out_var_SV_Target1 = _296; + out.out_var_SV_Target0 = float4(_271, _144.w); + out.out_var_SV_Target1 = _298; out.out_var_SV_Target2 = float4(in.in_var_TEXCOORD1, 1.0); - out.out_var_SV_Target3 = float4(in.in_var_TEXCOORD2, 1.0); + out.out_var_SV_Target3 = float4(in.in_var_TEXCOORD5, 1.0); return out; } diff --git a/projects/content/_shaders/msl/meshes.vert.msl b/projects/content/_shaders/msl/meshes.vert.msl index 4e8f7a3..0f92f0a 100644 --- a/projects/content/_shaders/msl/meshes.vert.msl +++ b/projects/content/_shaders/msl/meshes.vert.msl @@ -20,6 +20,7 @@ struct type_StructuredBuffer_Scene struct type_Uniforms { float4x4 ViewProjection; + float4x4 NoTranslateView; float4x4 ShadowMapProjection; float time; }; @@ -31,6 +32,7 @@ struct main0_out float3 out_var_TEXCOORD2 [[user(locn2)]]; float4 out_var_TEXCOORD3 [[user(locn3)]]; uint out_var_TEXCOORD4 [[user(locn4)]]; + float3 out_var_TEXCOORD5 [[user(locn5)]]; float4 gl_Position [[position]]; }; @@ -44,14 +46,17 @@ struct main0_in vertex main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniforms [[buffer(0)]], const device type_StructuredBuffer_Scene& scene [[buffer(1)]], uint gl_InstanceIndex [[instance_id]]) { main0_out out = {}; - float4 _51 = float4(in.in_var_TEXCOORD0, 1.0); - float4 _54 = scene._m0[gl_InstanceIndex].Model * _51; + float4 _53 = float4(in.in_var_TEXCOORD0, 1.0); + float4 _56 = scene._m0[gl_InstanceIndex].Model * _53; + float4x4 _91 = float4x4(float4(fast::normalize(float3(scene._m0[gl_InstanceIndex].Model[0][0], scene._m0[gl_InstanceIndex].Model[1][0], scene._m0[gl_InstanceIndex].Model[2][0])), 0.0), float4(fast::normalize(float3(scene._m0[gl_InstanceIndex].Model[0][1], scene._m0[gl_InstanceIndex].Model[1][1], scene._m0[gl_InstanceIndex].Model[2][1])), 0.0), float4(fast::normalize(float3(scene._m0[gl_InstanceIndex].Model[0][2], scene._m0[gl_InstanceIndex].Model[1][2], scene._m0[gl_InstanceIndex].Model[2][2])), 0.0), float4(0.0, 0.0, 0.0, 1.0)); + float4 _95 = float4(in.in_var_TEXCOORD1, 1.0); out.out_var_TEXCOORD0 = in.in_var_TEXCOORD3; - out.out_var_TEXCOORD1 = _54.xyz; - out.out_var_TEXCOORD2 = fast::normalize(float4(in.in_var_TEXCOORD1, 1.0) * float4x4(float4(fast::normalize(float3(scene._m0[gl_InstanceIndex].Model[0][0], scene._m0[gl_InstanceIndex].Model[1][0], scene._m0[gl_InstanceIndex].Model[2][0])), 0.0), float4(fast::normalize(float3(scene._m0[gl_InstanceIndex].Model[0][1], scene._m0[gl_InstanceIndex].Model[1][1], scene._m0[gl_InstanceIndex].Model[2][1])), 0.0), float4(fast::normalize(float3(scene._m0[gl_InstanceIndex].Model[0][2], scene._m0[gl_InstanceIndex].Model[1][2], scene._m0[gl_InstanceIndex].Model[2][2])), 0.0), float4(0.0, 0.0, 0.0, 1.0))).xyz; - out.out_var_TEXCOORD3 = Uniforms.ShadowMapProjection * _54; + out.out_var_TEXCOORD1 = _56.xyz; + out.out_var_TEXCOORD2 = fast::normalize(_95 * _91).xyz; + out.out_var_TEXCOORD3 = Uniforms.ShadowMapProjection * _56; out.out_var_TEXCOORD4 = gl_InstanceIndex; - out.gl_Position = Uniforms.ViewProjection * (scene._m0[gl_InstanceIndex].Model * _51); + out.out_var_TEXCOORD5 = (_95 * (_91 * transpose(Uniforms.NoTranslateView))).xyz; + out.gl_Position = Uniforms.ViewProjection * (scene._m0[gl_InstanceIndex].Model * _53); return out; } diff --git a/projects/content/_shaders/msl/ssao.frag.msl b/projects/content/_shaders/msl/ssao.frag.msl index 31f85f1..89e78b8 100644 --- a/projects/content/_shaders/msl/ssao.frag.msl +++ b/projects/content/_shaders/msl/ssao.frag.msl @@ -55,7 +55,7 @@ struct type_Uniforms int numSamples; }; -constant spvUnsafeArray _311 = spvUnsafeArray({ float3(0.0), float3(0.00039307403494603931903839111328125, 0.00020744701032526791095733642578125, 0.00023402007354889065027236938476562), float3(-0.001318361726589500904083251953125, -0.001457856036722660064697265625, 0.001546739018522202968597412109375), float3(0.0003496186691336333751678466796875, 8.4181214333511888980865478515625e-05, 5.8608897234080359339714050292969e-05), float3(-0.0005043491837568581104278564453125, -0.00383304059505462646484375, 0.002929248847067356109619140625), float3(-0.00241771643050014972686767578125, 0.0057135238312184810638427734375, 0.00173364556394517421722412109375), float3(-0.0007101023220457136631011962890625, 0.000413290224969387054443359375, 0.00037520084879361093044281005859375), float3(1.5587833331665024161338806152344e-05, -0.00011572847870411351323127746582031, 7.3567920480854809284210205078125e-05), float3(0.00334032182581722736358642578125, -0.0051653436385095119476318359375, 0.0050431825220584869384765625), float3(-0.0063966461457312107086181640625, 0.01290071941912174224853515625, 0.00147703452967107295989990234375), float3(0.007907788269221782684326171875, -0.0049759554676711559295654296875, 0.001991991885006427764892578125), float3(-0.0003332807100377976894378662109375, -0.00100087863393127918243408203125, 0.001031001214869320392608642578125), float3(0.00011193146201549097895622253417969, 0.00036116360570304095745086669921875, 0.0010905899107456207275390625), float3(-0.00385366589762270450592041015625, -0.004629385657608509063720703125, 0.00270807673223316669464111328125), float3(-0.0055218120105564594268798828125, 0.0163907893002033233642578125, 0.0033264369703829288482666015625), float3(-0.00297828204929828643798828125, -0.00340225151740014553070068359375, 0.0009606514940969645977020263671875), float3(0.0005643319454975426197052001953125, -0.00123721174895763397216796875, 0.001142332912422716617584228515625), float3(0.0042646829970180988311767578125, 0.001690786913968622684478759765625, 0.00338359293527901172637939453125), float3(0.028113491833209991455078125, -0.01881640218198299407958984375, 0.0140878893435001373291015625), float3(-0.03022454865276813507080078125, -0.000894616474397480487823486328125, 0.008499112911522388458251953125), float3(-0.01961914263665676116943359375, -0.0350324176251888275146484375, 0.014081305824220180511474609375), float3(0.015496986918151378631591796875, -0.010903127491474151611328125, 0.00180752319283783435821533203125), float3(0.0196535401046276092529296875, 0.01710924692451953887939453125, 0.0142847932875156402587890625), float3(-0.02892612479627132415771484375, 0.00322483875788748264312744140625, 0.06573773920536041259765625), float3(-0.0016983882524073123931884765625, 0.0004074592725373804569244384765625, 0.00372933782637119293212890625), float3(-0.0335367508232593536376953125, 0.0591063164174556732177734375, 0.001477129175327718257904052734375), float3(0.01729742996394634246826171875, 0.02095410041511058807373046875, 0.061427496373653411865234375), float3(-0.0362440533936023712158203125, -0.01097334362566471099853515625, 0.052580632269382476806640625), float3(-0.010873113758862018585205078125, 0.071666888892650604248046875, 0.07090236246585845947265625), float3(0.0404303781688213348388671875, -0.0758908092975616455078125, 0.066407024860382080078125), float3(0.006424785591661930084228515625, -0.00888848863542079925537109375, 0.00571323931217193603515625), float3(-0.0424978695809841156005859375, 0.122786454856395721435546875, 0.03013108484447002410888671875), float3(-0.012614764273166656494140625, -0.01173587143421173095703125, 0.0161450766026973724365234375), float3(0.02246730588376522064208984375, -0.023659668862819671630859375, 0.01735904999077320098876953125), float3(0.0280994363129138946533203125, -0.0286351330578327178955078125, 0.0076164784841239452362060546875), float3(0.0701790750026702880859375, -0.1532168686389923095703125, 0.0887149870395660400390625), float3(0.0073889424093067646026611328125, 0.152280390262603759765625, 0.00664083100855350494384765625), float3(0.07831905782222747802734375, -0.072104983031749725341796875, 0.094614334404468536376953125), float3(0.03289596736431121826171875, -0.0408993400633335113525390625, 0.040609411895275115966796875), float3(-0.141404449939727783203125, 0.17826557159423828125, 0.067046172916889190673828125), float3(0.108955644071102142333984375, 0.1114947497844696044921875, 0.21018303930759429931640625), float3(0.02759261615574359893798828125, 0.0139005817472934722900390625, 0.036677159368991851806640625), float3(0.05564410984516143798828125, -0.099730752408504486083984375, 0.113144241273403167724609375), float3(-0.0315654389560222625732421875, -0.22426509857177734375, 0.23739193379878997802734375), float3(-0.0474216155707836151123046875, 0.00566783733665943145751953125, 0.1736856400966644287109375), float3(0.088452465832233428955078125, 0.096331931650638580322265625, 0.083578832447528839111328125), float3(-0.0036428333260118961334228515625, 0.010955554433166980743408203125, 0.00330849713645875453948974609375), float3(-0.1911892592906951904296875, -0.18971312046051025390625, 0.1564487516880035400390625), float3(0.034361146390438079833984375, 0.0655452907085418701171875, 0.0308254323899745941162109375), float3(0.371889293193817138671875, 0.0229042805731296539306640625, 0.2982411682605743408203125), float3(-0.014679887332022190093994140625, 0.01349230110645294189453125, 0.00740495882928371429443359375), float3(-0.00653826631605625152587890625, -0.0058869807980954647064208984375, 0.005725885741412639617919921875), float3(-0.2333120405673980712890625, -0.35499393939971923828125, 0.03432808816432952880859375), float3(0.0411357469856739044189453125, -0.023320116102695465087890625, 0.01891444809734821319580078125), float3(-0.0945928990840911865234375, 0.02529100514948368072509765625, 0.092956520617008209228515625), float3(-0.0317381806671619415283203125, 0.226026356220245361328125, 0.2367977797985076904296875), float3(-0.3801217377185821533203125, 0.2481244504451751708984375, 0.47917068004608154296875), float3(0.13565014302730560302734375, 0.13791494071483612060546875, 0.4077457487583160400390625), float3(0.523879945278167724609375, -0.388758122920989990234375, 0.24387760460376739501953125), float3(-0.0520826168358325958251953125, -0.118409633636474609375, 0.095709107816219329833984375), float3(0.122609488666057586669921875, -0.4220634996891021728515625, 0.178109467029571533203125), float3(-0.2801954448223114013671875, -0.520291268825531005859375, 0.26809024810791015625), float3(-0.3271856009960174560546875, 0.23393590748310089111328125, 0.098123751580715179443359375), float3(0.3826406896114349365234375, 0.08367092907428741455078125, 0.257561206817626953125) }); +constant spvUnsafeArray _313 = spvUnsafeArray({ float3(0.0), float3(0.00039307403494603931903839111328125, 0.00020744701032526791095733642578125, 0.00023402007354889065027236938476562), float3(-0.001318361726589500904083251953125, -0.001457856036722660064697265625, 0.001546739018522202968597412109375), float3(0.0003496186691336333751678466796875, 8.4181214333511888980865478515625e-05, 5.8608897234080359339714050292969e-05), float3(-0.0005043491837568581104278564453125, -0.00383304059505462646484375, 0.002929248847067356109619140625), float3(-0.00241771643050014972686767578125, 0.0057135238312184810638427734375, 0.00173364556394517421722412109375), float3(-0.0007101023220457136631011962890625, 0.000413290224969387054443359375, 0.00037520084879361093044281005859375), float3(1.5587833331665024161338806152344e-05, -0.00011572847870411351323127746582031, 7.3567920480854809284210205078125e-05), float3(0.00334032182581722736358642578125, -0.0051653436385095119476318359375, 0.0050431825220584869384765625), float3(-0.0063966461457312107086181640625, 0.01290071941912174224853515625, 0.00147703452967107295989990234375), float3(0.007907788269221782684326171875, -0.0049759554676711559295654296875, 0.001991991885006427764892578125), float3(-0.0003332807100377976894378662109375, -0.00100087863393127918243408203125, 0.001031001214869320392608642578125), float3(0.00011193146201549097895622253417969, 0.00036116360570304095745086669921875, 0.0010905899107456207275390625), float3(-0.00385366589762270450592041015625, -0.004629385657608509063720703125, 0.00270807673223316669464111328125), float3(-0.0055218120105564594268798828125, 0.0163907893002033233642578125, 0.0033264369703829288482666015625), float3(-0.00297828204929828643798828125, -0.00340225151740014553070068359375, 0.0009606514940969645977020263671875), float3(0.0005643319454975426197052001953125, -0.00123721174895763397216796875, 0.001142332912422716617584228515625), float3(0.0042646829970180988311767578125, 0.001690786913968622684478759765625, 0.00338359293527901172637939453125), float3(0.028113491833209991455078125, -0.01881640218198299407958984375, 0.0140878893435001373291015625), float3(-0.03022454865276813507080078125, -0.000894616474397480487823486328125, 0.008499112911522388458251953125), float3(-0.01961914263665676116943359375, -0.0350324176251888275146484375, 0.014081305824220180511474609375), float3(0.015496986918151378631591796875, -0.010903127491474151611328125, 0.00180752319283783435821533203125), float3(0.0196535401046276092529296875, 0.01710924692451953887939453125, 0.0142847932875156402587890625), float3(-0.02892612479627132415771484375, 0.00322483875788748264312744140625, 0.06573773920536041259765625), float3(-0.0016983882524073123931884765625, 0.0004074592725373804569244384765625, 0.00372933782637119293212890625), float3(-0.0335367508232593536376953125, 0.0591063164174556732177734375, 0.001477129175327718257904052734375), float3(0.01729742996394634246826171875, 0.02095410041511058807373046875, 0.061427496373653411865234375), float3(-0.0362440533936023712158203125, -0.01097334362566471099853515625, 0.052580632269382476806640625), float3(-0.010873113758862018585205078125, 0.071666888892650604248046875, 0.07090236246585845947265625), float3(0.0404303781688213348388671875, -0.0758908092975616455078125, 0.066407024860382080078125), float3(0.006424785591661930084228515625, -0.00888848863542079925537109375, 0.00571323931217193603515625), float3(-0.0424978695809841156005859375, 0.122786454856395721435546875, 0.03013108484447002410888671875), float3(-0.012614764273166656494140625, -0.01173587143421173095703125, 0.0161450766026973724365234375), float3(0.02246730588376522064208984375, -0.023659668862819671630859375, 0.01735904999077320098876953125), float3(0.0280994363129138946533203125, -0.0286351330578327178955078125, 0.0076164784841239452362060546875), float3(0.0701790750026702880859375, -0.1532168686389923095703125, 0.0887149870395660400390625), float3(0.0073889424093067646026611328125, 0.152280390262603759765625, 0.00664083100855350494384765625), float3(0.07831905782222747802734375, -0.072104983031749725341796875, 0.094614334404468536376953125), float3(0.03289596736431121826171875, -0.0408993400633335113525390625, 0.040609411895275115966796875), float3(-0.141404449939727783203125, 0.17826557159423828125, 0.067046172916889190673828125), float3(0.108955644071102142333984375, 0.1114947497844696044921875, 0.21018303930759429931640625), float3(0.02759261615574359893798828125, 0.0139005817472934722900390625, 0.036677159368991851806640625), float3(0.05564410984516143798828125, -0.099730752408504486083984375, 0.113144241273403167724609375), float3(-0.0315654389560222625732421875, -0.22426509857177734375, 0.23739193379878997802734375), float3(-0.0474216155707836151123046875, 0.00566783733665943145751953125, 0.1736856400966644287109375), float3(0.088452465832233428955078125, 0.096331931650638580322265625, 0.083578832447528839111328125), float3(-0.0036428333260118961334228515625, 0.010955554433166980743408203125, 0.00330849713645875453948974609375), float3(-0.1911892592906951904296875, -0.18971312046051025390625, 0.1564487516880035400390625), float3(0.034361146390438079833984375, 0.0655452907085418701171875, 0.0308254323899745941162109375), float3(0.371889293193817138671875, 0.0229042805731296539306640625, 0.2982411682605743408203125), float3(-0.014679887332022190093994140625, 0.01349230110645294189453125, 0.00740495882928371429443359375), float3(-0.00653826631605625152587890625, -0.0058869807980954647064208984375, 0.005725885741412639617919921875), float3(-0.2333120405673980712890625, -0.35499393939971923828125, 0.03432808816432952880859375), float3(0.0411357469856739044189453125, -0.023320116102695465087890625, 0.01891444809734821319580078125), float3(-0.0945928990840911865234375, 0.02529100514948368072509765625, 0.092956520617008209228515625), float3(-0.0317381806671619415283203125, 0.226026356220245361328125, 0.2367977797985076904296875), float3(-0.3801217377185821533203125, 0.2481244504451751708984375, 0.47917068004608154296875), float3(0.13565014302730560302734375, 0.13791494071483612060546875, 0.4077457487583160400390625), float3(0.523879945278167724609375, -0.388758122920989990234375, 0.24387760460376739501953125), float3(-0.0520826168358325958251953125, -0.118409633636474609375, 0.095709107816219329833984375), float3(0.122609488666057586669921875, -0.4220634996891021728515625, 0.178109467029571533203125), float3(-0.2801954448223114013671875, -0.520291268825531005859375, 0.26809024810791015625), float3(-0.3271856009960174560546875, 0.23393590748310089111328125, 0.098123751580715179443359375), float3(0.3826406896114349365234375, 0.08367092907428741455078125, 0.257561206817626953125) }); struct main0_out { @@ -70,46 +70,55 @@ struct main0_in fragment main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniforms [[buffer(0)]], texture2d PositionTexture [[texture(0)]], texture2d NormalTexture [[texture(1)]], texture2d NoiseTexture [[texture(2)]], sampler Sampler0 [[sampler(0)]], sampler Sampler1 [[sampler(1)]], sampler Sampler2 [[sampler(2)]]) { main0_out out = {}; - float2 _314 = in.in_var_TEXCOORD0; - float4 _410; + float2 _317 = in.in_var_TEXCOORD0; + float4 _424; do { - _314.y = (_314.y * (-1.0)) + 1.0; - float4 _326 = PositionTexture.sample(Sampler0, _314); - float4 _327 = Uniforms.View * _326; - float3 _328 = _327.xyz; - float _329 = _327.z; - if (_329 < 0.00999999977648258209228515625) + _317.y = (_317.y * (-1.0)) + 1.0; + float4 _329 = PositionTexture.sample(Sampler0, _317); + float4 _330 = Uniforms.View * _329; + float3 _331 = _330.xyz; + float _332 = _330.z; + if (_332 < 0.00999999977648258209228515625) { - _410 = float4(1.0); + _424 = float4(1.0); break; } - float4 _336 = NormalTexture.sample(Sampler1, _314); - float3 _339 = fast::normalize((Uniforms.View * _336).xyz); - float4 _344 = NoiseTexture.sample(Sampler2, (_314 * float2(320.0, 180.0))); - float3 _346 = fast::normalize(_344.xyz); - float3 _350 = fast::normalize(_346 - (_339 * dot(_346, _339))); - float3x3 _352 = float3x3(_350, cross(_339, _350), _339); - float _354; - _354 = 0.0; - for (int _357 = 0; _357 < Uniforms.numSamples; ) + float4 _339 = NormalTexture.sample(Sampler1, _317); + float3 _340 = _339.xyz; + float4 _345 = NoiseTexture.sample(Sampler2, (_317 * float2(320.0, 180.0))); + float3 _347 = fast::normalize(_345.xyz); + float3 _351 = fast::normalize(_347 - (_340 * dot(_347, _340))); + float3x3 _354 = transpose(float3x3(_351, cross(_340, _351), _340)); + float _356; + _356 = 0.0; + float _357; + for (int _359 = 0; _359 < Uniforms.numSamples; _356 = _357, _359++) { - float3 _369 = _328 + ((_311[_357] * _352) * Uniforms.radius); - float4 _376 = Uniforms.Projection * float4(_369, 1.0); - float3 _383 = ((_376.xyz / float3(_376.w)).xyz * 0.5) + float3(0.5); - float4 _384 = float4(_383.x, _383.y, _383.z, _376.w); - _384.y = _383.y * (-1.0); - float4 _391 = Uniforms.View * PositionTexture.sample(Sampler0, _384.xy); - float _392 = _391.z; - _354 += (float(_392 >= (_369.z + Uniforms.bias0)) * smoothstep(0.0, 1.0, Uniforms.radius / abs(_329 - _392))); - _357++; - continue; + float3 _373 = _331 + (((_313[_359] + float3(0.0, 0.0, 0.00999999977648258209228515625)) * _354) * Uniforms.radius); + float _376 = _373.z; + float4 _380 = Uniforms.Projection * float4(_373.xy, _376, 1.0); + float3 _387 = ((_380.xyz / float3(_380.w)).xyz * 0.5) + float3(0.5); + float4 _388 = float4(_387.x, _387.y, _387.z, _380.w); + _388.y = (_387.y * (-1.0)) + 1.0; + float4 _395 = PositionTexture.sample(Sampler0, _388.xy); + float4 _396 = Uniforms.View * _395; + float _397 = _396.z; + float _408 = _356 + (float(_397 <= (_376 - Uniforms.bias0)) * smoothstep(0.0, 1.0, Uniforms.radius / abs(_332 - _397))); + if (_376 > 30.0) + { + _357 = _408 * precise::max(0.0, 1.0 - ((_376 - 30.0) * 0.0033333334140479564666748046875)); + } + else + { + _357 = _408; + } } - float _405 = 1.0 - (_354 / float(Uniforms.numSamples)); - _410 = float4(_405) + float4(_405 * 9.9999997473787516355514526367188e-06); + float _419 = 1.0 - (_356 / float(Uniforms.numSamples)); + _424 = float4(_419) + float4(_419 * 9.9999997473787516355514526367188e-06); break; } while(false); - out.out_var_SV_Target0 = _410; + out.out_var_SV_Target0 = _424; return out; } diff --git a/projects/content/_shaders/spv/lit_mesh.frag.spv b/projects/content/_shaders/spv/lit_mesh.frag.spv index b2e4ad4..1b321e7 100644 Binary files a/projects/content/_shaders/spv/lit_mesh.frag.spv and b/projects/content/_shaders/spv/lit_mesh.frag.spv differ diff --git a/projects/content/_shaders/spv/meshes.vert.spv b/projects/content/_shaders/spv/meshes.vert.spv index b0b1c96..a87f72c 100644 Binary files a/projects/content/_shaders/spv/meshes.vert.spv and b/projects/content/_shaders/spv/meshes.vert.spv differ diff --git a/projects/content/_shaders/spv/ssao.frag.spv b/projects/content/_shaders/spv/ssao.frag.spv index 0bc7ed7..8227293 100644 Binary files a/projects/content/_shaders/spv/ssao.frag.spv and b/projects/content/_shaders/spv/ssao.frag.spv differ