diff --git a/MAGE/Rendering/src/renderer/pass/voxelization_pass.cpp b/MAGE/Rendering/src/renderer/pass/voxelization_pass.cpp index 5d602d9f2..aa11bfc65 100644 --- a/MAGE/Rendering/src/renderer/pass/voxelization_pass.cpp +++ b/MAGE/Rendering/src/renderer/pass/voxelization_pass.cpp @@ -55,7 +55,7 @@ namespace mage::rendering { m_gs->BindShader(m_device_context); // RS: Bind the rasterization state. m_state_manager.get().Bind(m_device_context, - RasterizerStateID::CounterClockwiseCulling); + RasterizerStateID::NoCulling); // OM: Bind the depth-stencil state. m_state_manager.get().Bind(m_device_context, DepthStencilStateID::DepthNone); diff --git a/MAGE/Shaders/shaders/global.hlsli b/MAGE/Shaders/shaders/global.hlsli index 6a10e7656..a794f72b5 100644 --- a/MAGE/Shaders/shaders/global.hlsli +++ b/MAGE/Shaders/shaders/global.hlsli @@ -174,6 +174,9 @@ int3 WorldToVoxelIndex(float3 p_world) { */ float3 VoxelIndexToWorld(uint3 voxel_index) { // Valid range: [-R/2,R/2]x[R/2,-R/2]x[-R/2,R/2] + + voxel_index.y += 1u; + const float3 voxel = voxel_index - 0.5f * g_voxel_grid_resolution; return voxel * g_voxel_size * float3(1.0f, -1.0f, 1.0f) + g_voxel_grid_center; } diff --git a/MAGE/Shaders/shaders/voxelization/voxel_grid_GS.hlsl b/MAGE/Shaders/shaders/voxelization/voxel_grid_GS.hlsl index aa857b0aa..ae808518d 100644 --- a/MAGE/Shaders/shaders/voxelization/voxel_grid_GS.hlsl +++ b/MAGE/Shaders/shaders/voxelization/voxel_grid_GS.hlsl @@ -15,7 +15,7 @@ void GS(point GSInputPositionColor input[1], const float4 color = input[0].color; [branch] - if (0.0 != color.a) { + if (0.0f != color.a) { for (uint i = 0u; i < 14u; ++i) { const float3 offset = OffsettedUnitCube(i) * g_voxel_size; const float3 p_world = input[0].p_world + offset; diff --git a/MAGE/Shaders/shaders/voxelization/voxelization_GS.hlsl b/MAGE/Shaders/shaders/voxelization/voxelization_GS.hlsl index 69a649bb6..cb3e90a78 100644 --- a/MAGE/Shaders/shaders/voxelization/voxelization_GS.hlsl +++ b/MAGE/Shaders/shaders/voxelization/voxelization_GS.hlsl @@ -15,16 +15,22 @@ void GS(triangle GSInputPositionNormalTexture input[3], // Face normal based on the triangle edges: // normalize(cross(input[1].p_world - input[0].p_world, // input[2].p_world - input[0].p_world)) + // // Normalization is not needed (i.e. uniform scaling): - const float3 abs_n = abs(cross(input[1].p_world - input[0].p_world, - input[2].p_world - input[0].p_world)); - const uint axis_xy = (abs_n.x > abs_n.y) ? 0u : 1u; + // cross(input[1].p_world - input[0].p_world, + // input[2].p_world - input[0].p_world)) + // + // ~ abs(sum of shading normals) + const float3 abs_n = abs(input[0].n_world + + input[1].n_world + + input[2].n_world); + const uint axis_xy = (abs_n.x > abs_n.y) ? 0u : 1u; const uint axis = (abs_n.z > abs_n[axis_xy]) ? 2u : axis_xy; PSInputPositionNormalTexture output[3]; // Project the triangle in the dominant direction for rasterization (p), - // but not for lighting (p_view). + // but not for lighting (p_world). [unroll] for (uint i = 0u; i < 3u; ++i) {