diff --git a/DecalShader_VRC.shader b/DecalShader_VRC.shader index f80aed5..e01fae6 100644 --- a/DecalShader_VRC.shader +++ b/DecalShader_VRC.shader @@ -175,7 +175,6 @@ o.projectorSpacePos = ComputeNonStereoScreenPos(o.projectorSpacePos); o.localNormal = v.normal; o.localPos = v.vertex; - o.tex.xy = o.projectorSpacePos.xy; return o; } @@ -193,6 +192,8 @@ float4 i_ProjectorPos = UNITY_ACCESS_INSTANCED_PROP(Props, _ProjectorPos); clip(dot(lerp(-i_ProjectorPos.xyz, i_ProjectorPos.xyz - i.localPos, i_ProjectorPos.w), i.localNormal) + 0.00001); + i.projectorSpacePos *= _MainTex_ST; + i.projectorSpacePos.xy += _MainTex_ST.zw; i.tex = i.projectorSpacePos; FRAGMENT_SETUP(s) @@ -345,6 +346,8 @@ clip(isOut.x * isOut.y * isOut.z - 1); float4 i_ProjectorPos = UNITY_ACCESS_INSTANCED_PROP(Props, _ProjectorPos); clip(dot(lerp(-i_ProjectorPos.xyz, i_ProjectorPos.xyz - i.localPos, i_ProjectorPos.w), i.localNormal) + 0.00001); + i.projectorSpacePos *= _MainTex_ST; + i.projectorSpacePos.xy += _MainTex_ST.zw; i.tex.xy = i.projectorSpacePos.xy; UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); @@ -473,6 +476,8 @@ float4 i_ProjectorPos = UNITY_ACCESS_INSTANCED_PROP(Props, _ProjectorPos); clip(dot(lerp(-i_ProjectorPos.xyz, i_ProjectorPos.xyz - i.localPos, i_ProjectorPos.w), i.localNormal) + 0.00001); i.tex.xy = i.projectorSpacePos.xy; + i.tex.xy *= _MainTex_ST; + i.tex.xy += _MainTex_ST.zw; float4 projectorTex = tex2D(_MainTex, i.tex.xy); clip(projectorTex.a - _Cutoff); #if defined(_PARALLAXMAP) && (SHADER_TARGET >= 30) @@ -609,10 +614,12 @@ clip(isOut.x * isOut.y * isOut.z - 1); float4 i_ProjectorPos = UNITY_ACCESS_INSTANCED_PROP(Props, _ProjectorPos); clip(dot(lerp(-i_ProjectorPos.xyz, i_ProjectorPos.xyz - i.localPos, i_ProjectorPos.w), i.localNormal) + 0.00001); + i.projectorSpacePos *= _MainTex_ST; + i.projectorSpacePos.xy += _MainTex_ST.zw; float4 projectorTex = tex2D(_MainTex, i.projectorSpacePos.xy); float alpha = projectorTex.a * step(-dot(lerp(-_ProjectorPos.xyz, _ProjectorPos.xyz - i.localPos, _ProjectorPos.w), i.localNormal), 0); - clip(projectorTex - _Cutoff); + clip(projectorTex.a - _Cutoff); } half4 fragSceneHighlightPass(VertexOutput i) : SV_Target @@ -742,10 +749,12 @@ clip(isOut.x * isOut.y * isOut.z - 1); float4 i_ProjectorPos = UNITY_ACCESS_INSTANCED_PROP(Props, _ProjectorPos); clip(dot(lerp(-i_ProjectorPos.xyz, i_ProjectorPos.xyz - i.localPos, i_ProjectorPos.w), i.localNormal) + 0.00001); + i.projectorSpacePos *= _MainTex_ST; + i.projectorSpacePos.xy += _MainTex_ST.zw; float4 projectorTex = tex2D(_MainTex, i.projectorSpacePos.xy); float alpha = projectorTex.a * step(-dot(lerp(-_ProjectorPos.xyz, _ProjectorPos.xyz - i.localPos, _ProjectorPos.w), i.localNormal), 0); - clip(projectorTex - _Cutoff); + clip(projectorTex.a - _Cutoff); } half4 fragSceneHighlightPass(VertexOutput i) : SV_Target @@ -913,6 +922,8 @@ clip(isOut.x * isOut.y * isOut.z - 1); float4 i_ProjectorPos = UNITY_ACCESS_INSTANCED_PROP(Props, _ProjectorPos); clip(dot(lerp(-i_ProjectorPos.xyz, i_ProjectorPos.xyz - i.localPos, i_ProjectorPos.w), i.localNormal) + 0.00001); + i.projectorSpacePos *= _MainTex_ST; + i.projectorSpacePos.xy += _MainTex_ST.zw; i.tex.xy = i.projectorSpacePos.xy; FRAGMENT_SETUP(s) @@ -1045,6 +1056,8 @@ clip(isOut.x * isOut.y * isOut.z - 1); float4 i_ProjectorPos = UNITY_ACCESS_INSTANCED_PROP(Props, _ProjectorPos); clip(dot(lerp(-i_ProjectorPos.xyz, i_ProjectorPos.xyz - i.localPos, i_ProjectorPos.w), i.localNormal) + 0.00001); + i.projectorSpacePos *= _MainTex_ST; + i.projectorSpacePos.xy += _MainTex_ST.zw; i.uv.xy = i.projectorSpacePos.xy; #ifdef EDITOR_VISUALIZATION diff --git a/ProjectorInput.cs b/ProjectorInput.cs index bf58339..b662097 100644 --- a/ProjectorInput.cs +++ b/ProjectorInput.cs @@ -42,7 +42,7 @@ public void Update() material.SetVector("_ProjectorPos", projectorPos); } - private void OnDrawGizmos() + private void OnDrawGizmosSelected() { var gizmosMatrix = Gizmos.matrix; Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one); diff --git a/ProjectorInputUdon.cs b/ProjectorInputUdon.cs index 9d7e75f..b337605 100644 --- a/ProjectorInputUdon.cs +++ b/ProjectorInputUdon.cs @@ -19,7 +19,4 @@ public void Update() material.SetVector("_ProjectorPos", projectorPos); this.enabled = false; } - private void OnDrawGizmos() - { - } } diff --git a/Test.mat b/Test.mat index 8879615..c7f7e67 100644 --- a/Test.mat +++ b/Test.mat @@ -9,8 +9,8 @@ Material: m_PrefabAsset: {fileID: 0} m_Name: Test m_Shader: {fileID: 4800000, guid: 53d111573e45ef34795e4fa37c91a21e, type: 3} - m_ShaderKeywords: _ALPHATEST_ON - m_LightmapFlags: 4 + m_ShaderKeywords: _ALPHATEST_ON _EMISSION + m_LightmapFlags: 2 m_EnableInstancingVariants: 1 m_DoubleSidedGI: 0 m_CustomRenderQueue: 2450 @@ -21,7 +21,7 @@ Material: serializedVersion: 3 m_TexEnvs: - _BumpMap: - m_Texture: {fileID: 0} + m_Texture: {fileID: 2800000, guid: b43a3dbfb2da54640a6adb6bfd4526fa, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _DetailAlbedoMap: @@ -37,15 +37,15 @@ Material: m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _EmissionMap: - m_Texture: {fileID: 0} + m_Texture: {fileID: 2800000, guid: ff510a5ed1180cf4094512224d71f07e, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MainTex: - m_Texture: {fileID: 0} + m_Texture: {fileID: 2800000, guid: 9271f4ae86f872f4b835352352e76b48, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MetallicGlossMap: - m_Texture: {fileID: 0} + m_Texture: {fileID: 2800000, guid: 66137e5d238dfe54eaabda0685260c35, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _OcclusionMap: @@ -58,7 +58,7 @@ Material: m_Offset: {x: 0, y: 0} m_Floats: - _BumpScale: 1 - - _Cutoff: 0.5 + - _Cutoff: 0 - _DetailNormalMapScale: 1 - _DstBlend: 0 - _GlossMapScale: 1 @@ -75,4 +75,4 @@ Material: - _ZWrite: 1 m_Colors: - _Color: {r: 1, g: 1, b: 1, a: 1} - - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _EmissionColor: {r: 1, g: 1, b: 1, a: 1}