Skip to content

Commit

Permalink
Voxelization fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matt77hias committed Mar 12, 2018
1 parent 2da9f31 commit 6595de1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion MAGE/Rendering/src/renderer/pass/voxelization_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions MAGE/Shaders/shaders/global.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion MAGE/Shaders/shaders/voxelization/voxel_grid_GS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions MAGE/Shaders/shaders/voxelization/voxelization_GS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down

0 comments on commit 6595de1

Please sign in to comment.