Skip to content

Commit

Permalink
Merge pull request #140 from prefrontalcortex/fix-texture-offset-and-…
Browse files Browse the repository at this point in the history
…tiling-on-shader-switch

Fix: Texture offset/tiling values getting lost when switching to other shaders
  • Loading branch information
atteneder authored Feb 19, 2021
2 parents f728859 + a0d0c56 commit 4815a66
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Runtime/Scripts/MaterialGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected enum MaterialType {
public static readonly int cutoffPropId = Shader.PropertyToID("_Cutoff");
public static readonly int emissionColorPropId = Shader.PropertyToID("_EmissionColor");
public static readonly int emissionMapPropId = Shader.PropertyToID("_EmissionMap");
public static readonly int mainTexPropId = Shader.PropertyToID("_MainTex");
public static readonly int mainTexRotation = Shader.PropertyToID("_MainTexRotation");
public static readonly int mainTexScaleTransform = Shader.PropertyToID("_MainTex_ST");
public static readonly int metallicPropId = Shader.PropertyToID("_Metallic");
Expand Down Expand Up @@ -210,6 +211,8 @@ private static void TrySetTextureTransform(
textureST.y = -textureST.y; // flip scale in Y
}

material.SetTextureOffset(mainTexPropId, textureST.zw);
material.SetTextureScale(mainTexPropId, textureST.xy);
material.SetVector(mainTexScaleTransform, textureST);
}

Expand Down

0 comments on commit 4815a66

Please sign in to comment.