Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better positioning for snap grid visualization #493

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Assets/Shaders/SnapGrid3D.shader
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// MIT License
//
// Copyright (c) 2020 fuqunaga
Expand Down Expand Up @@ -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);
Expand Down