/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Data/Base/Shaders/Editor/GizmoHandle.ezShader
128 строк
3 KB
Jan Krassnigg
Fixed #1915: Gizmos keep constant size in orthographic views
28 апр 2026, 10:24
28 апр 2026, 10:24
c539b89
Код
Авторство
О чём код?
[PLATFORMS] ALL [PERMUTATIONS] RENDER_PASS GIZMO_CONSTANT_SIZE PREPARE_DEPTH CAMERA_MODE GIZMO_FACE_CAMERA [RENDERSTATE] #if GIZMO_CONSTANT_SIZE == 1 CullMode = CullMode_Back #else CullMode = CullMode_Back #endif #if PREPARE_DEPTH == TRUE DepthTest = true DepthWrite = true DepthTestFunc = CompareFunc_Greater #else DepthTest = true DepthWrite = true DepthTestFunc = CompareFunc_LessEqual #endif #if !PREPARE_DEPTH && RENDER_PASS == RENDER_PASS_FORWARD BlendingEnabled0 = true BlendOp0 = BlendOp_Add DestBlend0 = Blend_InvSrcAlpha SourceBlend0 = Blend_SrcAlpha DestBlendAlpha0 = Blend_InvSrcAlpha #endif [MATERIALCONFIG] RenderDataCategory = SimpleForeground [VERTEXSHADER] #define USE_COLOR0 #define USE_NORMAL #include <Shaders/Common/GlobalConstants.h> #include <Shaders/Editor/GizmoConstants.h> #include <Shaders/Materials/MaterialInterpolator.h> VS_OUT main(VS_IN Input) { #if CAMERA_MODE == CAMERA_MODE_STEREO s_ActiveCameraEyeIndex = Input.InstanceID % 2; #endif float3 centerPosition = mul(ObjectToWorldMatrix, float4(0, 0, 0, 1)).xyz; #if GIZMO_CONSTANT_SIZE == 1 #if CAMERA_MODE == CAMERA_MODE_ORTHO // Ortho proj _m11 = 2 / visibleWorldHeight. Scaling by the visible world height // keeps the gizmo at constant pixel size regardless of ortho zoom. float orthoWorldHeight = 2.0f / GetCameraToScreenMatrix()._m11; float scale = orthoWorldHeight * GizmoScale; #else float scale = length(centerPosition - GetCameraPosition()) * GizmoScale; #endif #else float scale = 1.0f; #endif float expand = 0.0; #if (RENDER_PASS == RENDER_PASS_PICKING) || (RENDER_PASS == RENDER_PASS_PICKING_WIREFRAME) expand = 0.04; #endif float3 inpos = Input.Position.xyz + (Input.Normal.xyz * 2 - 1) * expand; #if GIZMO_FACE_CAMERA == 1 float3 localCamPos = mul(WorldToObjectMatrix, float4(GetCameraPosition().xyz, 1)).xyz; if (localCamPos.x < 0) inpos.x = -inpos.x; if (localCamPos.y < 0) inpos.y = -inpos.y; if (localCamPos.z < 0) inpos.z = -inpos.z; #endif float4 worldSpacePos = mul(ObjectToWorldMatrix, float4(inpos * scale, 1.0f)); VS_OUT RetVal; #if defined(CAMERA_MODE) # if CAMERA_MODE == CAMERA_MODE_STEREO RetVal.RenderTargetArrayIndex = Input.InstanceID % 2; # endif #endif RetVal.Position = mul(GetWorldToScreenMatrix(), worldSpacePos); RetVal.Color0 = GizmoColor; RetVal.Normal = float3(0, 1, 0); return RetVal; } [PIXELSHADER] #define USE_COLOR0 #define USE_NORMAL #include <Shaders/Common/GlobalConstants.h> #include <Shaders/Editor/GizmoConstants.h> #include <Shaders/Materials/MaterialInterpolator.h> float4 main(PS_IN Input) : SV_Target { #if PREPARE_DEPTH == 1 return float4(0, 0, 0, 1); #else #if (RENDER_PASS == RENDER_PASS_PICKING) || (RENDER_PASS == RENDER_PASS_PICKING_WIREFRAME) return RGBA8ToFloat4(GameObjectID); #else return Input.Color0; #endif #endif }