ssao fixes

This commit is contained in:
peterino2 2025-05-24 20:24:17 -07:00
parent fefbc7436b
commit 6cd0dcb89e
15 changed files with 935 additions and 687 deletions

View File

@ -5,6 +5,7 @@ allocator: std.mem.Allocator,
arena: std.heap.ArenaAllocator, arena: std.heap.ArenaAllocator,
windowsMenu: std.ArrayListUnmanaged(*MenuEntry) = .{}, windowsMenu: std.ArrayListUnmanaged(*MenuEntry) = .{},
entriesByName: std.AutoHashMapUnmanaged(u32, *MenuEntry) = .{}, entriesByName: std.AutoHashMapUnmanaged(u32, *MenuEntry) = .{},
menuOpen: bool = true,
pub fn create(allocator: std.mem.Allocator) !*@This() { pub fn create(allocator: std.mem.Allocator) !*@This() {
const self = try Slack.create(allocator); const self = try Slack.create(allocator);
@ -34,9 +35,7 @@ pub fn addMenuObject(self: *@This(), ptr: anytype, comptime name: []const u8) !v
pub fn windowOpen(entry: *MenuEntry, dt: f64) void { pub fn windowOpen(entry: *MenuEntry, dt: f64) void {
_ = dt; _ = dt;
ig.showDemoWindow(&entry.open);
if (ig.begin("sample window", &entry.open, .{})) {}
ig.end();
} }
pub fn addWindowsMenu(self: *@This(), entry: MenuEntry) !void { pub fn addWindowsMenu(self: *@This(), entry: MenuEntry) !void {
@ -54,7 +53,9 @@ pub fn addWindowsMenu(self: *@This(), entry: MenuEntry) !void {
} }
pub fn tick(self: *@This(), dt: f64) void { pub fn tick(self: *@This(), dt: f64) void {
ig.showDemoWindow(null); if (!self.menuOpen) {
return;
}
if (ig.beginMainMenuBar()) { if (ig.beginMainMenuBar()) {
if (ig.beginMenu("Windows..", true)) { if (ig.beginMenu("Windows..", true)) {

View File

@ -86,7 +86,9 @@ Output main(Input input)
output.Normal = normalize(mul(noTranslate, float4(input.Normal, 1.0))).xyz; output.Normal = normalize(mul(noTranslate, float4(input.Normal, 1.0))).xyz;
float4x4 noTranslateScreen = mul(NoTranslateView, noTranslate); float4x4 noTranslateScreen = mul(NoTranslateView, noTranslate);
output.ScreenNormal = mul(noTranslateScreen, float4(input.Normal, 1.0)).xyz; output.ScreenNormal = mul(NoTranslateView, float4(input.Normal, 1.0)).xyz;
// output.ScreenNormal = input.Normal;
// output.ScreenNormal = float4(input.Normal, 1.0).xyz;
output.DirectionalShadowFragPos = mul(ShadowMapProjection, WorldPos); output.DirectionalShadowFragPos = mul(ShadowMapProjection, WorldPos);
output.Instance = input.Instance; output.Instance = input.Instance;

View File

@ -130,10 +130,15 @@ float4 main(float2 UV : TEXCOORD0) : SV_Target0
// c = float3(uv.x, uv.y, 0.0); // c = float3(uv.x, uv.y, 0.0);
// c = SsaoTexture.Sample(Sampler2, uv).x; // c = SsaoTexture.Sample(Sampler2, uv).x;
// float4 ssao = SsaoTexture.Sample(Sampler2, uv);
#if 0
float4 ssao = SsaoTexture.Sample(Sampler2, uv);
c = ssao.xyz;
#else
float3 ssao = blurSSAO(uv); float3 ssao = blurSSAO(uv);
c = c * ssao; c = c * ssao;
#endif
//float4 x = SsaoTexture.Sample(Sampler2, uv); //float4 x = SsaoTexture.Sample(Sampler2, uv);
//c = x; //c = x;

View File

@ -1,29 +1,29 @@
static const float3 SamplingKernel[64] = { float3( -0, 0, 0 ), static const float3 SamplingKernel[64] = { float3( -0, 0, 0 ),
float3( 0.00039307403, 0.00020744701, 0.00023402007 ), float3( 0.00039307403, 0.00020744701, 0.023402007 ),
float3( -0.0013183617, -0.001457856, 0.001546739 ), float3( -0.0013183617, -0.001457856, 0.01546739 ),
float3( 0.00034961867, 0.000084181214, 0.000058608897 ), float3( 0.00034961867, 0.000084181214, 0.058608897 ),
float3( -0.0005043492, -0.0038330406, 0.0029292488 ), float3( -0.0005043492, -0.0038330406, 0.029292488 ),
float3( -0.0024177164, 0.005713524, 0.0017336456 ), float3( -0.0024177164, 0.005713524, 0.017336456 ),
float3( -0.0007101023, 0.00041329022, 0.00037520085 ), float3( -0.0007101023, 0.00041329022, 0.037520085 ),
float3( 0.000015587833, -0.00011572848, 0.00007356792 ), float3( 0.000015587833, -0.00011572848, 0.07356792 ),
float3( 0.0033403218, -0.0051653436, 0.0050431825 ), float3( 0.0033403218, -0.0051653436, 0.050431825 ),
float3( -0.006396646, 0.012900719, 0.0014770345 ), float3( -0.006396646, 0.012900719, 0.0014770345 ),
float3( 0.007907788, -0.0049759555, 0.001991992 ), float3( 0.007907788, -0.0049759555, 0.001991992 ),
float3( -0.0003332807, -0.0010008786, 0.0010310012 ), float3( -0.0003332807, -0.0010008786, 0.0010310012 ),
float3( 0.00011193146, 0.0003611636, 0.0010905899 ), float3( 0.00011193146, 0.0003611636, 0.010905899 ),
float3( -0.003853666, -0.0046293857, 0.0027080767 ), float3( -0.003853666, -0.0046293857, 0.027080767 ),
float3( -0.005521812, 0.01639079, 0.003326437 ), float3( -0.005521812, 0.01639079, 0.003326437 ),
float3( -0.002978282, -0.0034022515, 0.0009606515 ), float3( -0.002978282, -0.0034022515, 0.009606515 ),
float3( 0.00056433195, -0.0012372117, 0.0011423329 ), float3( 0.00056433195, -0.0012372117, 0.011423329 ),
float3( 0.004264683, 0.0016907869, 0.003383593 ), float3( 0.004264683, 0.0016907869, 0.003383593 ),
float3( 0.028113492, -0.018816402, 0.014087889 ), float3( 0.028113492, -0.018816402, 0.014087889 ),
float3( -0.030224549, -0.0008946165, 0.008499113 ), float3( -0.030224549, -0.0008946165, 0.08499113 ),
float3( -0.019619143, -0.035032418, 0.014081306 ), float3( -0.019619143, -0.035032418, 0.014081306 ),
float3( 0.015496987, -0.0109031275, 0.0018075232 ), float3( 0.015496987, -0.0109031275, 0.0018075232 ),
float3( 0.01965354, 0.017109247, 0.014284793 ), float3( 0.01965354, 0.017109247, 0.014284793 ),
float3( -0.028926125, 0.0032248388, 0.06573774 ), float3( -0.028926125, 0.0032248388, 0.06573774 ),
float3( -0.0016983883, 0.00040745927, 0.0037293378 ), float3( -0.0016983883, 0.00040745927, 0.0037293378 ),
float3( -0.03353675, 0.059106316, 0.0014771292 ), float3( -0.03353675, 0.059106316, 0.014771292 ),
float3( 0.01729743, 0.0209541, 0.061427496 ), float3( 0.01729743, 0.0209541, 0.061427496 ),
float3( -0.036244053, -0.010973344, 0.052580632 ), float3( -0.036244053, -0.010973344, 0.052580632 ),
float3( -0.010873114, 0.07166689, 0.07090236 ), float3( -0.010873114, 0.07166689, 0.07090236 ),

View File

@ -38,6 +38,7 @@ float4 main(float2 UV: TEXCOORD0) : SV_Target0
float3 normal = NormalTexture.Sample(Sampler1, uv).xyz; float3 normal = NormalTexture.Sample(Sampler1, uv).xyz;
float3 randomVec = normalize(NoiseTexture.Sample(Sampler2, uv * scale).xyz); float3 randomVec = normalize(NoiseTexture.Sample(Sampler2, uv * scale).xyz);
// randomVec = normalize(float3(1.0, 1.0, 0.0) + randomVec * 0.00001); // randomVec = normalize(float3(1.0, 1.0, 0.0) + randomVec * 0.00001);
// randomVec = mul(View, randomVec);
float3 x = normal; float3 x = normal;
@ -49,10 +50,15 @@ float4 main(float2 UV: TEXCOORD0) : SV_Target0
float occlusion = 0.0; float occlusion = 0.0;
x = float3(0.0,0.0,0.0); x = (normal + 1.0) * 0.5; // -1 -> 0 . 1.0 -> 1.0 0 -> 0.5
x = tangent;
//for(int i = 0; i < numSamples; i += 1)
for(int i = 0; i < numSamples; i += 1) for(int i = 0; i < numSamples; i += 1)
{ {
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 float d = length(SamplingKernel[i]);
//float3 samplePos = mul(TBN, d * normalize(SamplingKernel[i] * float3(1.0, 1.0, 1.0))); //float3(0.0, 0.0, 1.0)); // from tangent to view-space
float3 samplePos = mul(TBN, SamplingKernel[i] + float3(0.0, 0.0, 0.05)); //float3(0.0, 0.0, 1.0)); // from tangent to view-space
samplePos = position + samplePos * radius; samplePos = position + samplePos * radius;
// project sample position (to sample texture) (to get position on screen/texture) // project sample position (to sample texture) (to get position on screen/texture)
@ -69,8 +75,8 @@ float4 main(float2 UV: TEXCOORD0) : SV_Target0
// x += (float3(offset.xy - uv, 0.0) * 0.5 + 0.5) / numSamples; // x += (float3(offset.xy - uv, 0.0) * 0.5 + 0.5) / numSamples;
// get sample depth // get sample depth
float sampleDepth = mul(View, PositionTexture.Sample(Sampler0, offset.xy)).z; // texture(gPosition, offset.xy).z; // get depth value of kernel sample 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(sampleDepth, sampleDepth, sampleDepth) / numSamples;
x -= float3(samplePos.z, samplePos.z, samplePos.z) / numSamples; // x -= float3(samplePos.z, samplePos.z, samplePos.z) / numSamples;
// c = float4(sampleDepth, sampleDepth, sampleDepth, 1.0) / 100; // c = float4(sampleDepth, sampleDepth, sampleDepth, 1.0) / 100;
// c = float4(offset) * 2.0 - 0.6 ; // c = float4(offset) * 2.0 - 0.6 ;
@ -83,7 +89,7 @@ float4 main(float2 UV: TEXCOORD0) : SV_Target0
occlusion *= max(0.0, 1.0 - ((samplePos.z - 30) / 300)); occlusion *= max(0.0, 1.0 - ((samplePos.z - 30) / 300));
} }
} }
x.z = 0;
occlusion = 1.0 - (occlusion / numSamples); occlusion = 1.0 - (occlusion / numSamples);
// occlusion = 1.0 - occlusion; // occlusion = 1.0 - occlusion;
// c += PositionTexture.Sample(Sampler0, uv).x * 0.00001; // c += PositionTexture.Sample(Sampler0, uv).x * 0.00001;
@ -93,7 +99,8 @@ float4 main(float2 UV: TEXCOORD0) : SV_Target0
// c = float4(x, x, x, 1.0); // c = float4(x, x, x, 1.0);
c = occlusion; c = occlusion;
//c = float4(x, 1.0); //float j = x.z;
// c = float4(x, 1.0);
return c + occlusion * 0.00001; return c + occlusion * 0.00001;
} }

View File

@ -83,7 +83,7 @@ pub const Renderer = struct {
ssaoSystem: *SsaoSystem = undefined, ssaoSystem: *SsaoSystem = undefined,
positionTargetFormat: gpu.GPUTextureFormat = .textureformatR16g16b16a16Float, positionTargetFormat: gpu.GPUTextureFormat = .textureformatR16g16b16a16Float,
normalTargetFormat: gpu.GPUTextureFormat = .textureformatB8g8r8a8Unorm, normalTargetFormat: gpu.GPUTextureFormat = .textureformatR16g16b16a16Float,
pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This(), "rend.Renderer"); pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This(), "rend.Renderer");
@ -479,6 +479,7 @@ pub const Renderer = struct {
}; };
pci.rasterizer_state.fill_mode = .fillmodeFill; pci.rasterizer_state.fill_mode = .fillmodeFill;
pci.rasterizer_state.cull_mode = .cullmodeBack;
self.meshPipe = self.device.createGPUGraphicsPipeline(&pci); self.meshPipe = self.device.createGPUGraphicsPipeline(&pci);
} }

View File

@ -189,10 +189,14 @@ pub const MeshBuilder = struct {
.z = @floatCast(n.data[2]), .z = @floatCast(n.data[2]),
}; };
normal = normal.normalize();
// normal = .{ .y = 1.0 };
normal = settings.rotation.rotateVector(normal); normal = settings.rotation.rotateVector(normal);
if (normal.dot(.{ .y = 1.0 }) < 0.5) { if (normal.dot(.{ .y = 1.0 }) < 0.5) {
// return; // return;
} }
core.engine_log("{any}", .{normal});
// append all vertices to the vertex list // append all vertices to the vertex list
for (face.vertices) |vert| { for (face.vertices) |vert| {

View File

@ -48,14 +48,13 @@ vertex main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniform
main0_out out = {}; main0_out out = {};
float4 _53 = float4(in.in_var_TEXCOORD0, 1.0); float4 _53 = float4(in.in_var_TEXCOORD0, 1.0);
float4 _56 = scene._m0[gl_InstanceIndex].Model * _53; 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); float4 _95 = float4(in.in_var_TEXCOORD1, 1.0);
out.out_var_TEXCOORD0 = in.in_var_TEXCOORD3; out.out_var_TEXCOORD0 = in.in_var_TEXCOORD3;
out.out_var_TEXCOORD1 = _56.xyz; out.out_var_TEXCOORD1 = _56.xyz;
out.out_var_TEXCOORD2 = fast::normalize(_95 * _91).xyz; out.out_var_TEXCOORD2 = fast::normalize(_95 * 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 * _56; out.out_var_TEXCOORD3 = Uniforms.ShadowMapProjection * _56;
out.out_var_TEXCOORD4 = gl_InstanceIndex; out.out_var_TEXCOORD4 = gl_InstanceIndex;
out.out_var_TEXCOORD5 = (_95 * (_91 * transpose(Uniforms.NoTranslateView))).xyz; out.out_var_TEXCOORD5 = (Uniforms.NoTranslateView * _95).xyz;
out.gl_Position = Uniforms.ViewProjection * (scene._m0[gl_InstanceIndex].Model * _53); out.gl_Position = Uniforms.ViewProjection * (scene._m0[gl_InstanceIndex].Model * _53);
return out; return out;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -109,7 +109,6 @@ pub const ExternGameObject = struct {
ig.end(); ig.end();
//_ = self; //_ = self;
_ = rctx;
// imgui.utils.structHexView(self); // imgui.utils.structHexView(self);
// imgui.utils.structHexView(rctx.activeCamera.?); // imgui.utils.structHexView(rctx.activeCamera.?);
// if (ig.begin("external game object", null, .{})) { // if (ig.begin("external game object", null, .{})) {
@ -124,13 +123,13 @@ pub const ExternGameObject = struct {
// } // }
// ig.end(); // ig.end();
// if (ig.begin("list of textures", null, .{})) { if (ig.begin("list of textures", null, .{})) {
// var iterator = rctx.textureList.map.iterator(); var iterator = rctx.textureList.map.iterator();
// while (iterator.next()) |i| { while (iterator.next()) |i| {
// ig.textf("{s}", .{i.value_ptr.*.name.utf8()}); ig.textf("{s}", .{i.value_ptr.*.name.utf8()});
// } }
// } }
// ig.end(); ig.end();
// if (ig.begin("list of meshes", null, .{})) { // if (ig.begin("list of meshes", null, .{})) {
// ig.textf("number of meshes: {d}", .{rctx.meshPool.installedMeshes.count()}); // ig.textf("number of meshes: {d}", .{rctx.meshPool.installedMeshes.count()});