Skip to content

Commit

Permalink
Culling with compute Version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
PodeCaradox committed Jun 3, 2022
1 parent bccd982 commit 8c5daba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions VFRZInstancing/Content/instance_effect.fx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ void InstancingCS(uint3 localID : SV_GroupThreadID, uint3 groupID : SV_GroupID,
index.y += column;
index.x += column;


if(index.x < 0 || index.y < 0 || index.y >= MapSizeY || index.x >= MapSizeX) return;
VisibleTiles[globalID.x + globalID.y * Columns] = AllTiles[index.y * MapSizeX + index.x];
uint visibleIndex = globalID.x + globalID.y * Columns;
if(index.x < 0 || index.y < 0 || index.y >= MapSizeY || index.x >= MapSizeX){
VisibleTiles[visibleIndex].InstanceTransform.z = -1;
return;
}
VisibleTiles[visibleIndex] = AllTiles[index.y * MapSizeX + index.x];
}


Expand Down Expand Up @@ -101,7 +104,7 @@ InstancingVSoutput InstancingVS(in StaticVSinput input)
float2 position = input.Position.xy * imageSize - float2(imageSize.x / 2, imageSize.y);;

//calculate position with camera
float4 pos = float4(position.xy + tile.InstanceTransform .xy,tile.InstanceTransform.z,1);
float4 pos = float4(position.xy + tile.InstanceTransform.xy, tile.InstanceTransform.z, 1);
pos = mul(pos, WorldViewProjection);


Expand Down
4 changes: 2 additions & 2 deletions VFRZInstancing/TileMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public TileMap(Game game, int sizeX, int sizeZ) : base(game)
{
_size = new Point(sizeX, sizeZ);
_raster.MultiSampleAntiAlias = false;
_raster.ScissorTestEnable = false;
_raster.ScissorTestEnable = true;
_raster.FillMode = FillMode.Solid;
_raster.CullMode = CullMode.CullCounterClockwiseFace;
_raster.DepthClipEnable = true;
Expand Down Expand Up @@ -327,7 +327,7 @@ private void ComputeCulling()
_effect.CurrentTechnique.Passes[0].ApplyCompute();
GraphicsDevice.DispatchCompute(tileCountX / _computeGroupSize, tileCountY / _computeGroupSize, 1);

_instancesVertexBuffer = (uint)(tileCountX + tileCountY * tileCountX);
_instancesVertexBuffer = (uint)(tileCountY * tileCountX);
}
#endregion
}
Expand Down

0 comments on commit 8c5daba

Please sign in to comment.