Skip to content

Commit

Permalink
Offset and Tilling activate
Browse files Browse the repository at this point in the history
  • Loading branch information
frou01 committed Mar 29, 2023
1 parent efbe495 commit e3fc59c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
19 changes: 16 additions & 3 deletions DecalShader_VRC.shader
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ProjectorInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions ProjectorInputUdon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@ public void Update()
material.SetVector("_ProjectorPos", projectorPos);
this.enabled = false;
}
private void OnDrawGizmos()
{
}
}
16 changes: 8 additions & 8 deletions Test.mat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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}

0 comments on commit e3fc59c

Please sign in to comment.