Hi,
i’m trying to set the offset of the secondary normal map (Unity 5 Standard Shader) using

rend.material.SetTextureOffset("_DetailNormalMap", new Vector2(offset, offset));

but the offset doesn’t change. Perhaps “_DetailNormalMap” is not the correct property name? I found it using the inspector debug view. Also, i can set the main normal using “_MainTex” / “_BumpMap” just fine.

This is how the material is set up in the editor:

52384-shader.jpg

Any idea what’s wrong?

You can’t. rend.material.SetTextureOffset() doesn’t work because it’s for the main texture i think.

Try to download the standard shader , change code to put a property available for designer in shader.

_OffsetX (“OffsetX”, Float) = 0

_OffsetY (“OffsetY”, Float) = 0

You put in code:

uv.x += _OffsetX;

uv.y += _OffsetY;

If you declare your vairable _OffsetX and _OffsetY in Properties , you can set via code C#.

Here is how to do the same thing, but a bit more detailed and with support for tiling in addition to offset.

-Download build in shaders.

-Copy “Standard.shader”, rename to “StandardShift.shader”, and put into project in the same folder called Shaders.

-Copy the following files and put into project in a folder called Shaders. Note that only the file “UnityStandardInput.cginc” from this list will be modified, but all other files are needed, otherwise it won’t work.

UnityStandardInput.cginc
UnityStandardCore.cginc
UnityStandardCoreForward.cginc
UnityStandardCoreForwardSimple.cginc
UnityStandardMeta.cginc

-Open StandardShift.shader.

-Modify the first line to:

Shader "StandardShift"

Place this code just below the line “_DetailNormalMap(“Normal Map”,…”

_EmissionTileOffset("EmissionTileOffset", Vector) = (1,1,0,0)

-Open UnityStandardInput.cginc.

Place this code just below the line “sampler2D _EmissionMap;”

half4		_EmissionTileOffset;

-Search for this function:

“half3 Emission(float2 uv)”

-Place this code just above the line “return tex2D(…”

uv.x *= _EmissionTileOffset.x;
uv.y *= _EmissionTileOffset.y;
uv.x += _EmissionTileOffset.z;
uv.y += _EmissionTileOffset.w;

-Create a material and set the shader to StandardShift.

-Add the material to an object.

-Create a script and add the script to the object.

-Add this code to the script:

rend = GetComponent<Renderer>();
rend.material.SetVector("_EmissionTileOffset", new Vector4(0.5f, 0.5f, 0f, 0f));

The vector format is:

Tile X, Tile Y, Offset X, Offset Y

Note that you can only set the shader properties in code, not in the Editor.

If it doesn’t work, make sure all required files are copied to the Shader folder. Then go to Unity->Assets->Reimport All. After that, select the StandardShift shader → Inspector → compile and show code.