From 5e82deaf218f34c55f629846e878851239e2c32f Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Wed, 9 Aug 2023 11:36:35 +0100 Subject: [PATCH] Better positioning for snap grid visualization --- Assets/Shaders/SnapGrid3D.shader | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Assets/Shaders/SnapGrid3D.shader b/Assets/Shaders/SnapGrid3D.shader index a43ce07c0b..1c5984e3a0 100644 --- a/Assets/Shaders/SnapGrid3D.shader +++ b/Assets/Shaders/SnapGrid3D.shader @@ -1,4 +1,4 @@ -// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' +// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' // MIT License // // Copyright (c) 2020 fuqunaga @@ -148,16 +148,16 @@ Shader "Custom/Grid3D" float3 _Pointer_CS = mul(_WorldToCanvasMatrix, _Pointer_GS); float3 quantizedPointer_CS = float3( - round(_Pointer_CS.x / _GridInterval) * _GridInterval, - round(_Pointer_CS.y / _GridInterval) * _GridInterval, - round(_Pointer_CS.z / _GridInterval) * _GridInterval + round((_Pointer_CS.x + _GridInterval * 0.5) / _GridInterval) * _GridInterval, + round((_Pointer_CS.y + _GridInterval * 0.5) / _GridInterval) * _GridInterval, + round((_Pointer_CS.z + _GridInterval * 0.5) / _GridInterval) * _GridInterval ); float3 _CanvasOrigin_CS = mul(_WorldToCanvasMatrix, _CanvasOrigin_GS); float3 quantizedCanvasOrigin_CS = float3( - round(_CanvasOrigin_CS.x / _GridInterval) * _GridInterval, - round(_CanvasOrigin_CS.y / _GridInterval) * _GridInterval, - round(_CanvasOrigin_CS.z / _GridInterval) * _GridInterval + round((_CanvasOrigin_CS.x + _GridInterval * 0.5) / _GridInterval) * _GridInterval, + round((_CanvasOrigin_CS.y + _GridInterval * 0.5) / _GridInterval) * _GridInterval, + round((_CanvasOrigin_CS.z + _GridInterval * 0.5) / _GridInterval) * _GridInterval ); float3 canvasOffsetFix_CS = quantizedCanvasOrigin_CS - _CanvasOrigin_CS; float3 canvasOffsetFix_GS = mul(_CanvasToWorldMatrix, canvasOffsetFix_CS);