Search Unity

Question Apply material shader on texture.

Discussion in 'General Graphics' started by diordiychukdmitry, Nov 7, 2022.

  1. diordiychukdmitry

    diordiychukdmitry

    Joined:
    Jun 2, 2019
    Posts:
    2
    Hello. I would like to apply shader on texture to rotate it. I've chosen this way, because after that I want save series of rotations in png. Here is my code:

    Code (CSharp):
    1. public class Test : MonoBehaviour
    2.     {
    3.         public Texture2D texture;
    4.         public Material rotateShader;
    5.         public float timer;
    6.  
    7.         private Renderer _rend;
    8.         // Start is called before the first frame update
    9.         void Start()
    10.         {
    11.             _rend = gameObject.GetComponent<Renderer>();
    12.         }
    13.  
    14.         private float _t = 0.0f;
    15.  
    16.         private float degrees = 0.0f;
    17.         // Update is called once per frame
    18.         void Update()
    19.         {
    20.             if (_t >= timer)
    21.             {
    22.                 // rotateShader.SetFloat("Degrees", degrees);
    23.                 RenderTexture renderTexture = RenderTexture.GetTemporary(texture.width, texture.height, 0);
    24.                 Texture2D temp = new(texture.width, texture.height, DefaultFormat.LDR, TextureCreationFlags.None);
    25.                 Graphics.Blit(texture, renderTexture, rotateShader);
    26.                 Graphics.CopyTexture(renderTexture, temp);
    27.                 _rend.material.mainTexture = temp;
    28.                 RenderTexture.ReleaseTemporary(renderTexture);
    29.                 _t = 0.0f;
    30.                 degrees += 5.0f;
    31.             }
    32.  
    33.             _t += Time.deltaTime;
    34.         }
    35.     }
    Here is my shader:

    upload_2022-11-7_15-41-3.png
    For some reason I've got this:

    upload_2022-11-7_15-42-11.png

    Where I'm doing some thing wrong?
     
  2. diordiychukdmitry

    diordiychukdmitry

    Joined:
    Jun 2, 2019
    Posts:
    2
    Looks like it doesn't work in URP.