From 7f0c121e68b0bd1fcabcf1e8d18e1b60fea177f3 Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 5 Mar 2025 10:32:19 +0800 Subject: [PATCH] stash update materials --- Runtime/Gizmos/DebugX.base.cs | 34 ++--- Runtime/Gizmos/DebugX.lines.cs | 6 +- Runtime/Materials/Billboard.mat | 9 +- Runtime/Materials/Dot.mat | 10 +- Runtime/Materials/Line.mat | 1 + Runtime/Materials/Lit.mat | 8 +- Runtime/Materials/Unlit.mat | 1 + Runtime/Materials/UnlitOverwrite.mat | 139 ++++++++++++++++++ Runtime/Materials/UnlitOverwrite.mat.meta | 8 + .../DCFApixels.DebugX/MaterialsList.prefab | 2 +- .../{HandlesUnlit.shader => Handles.shader} | 105 ++++++++----- ...sUnlit.shader.meta => Handles.shader.meta} | 0 Runtime/Shaders/HandlesLit.shader | 86 ----------- Runtime/Shaders/HandlesLit.shader.meta | 9 -- Runtime/Utils/StaticData.cs | 25 +--- 15 files changed, 266 insertions(+), 177 deletions(-) create mode 100644 Runtime/Materials/UnlitOverwrite.mat create mode 100644 Runtime/Materials/UnlitOverwrite.mat.meta rename Runtime/Shaders/{HandlesUnlit.shader => Handles.shader} (51%) rename Runtime/Shaders/{HandlesUnlit.shader.meta => Handles.shader.meta} (100%) delete mode 100644 Runtime/Shaders/HandlesLit.shader delete mode 100644 Runtime/Shaders/HandlesLit.shader.meta diff --git a/Runtime/Gizmos/DebugX.base.cs b/Runtime/Gizmos/DebugX.base.cs index 57b5f0d..cedf8dc 100644 --- a/Runtime/Gizmos/DebugX.base.cs +++ b/Runtime/Gizmos/DebugX.base.cs @@ -46,7 +46,7 @@ namespace DCFApixels #region Mesh //TODO потестить [IN(LINE)] public DrawHandler Mesh(Mesh mesh, Vector3 position, Quaternion rotation, Vector3 size) - where TMat : struct, IStaticMaterial_InstancedProcedural + where TMat : struct, IStaticMaterial { return Gizmo(new MeshGizmo(mesh, position, rotation, size)); } @@ -81,7 +81,7 @@ namespace DCFApixels } } private readonly struct MeshGizmo : IGizmo> - where TMat : struct, IStaticMaterial_InstancedProcedural + where TMat : struct, IStaticMaterial { public readonly Mesh Mesh; public readonly Quaternion Rotation; @@ -116,7 +116,7 @@ namespace DCFApixels [IN(LINE)] public DrawHandler Mesh(Vector3 position, Quaternion rotation, Vector3 size) where TMesh : struct, IStaticMesh - where TMat : struct, IStaticMaterial_InstancedProcedural + where TMat : struct, IStaticMaterial { return Gizmo(new InstancingMeshGizmo(position, rotation, size)); } @@ -153,7 +153,7 @@ namespace DCFApixels } private readonly struct InstancingMeshGizmo : IGizmo> where TMesh : struct, IStaticMesh - where TMat : struct, IStaticMaterial_InstancedProcedural + where TMat : struct, IStaticMaterial { public readonly Quaternion Rotation; public readonly Vector3 Position; @@ -184,7 +184,7 @@ namespace DCFApixels #region Line [IN(LINE)] public DrawHandler Line(Vector3 start, Vector3 end) - where TMat : struct, IStaticMaterial_InstancedProcedural + where TMat : struct, IStaticMaterial { return Gizmo(new WireLineGizmo(start, end)); } @@ -194,7 +194,7 @@ namespace DCFApixels return Gizmo(new WireLineGizmo(start, end)); } private readonly struct WireLineGizmo : IGizmo> - where TMat : struct, IStaticMaterial_InstancedProcedural + where TMat : struct, IStaticMaterial { public readonly Vector3 Start; public readonly Vector3 End; @@ -256,7 +256,7 @@ namespace DCFApixels } } - private readonly IStaticMaterial_InstancedProcedural _material; + private readonly IStaticMaterial _material; private int _buffersLength = 0; private PinnedArray _matrices; @@ -271,7 +271,7 @@ namespace DCFApixels public virtual int ExecuteOrder => _material.GetExecuteOrder(); public virtual bool IsStaticRender => true; - public MeshRendererBase(IStaticMaterial_InstancedProcedural material) + public MeshRendererBase(IStaticMaterial material) { _materialPropertyBlock = new MaterialPropertyBlock(); _material = material; @@ -316,7 +316,7 @@ namespace DCFApixels } public void Render(CommandBuffer cb) { - Material material = _material.GetMaterial_InstancedProcedural(); + Material material = _material.GetMaterial(); var items = new GizmosList(_gizmos.Array, _prepareCount).As().Items; _materialPropertyBlock.Clear(); _jobHandle.Complete(); @@ -360,7 +360,7 @@ namespace DCFApixels } private readonly IStaticMesh _mesh; - private readonly IStaticMaterial_InstancedProcedural _material; + private readonly IStaticMaterial _material; private readonly MaterialPropertyBlock _materialPropertyBlock; private GraphicsBuffer _graphicsBuffer; @@ -373,13 +373,13 @@ namespace DCFApixels private readonly bool _enableInstancing; - public InstancingMeshRendererBase(IStaticMesh mesh, IStaticMaterial_InstancedProcedural material) + public InstancingMeshRendererBase(IStaticMesh mesh, IStaticMaterial material) { _mesh = mesh; _material = material; _materialPropertyBlock = new MaterialPropertyBlock(); _drawDatas = PinnedArray.Pin(DummyArray.Get()); - _enableInstancing = IsSupportsComputeShaders && _material.GetMaterial_InstancedProcedural().enableInstancing; + _enableInstancing = IsSupportsComputeShaders && _material.GetMaterial().enableInstancing; } public virtual int ExecuteOrder => _material.GetExecuteOrder(); public virtual bool IsStaticRender => true; @@ -419,7 +419,7 @@ namespace DCFApixels Mesh mesh = _mesh.GetMesh(); if (_enableInstancing) { - Material material = _material.GetMaterial_InstancedProcedural(); + Material material = _material.GetMaterial(); _jobHandle.Complete(); _graphicsBuffer.SetData(_drawDatas.Array); cb.DrawMeshInstancedProcedural(mesh, 0, material, -1, _prepareCount, _materialPropertyBlock); @@ -479,7 +479,7 @@ namespace DCFApixels } } private readonly IStaticMesh _mesh = default(WireLineMesh); - private readonly IStaticMaterial_InstancedProcedural _material; + private readonly IStaticMaterial _material; private readonly MaterialPropertyBlock _materialPropertyBlock; private GraphicsBuffer _graphicsBuffer; @@ -492,12 +492,12 @@ namespace DCFApixels private readonly bool _enableInstancing; - public WireLineRendererBase(IStaticMaterial_InstancedProcedural material) + public WireLineRendererBase(IStaticMaterial material) { _material = material; _materialPropertyBlock = new MaterialPropertyBlock(); _drawDatas = PinnedArray.Pin(DummyArray.Get()); - _enableInstancing = IsSupportsComputeShaders && _material.GetMaterial_InstancedProcedural().enableInstancing; + _enableInstancing = IsSupportsComputeShaders && _material.GetMaterial().enableInstancing; } public virtual int ExecuteOrder => _material.GetExecuteOrder(); public virtual bool IsStaticRender => true; @@ -534,7 +534,7 @@ namespace DCFApixels Mesh mesh = _mesh.GetMesh(); if (_enableInstancing) { - Material material = _material.GetMaterial_InstancedProcedural(); + Material material = _material.GetMaterial(); _jobHandle.Complete(); _graphicsBuffer.SetData(_drawDatas.Array); cb.DrawMeshInstancedProcedural(mesh, 0, material, -1, _prepareCount, _materialPropertyBlock); diff --git a/Runtime/Gizmos/DebugX.lines.cs b/Runtime/Gizmos/DebugX.lines.cs index 27271bb..6c8688a 100644 --- a/Runtime/Gizmos/DebugX.lines.cs +++ b/Runtime/Gizmos/DebugX.lines.cs @@ -202,7 +202,7 @@ namespace DCFApixels public void Render(Camera camera, GizmosList list, CommandBuffer cb) { if (camera == null) { return; } - default(UnlitOverwriteMat).GetMaterial_InstancedProcedural().SetPass(0); + default(UnlitOverwriteMat).GetMaterial().SetPass(0); GL.Begin(GL.QUADS); Vector3 cameraPosition = camera.transform.position; foreach (ref readonly var item in list) @@ -256,7 +256,7 @@ namespace DCFApixels public void Render(Camera camera, GizmosList list, CommandBuffer cb) { if (camera == null) { return; } - default(UnlitOverwriteMat).GetMaterial_InstancedProcedural().SetPass(0); + default(UnlitOverwriteMat).GetMaterial().SetPass(0); GL.Begin(GL.LINES); var cameraPosition = camera.transform.position; foreach (ref readonly var item in list) @@ -318,7 +318,7 @@ namespace DCFApixels { if (camera == null) { return; } GL.PushMatrix(); - default(UnlitOverwriteMat).GetMaterial_InstancedProcedural().SetPass(0); + default(UnlitOverwriteMat).GetMaterial().SetPass(0); GL.Begin(GL.LINES); var cameraPosition = camera.transform.position; foreach (ref readonly var item in list) diff --git a/Runtime/Materials/Billboard.mat b/Runtime/Materials/Billboard.mat index a5c1f96..69e00ae 100644 --- a/Runtime/Materials/Billboard.mat +++ b/Runtime/Materials/Billboard.mat @@ -21,10 +21,11 @@ Material: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: Billboard - m_Shader: {fileID: 4800000, guid: 0fe57c76c30f7274f9ebb46c87d64036, type: 3} + m_Shader: {fileID: 4800000, guid: 37036939f3d0a824c82a3f34093d4a42, type: 3} m_Parent: {fileID: 0} m_ModifiedSerializedProperties: 0 - m_ValidKeywords: [] + m_ValidKeywords: + - _BILLBOARD_ON m_InvalidKeywords: [] m_LightmapFlags: 4 m_EnableInstancingVariants: 1 @@ -98,6 +99,7 @@ Material: - _AddPrecomputedVelocity: 0 - _AlphaClip: 0 - _AlphaToMask: 0 + - _Billboard: 1 - _Blend: 0 - _BlendModePreserveSpecular: 1 - _BumpScale: 1 @@ -107,9 +109,11 @@ Material: - _Cutoff: 0.5 - _DetailAlbedoMapScale: 1 - _DetailNormalMapScale: 1 + - _Dot: 0 - _DstBlend: 0 - _DstBlendAlpha: 0 - _EnvironmentReflections: 1 + - _FakeLight: 0 - _GlossMapScale: 0 - _Glossiness: 0 - _GlossyReflections: 0 @@ -124,6 +128,7 @@ Material: - _SrcBlend: 1 - _SrcBlendAlpha: 1 - _Surface: 0 + - _VertexColor: 0 - _WorkflowMode: 1 - _ZWrite: 1 m_Colors: diff --git a/Runtime/Materials/Dot.mat b/Runtime/Materials/Dot.mat index 6f7ef0a..288196c 100644 --- a/Runtime/Materials/Dot.mat +++ b/Runtime/Materials/Dot.mat @@ -21,10 +21,12 @@ Material: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: Dot - m_Shader: {fileID: 4800000, guid: 69efe102f685e6c4cb2e2f25b7f7bdc7, type: 3} + m_Shader: {fileID: 4800000, guid: 37036939f3d0a824c82a3f34093d4a42, type: 3} m_Parent: {fileID: 0} m_ModifiedSerializedProperties: 0 - m_ValidKeywords: [] + m_ValidKeywords: + - _BILLBOARD_ON + - _DOT_ON m_InvalidKeywords: [] m_LightmapFlags: 4 m_EnableInstancingVariants: 1 @@ -98,6 +100,7 @@ Material: - _AddPrecomputedVelocity: 0 - _AlphaClip: 0 - _AlphaToMask: 0 + - _Billboard: 1 - _Blend: 0 - _BlendModePreserveSpecular: 1 - _BumpScale: 1 @@ -107,9 +110,11 @@ Material: - _Cutoff: 0.5 - _DetailAlbedoMapScale: 1 - _DetailNormalMapScale: 1 + - _Dot: 1 - _DstBlend: 0 - _DstBlendAlpha: 0 - _EnvironmentReflections: 1 + - _FakeLight: 0 - _GlossMapScale: 0 - _Glossiness: 0 - _GlossyReflections: 0 @@ -124,6 +129,7 @@ Material: - _SrcBlend: 1 - _SrcBlendAlpha: 1 - _Surface: 0 + - _VertexColor: 0 - _WorkflowMode: 1 - _ZWrite: 1 m_Colors: diff --git a/Runtime/Materials/Line.mat b/Runtime/Materials/Line.mat index a5ff50a..7ba81f6 100644 --- a/Runtime/Materials/Line.mat +++ b/Runtime/Materials/Line.mat @@ -26,6 +26,7 @@ Material: m_Ints: [] m_Floats: - _FakeLight: 0 + - _OnePass: 0 - _VertexColor: 0 m_Colors: - _Color: {r: 1, g: 1, b: 1, a: 1} diff --git a/Runtime/Materials/Lit.mat b/Runtime/Materials/Lit.mat index 32a7f83..a8a879c 100644 --- a/Runtime/Materials/Lit.mat +++ b/Runtime/Materials/Lit.mat @@ -21,10 +21,12 @@ Material: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: Lit - m_Shader: {fileID: 4800000, guid: b3126f69d0ed1ac439449358fc8a54aa, type: 3} + m_Shader: {fileID: 4800000, guid: 37036939f3d0a824c82a3f34093d4a42, type: 3} m_Parent: {fileID: 0} m_ModifiedSerializedProperties: 0 - m_ValidKeywords: [] + m_ValidKeywords: + - _FAKELIGHT_ON + - _VERTEXCOLOR_ON m_InvalidKeywords: [] m_LightmapFlags: 4 m_EnableInstancingVariants: 1 @@ -110,6 +112,7 @@ Material: - _DstBlend: 0 - _DstBlendAlpha: 0 - _EnvironmentReflections: 1 + - _FakeLight: 1 - _GlossMapScale: 0 - _Glossiness: 0 - _GlossyReflections: 0 @@ -124,6 +127,7 @@ Material: - _SrcBlend: 1 - _SrcBlendAlpha: 1 - _Surface: 0 + - _VertexColor: 1 - _WorkflowMode: 1 - _ZWrite: 1 m_Colors: diff --git a/Runtime/Materials/Unlit.mat b/Runtime/Materials/Unlit.mat index 779b0c7..3a0221e 100644 --- a/Runtime/Materials/Unlit.mat +++ b/Runtime/Materials/Unlit.mat @@ -117,6 +117,7 @@ Material: - _GlossyReflections: 0 - _Metallic: 0 - _OcclusionStrength: 1 + - _OnePass: 0 - _Parallax: 0.005 - _QueueOffset: 0 - _ReceiveShadows: 1 diff --git a/Runtime/Materials/UnlitOverwrite.mat b/Runtime/Materials/UnlitOverwrite.mat new file mode 100644 index 0000000..46ac703 --- /dev/null +++ b/Runtime/Materials/UnlitOverwrite.mat @@ -0,0 +1,139 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &-8282512757102464268 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 9 +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: UnlitOverwrite + m_Shader: {fileID: 4800000, guid: 7bfe6625bfb0167438e98aa0d69e97e7, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: + - _VERTEXCOLOR_ON + m_LightmapFlags: 4 + m_EnableInstancingVariants: 1 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: + - MOTIONVECTORS + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BaseMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AddPrecomputedVelocity: 0 + - _AlphaClip: 0 + - _AlphaToMask: 0 + - _Blend: 0 + - _BlendModePreserveSpecular: 1 + - _BumpScale: 1 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _Cull: 2 + - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _DstBlendAlpha: 0 + - _EnvironmentReflections: 1 + - _FakeLight: 0 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _Metallic: 0 + - _OcclusionStrength: 1 + - _OnePass: 0 + - _Parallax: 0.005 + - _QueueOffset: 0 + - _ReceiveShadows: 1 + - _Smoothness: 0.5 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _SrcBlendAlpha: 1 + - _Surface: 0 + - _VertexColor: 1 + - _WorkflowMode: 1 + - _ZWrite: 1 + m_Colors: + - _BaseColor: {r: 1, g: 1, b: 1, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} + m_BuildTextureStacks: [] + m_AllowLocking: 1 diff --git a/Runtime/Materials/UnlitOverwrite.mat.meta b/Runtime/Materials/UnlitOverwrite.mat.meta new file mode 100644 index 0000000..c72033c --- /dev/null +++ b/Runtime/Materials/UnlitOverwrite.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c39ea10bc1b7eeb4b95b16a7d83e82d8 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Resources/DCFApixels.DebugX/MaterialsList.prefab b/Runtime/Resources/DCFApixels.DebugX/MaterialsList.prefab index 69fa769..112bd76 100644 --- a/Runtime/Resources/DCFApixels.DebugX/MaterialsList.prefab +++ b/Runtime/Resources/DCFApixels.DebugX/MaterialsList.prefab @@ -533,7 +533,7 @@ MeshRenderer: m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: - - {fileID: 2100000, guid: e3db4ecf82b06ef4fa7fdb30e68362fa, type: 2} + - {fileID: 2100000, guid: c39ea10bc1b7eeb4b95b16a7d83e82d8, type: 2} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 diff --git a/Runtime/Shaders/HandlesUnlit.shader b/Runtime/Shaders/Handles.shader similarity index 51% rename from Runtime/Shaders/HandlesUnlit.shader rename to Runtime/Shaders/Handles.shader index 11e1cbe..2de88d5 100644 --- a/Runtime/Shaders/HandlesUnlit.shader +++ b/Runtime/Shaders/Handles.shader @@ -1,11 +1,12 @@ -Shader "DCFApixels/DebugX/Handles Unlit" +Shader "DCFApixels/DebugX/Handles" { Properties { _Color ("Color", Color) = (1,1,1,1) [Toggle] _VertexColor("Vertex Color", Float) = 0 [Toggle] _FakeLight("Fake Light", Float) = 0 - [Toggle] _OnePass("One Pass", Float) = 0 + [Toggle] _Billboard("Billboard", Float) = 0 + [Toggle] _Dot("Dot", Float) = 0 } SubShader { @@ -25,11 +26,13 @@ Shader "DCFApixels/DebugX/Handles Unlit" #pragma shader_feature_local _VERTEXCOLOR_ON #pragma shader_feature_local _FAKELIGHT_ON #pragma shader_feature_local _ONEPASS_ON + #pragma shader_feature_local _BILLBOARD_ON + #pragma shader_feature_local _DOT_ON #pragma instancing_options procedural:setup #include "UnityCG.cginc" -#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED +#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) struct InstanceData { float4x4 m; @@ -37,32 +40,6 @@ Shader "DCFApixels/DebugX/Handles Unlit" }; StructuredBuffer _DataBuffer; #endif - - - void setup() - { -#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED - InstanceData data = _DataBuffer[unity_InstanceID]; - float4x4 m = data.m; - - float rotation = m.w * m.w * _Time.y * 0.5f; - rotate2D(m.xz, rotation); - - unity_ObjectToWorld._11_21_31_41 = float4(m.w, 0, 0, 0); - unity_ObjectToWorld._12_22_32_42 = float4(0, m.w, 0, 0); - unity_ObjectToWorld._13_23_33_43 = float4(0, 0, m.w, 0); - unity_ObjectToWorld._14_24_34_44 = float4(m.xyz, 1); - unity_WorldToObject = unity_ObjectToWorld; - unity_WorldToObject._14_24_34 *= -1; - unity_WorldToObject._11_22_33 = 1.0f / unity_WorldToObject._11_22_33; - - _Color = data.color; -#endif - } - - - - struct appdata_t { float4 vertex : POSITION; @@ -72,8 +49,7 @@ Shader "DCFApixels/DebugX/Handles Unlit" #if _VERTEXCOLOR_ON float4 color : COLOR; #endif - uint instanceID : SV_InstanceID; - UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_INPUT_INSTANCE_ID }; struct v2f @@ -85,18 +61,73 @@ Shader "DCFApixels/DebugX/Handles Unlit" float4 _Color; float4 _DebugX_GlobalColor; + void setup() + { +#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) + InstanceData data = _DataBuffer[unity_InstanceID]; + + UNITY_MATRIX_M = data.m; //UNITY_MATRIX_M + _Color = data.color; +#endif + } + + + + +#if _DOT_ON + float _DebugX_GlobalDotSize; + float GetHandleSize(float3 objectPosition) + { + float3 viewDir = normalize(_WorldSpaceCameraPos - objectPosition); + + float distance = length(_WorldSpaceCameraPos - objectPosition); + float isOrthographic = UNITY_MATRIX_P[3][3]; + distance = lerp(distance, 1, isOrthographic); + + float fov = radians(UNITY_MATRIX_P[1][1] * 2.0); + float scale = distance * (1 / fov) * 0.015; + + return scale * _DebugX_GlobalDotSize; + } +#endif + + + v2f vert (appdata_t v) { v2f o; + UNITY_SETUP_INSTANCE_ID(v); -#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED - InstanceData data = _DataBuffer[v.instanceID]; - float4 pos = mul(data.m, v.vertex); - o.vertex = UnityObjectToClipPos(pos); - half4 color = data.color; + float4x4 M = UNITY_MATRIX_M; +#if _DOT_ON + float scaleMultiplier = GetHandleSize(mul(UNITY_MATRIX_M, float4(0, 0, 0, 1)).xyz); + M._m00 *= scaleMultiplier; + M._m11 *= scaleMultiplier; + M._m22 *= scaleMultiplier; +#endif + + +#if _BILLBOARD_ON + float4 worldOrigin = mul(M, float4(0, 0, 0, 1)); + float4 viewOrigin = float4(UnityObjectToViewPos(float3(0, 0, 0)), 1); + float4 worldPos = mul(M, v.vertex); + + float4 viewPos = worldPos - worldOrigin + viewOrigin; + + float4 clipsPos = mul(UNITY_MATRIX_P, viewPos); + o.vertex = clipsPos; #else - o.vertex = UnityObjectToClipPos(v.vertex); + o.vertex = UnityObjectToClipPos(v.vertex); //UNITY_MATRIX_VP +#endif + + half4 color = _Color; +#if _FAKELIGHT_ON + float3 eyeNormal = normalize (mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal).xyz); + float nl = saturate(eyeNormal.z); + float lighting = 0.333 + nl * 0.667 * 0.5; + color.rgb = lighting * color.rgb; + color = saturate(color) * _DebugX_GlobalColor; #endif #if _VERTEXCOLOR_ON diff --git a/Runtime/Shaders/HandlesUnlit.shader.meta b/Runtime/Shaders/Handles.shader.meta similarity index 100% rename from Runtime/Shaders/HandlesUnlit.shader.meta rename to Runtime/Shaders/Handles.shader.meta diff --git a/Runtime/Shaders/HandlesLit.shader b/Runtime/Shaders/HandlesLit.shader deleted file mode 100644 index 675c150..0000000 --- a/Runtime/Shaders/HandlesLit.shader +++ /dev/null @@ -1,86 +0,0 @@ -Shader "DCFApixels/DebugX/Handles Lit" -{ - Properties - { - _Color ("Color", Color) = (1,1,1,1) - } - SubShader - { - Tags { "Queue"="Transparent" "RenderType"="Transparent" "IgnoreProjector"="True" "ForceNoShadowCasting"="True" } - Blend SrcAlpha OneMinusSrcAlpha - ZWrite Off - Fog { Mode Off } - Lighting Off - Offset -1, -1 - - ZTest On - - CGINCLUDE - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile_instancing - #include "UnityCG.cginc" - - struct appdata_t - { - float3 vertex : POSITION; - float3 normal : NORMAL; - float4 color : COLOR; - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - struct v2f - { - float4 vertex : SV_POSITION; - half4 color : COLOR0; - }; - - UNITY_INSTANCING_BUFFER_START(Props) - UNITY_DEFINE_INSTANCED_PROP(float4, _Color) - UNITY_INSTANCING_BUFFER_END(Props) - - float4 _DebugX_GlobalColor; - - v2f vert (appdata_t v) - { - v2f o; - UNITY_SETUP_INSTANCE_ID(v); - - float4 icolor = UNITY_ACCESS_INSTANCED_PROP(Props, _Color); - if (icolor.a >= 0) - { - v.color = v.color * icolor; - } - float3 eyeNormal = normalize (mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal).xyz); - float nl = saturate(eyeNormal.z); - float lighting = 0.333 + nl * 0.667 * 0.5; - float4 color; - color.rgb = lighting * v.color.rgb; - color.a = v.color.a; - o.color = saturate(color) * _DebugX_GlobalColor; - o.vertex = UnityObjectToClipPos(v.vertex); - return o; - } - ENDCG - - Pass - { - ZTest LEqual - CGPROGRAM - half4 frag (v2f i) : SV_Target - { - return i.color; - } - ENDCG - } - Pass - { - ZTest Greater - CGPROGRAM - half4 frag (v2f i) : SV_Target - { - return i.color * half4(1, 1, 1, 0.2); - } - ENDCG - } - } -} diff --git a/Runtime/Shaders/HandlesLit.shader.meta b/Runtime/Shaders/HandlesLit.shader.meta deleted file mode 100644 index 9864f09..0000000 --- a/Runtime/Shaders/HandlesLit.shader.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: b3126f69d0ed1ac439449358fc8a54aa -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Utils/StaticData.cs b/Runtime/Utils/StaticData.cs index 862e534..dc8a749 100644 --- a/Runtime/Utils/StaticData.cs +++ b/Runtime/Utils/StaticData.cs @@ -7,10 +7,6 @@ namespace DCFApixels.DebugXCore int GetExecuteOrder(); Material GetMaterial(); } - public interface IStaticMaterial_InstancedProcedural : IStaticMaterial - { - Material GetMaterial_InstancedProcedural(); - } public interface IStaticMesh : IStaticData { Mesh GetMesh(); @@ -19,46 +15,39 @@ namespace DCFApixels.DebugXCore ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public readonly struct LitMat : IStaticMaterial_InstancedProcedural + public readonly struct LitMat : IStaticMaterial { public int GetExecuteOrder() => 0; - public Material GetMaterial_InstancedProcedural() => DebugXAssets.Materials.Lit; public Material GetMaterial() => DebugXAssets.Materials.Lit; } - public readonly struct UnlitMat : IStaticMaterial_InstancedProcedural + public readonly struct UnlitMat : IStaticMaterial { public int GetExecuteOrder() => 100_000; - public Material GetMaterial_InstancedProcedural() => DebugXAssets.Materials.Unlit; public Material GetMaterial() => DebugXAssets.Materials.Unlit; } - public readonly struct BillboardMat : IStaticMaterial_InstancedProcedural + public readonly struct BillboardMat : IStaticMaterial { public int GetExecuteOrder() => 200_000; - public Material GetMaterial_InstancedProcedural() => DebugXAssets.Materials.Billboard; public Material GetMaterial() => DebugXAssets.Materials.Billboard; } - public readonly struct DotMat : IStaticMaterial_InstancedProcedural + public readonly struct DotMat : IStaticMaterial { public int GetExecuteOrder() => 300_000; - public Material GetMaterial_InstancedProcedural() => DebugXAssets.Materials.Dot; public Material GetMaterial() => DebugXAssets.Materials.Dot; } - public readonly struct GeometryUnlitMat : IStaticMaterial_InstancedProcedural + public readonly struct GeometryUnlitMat : IStaticMaterial { public int GetExecuteOrder() => 1_000_000; - public Material GetMaterial_InstancedProcedural() => DebugXAssets.Materials.Unlit; public Material GetMaterial() => DebugXAssets.Materials.Unlit; } - public readonly struct UnlitOverwriteMat : IStaticMaterial_InstancedProcedural + public readonly struct UnlitOverwriteMat : IStaticMaterial { public int GetExecuteOrder() => 1_000_000; - public Material GetMaterial_InstancedProcedural() => DebugXAssets.Materials.UnlitOverwrite; public Material GetMaterial() => DebugXAssets.Materials.UnlitOverwrite; } - public readonly struct WireMat : IStaticMaterial_InstancedProcedural + public readonly struct WireMat : IStaticMaterial { public int GetExecuteOrder() => 1_000_000; - public Material GetMaterial_InstancedProcedural() => DebugXAssets.Materials.Wire; public Material GetMaterial() => DebugXAssets.Materials.Wire; }