|
1 | | -//UNITY_SHADER_NO_UPGRADE |
| 1 | +//UNITY_SHADER_NO_UPGRADE |
2 | 2 | Shader "Hidden/CSG/internal/Grid" |
3 | 3 | { |
4 | 4 | Properties |
@@ -74,21 +74,17 @@ Shader "Hidden/CSG/internal/Grid" |
74 | 74 |
|
75 | 75 | vertexOutput vert(vertexInput input) |
76 | 76 | { |
77 | | - half3 worldGridCenter = half4(_WorldSpaceCameraPos.x, 0, _WorldSpaceCameraPos.z, 1); |
| 77 | + half3 worldGridCenter = half3(_WorldSpaceCameraPos.x, 0, _WorldSpaceCameraPos.z); |
78 | 78 | float4 objectCenter = mul(unity_ObjectToWorld, float4(0,0,0,1)); |
79 | 79 | objectCenter.xyz /= objectCenter.w; |
80 | 80 | objectCenter.w = 0.0f; |
81 | 81 |
|
82 | 82 | vertexOutput output; |
83 | 83 |
|
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); |
88 | 86 |
|
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); |
92 | 88 | float4 position = float4(vposition, 1); |
93 | 89 |
|
94 | 90 | output.objectPos = mul(unity_ObjectToWorld, float4(vposition, 1)); |
|
0 commit comments