Skip to content

Commit fb728d1

Browse files
committed
Fixed grid rendering precision issues when grid size is very small
1 parent ea19373 commit fb728d1

File tree

1 file changed

+5
-9
lines changed
  • RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Resources/Shaders

1 file changed

+5
-9
lines changed

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Resources/Shaders/grid.shader

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//UNITY_SHADER_NO_UPGRADE
1+
//UNITY_SHADER_NO_UPGRADE
22
Shader "Hidden/CSG/internal/Grid"
33
{
44
Properties
@@ -74,21 +74,17 @@ Shader "Hidden/CSG/internal/Grid"
7474

7575
vertexOutput vert(vertexInput input)
7676
{
77-
half3 worldGridCenter = half4(_WorldSpaceCameraPos.x, 0, _WorldSpaceCameraPos.z, 1);
77+
half3 worldGridCenter = half3(_WorldSpaceCameraPos.x, 0, _WorldSpaceCameraPos.z);
7878
float4 objectCenter = mul(unity_ObjectToWorld, float4(0,0,0,1));
7979
objectCenter.xyz /= objectCenter.w;
8080
objectCenter.w = 0.0f;
8181

8282
vertexOutput output;
8383

84-
//half3 normal = normalize(mul((float3x3)unity_ObjectToWorld, half3(0, 1, 0)));
85-
//half4 gridPlane = half4(normal, -dot(normal, objectCenter));
86-
//float distance = (gridPlane.x * _WorldSpaceCameraPos.x) + (gridPlane.y * _WorldSpaceCameraPos.y) + (gridPlane.z * _WorldSpaceCameraPos.z) + (gridPlane.w);
87-
//float gridSize = (max(1, abs(distance)) * 100);
84+
float3 camDelta = _WorldSpaceCameraPos.xyz - (input.vertex.xyz / input.vertex.w);
85+
float camDistance = length(camDelta);
8886

89-
float gridSize = max(1, abs(_GridSize)) * 200;
90-
91-
float3 vposition = (input.vertex.xzy * gridSize);
87+
float3 vposition = (input.vertex.xzy * max(1,camDistance) * 5);
9288
float4 position = float4(vposition, 1);
9389

9490
output.objectPos = mul(unity_ObjectToWorld, float4(vposition, 1));

0 commit comments

Comments
 (0)