Search Unity

How to change secondary map tiling scale run time with C#

Discussion in 'Scripting' started by paragyogi, Dec 15, 2018.

  1. paragyogi

    paragyogi

    Joined:
    Oct 4, 2018
    Posts:
    10
    I need to change tiling of secondary map run time through C#
    with material.mainTextureScale only change to main texture is happening
    001 Accessing Secondary Map Tiling.png
    Was not able to find solution online can you please support
     
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    831
    You can set the properties of the built-in shaders using material.SetFloat etc...

    To get the shader variable names you can right click the material and select 'edit shader' to view the source code.

    Something like this code will set the secondary UV type:

    Code (CSharp):
    1. meshRenderer.material.SetFloat( "_UVSec" , 0 );
    For changing tiling/offsets you can pass a different texture name. Instead of:

    Code (CSharp):
    1. meshRenderer.material.SetTextureScale("_MainTex", new Vector2(scaleX, scaleY));
    try:

    Code (CSharp):
    1. meshRenderer.material.SetTextureScale("_DetailAlbedoMap", new Vector2(scaleX, scaleY));
    or any number of the other maps available in that shader.
     
  3. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    518
    Currently looking for a way to do this using GLSL or Shader Language so it's not passed through the CPU, but the GPU instead:



    Is this possible in GLSL?