Game Engine/Unity

[์ด์Šˆ/ํ•ด๊ฒฐ]HDRP Lit Shader Material offset ๋ณ€๊ฒฝ

SOMmeow 2021. 12. 3. 21:24

์—ฐ๊ธฐ๊ฐ€ X์ถ•์œผ๋กœ ์ด๋™ํ•˜๋Š” ํ…์Šค์ณ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ (HDRP/Lit shader)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveFogOffset : MonoBehaviour
{
    // Scroll main texture based on time

    float scrollSpeed = 0.01f;
    public Renderer rend;

    void Start()
    {
        rend = GetComponent<Renderer> ();
    }

    void Update()
    {
        float offset = Time.time * scrollSpeed;
        rend.material.SetTextureOffset("_BaseColorMap", new Vector2(offset, 0));

        print (rend.material.GetTextureOffset("_BaseColorMap"));
    }
}

 

๊ตฌ๊ธ€์— texture offset change์ด๋Ÿฐ๊ฑฐ ๊ฒ€์ƒ‰ํ•˜๋ฉด 

๋Œ€๋ถ€๋ถ„ standard shader ๋ฒ„์ „์œผ๋กœ ๋‚˜์™€์„œ HDRP Lit shader ๋ฒ„์ „ ์Šคํฌ๋ฆฝํŠธ ๊ณต์œ ํ•จ

(URP๋Š” ์•ˆํ•ด๋ด์„œ ๋˜๋Š”์ง€ ์•ˆ๋˜๋Š”์ง€ ๋ชจ๋ฆ„)

 

์Šคํƒ ๋‹ค๋“œ ์…ฐ์ด๋”๋Š” "_BaseColorMap"  ๋Œ€์‹ ์— "_MainTex"๋กœ ๋ฐ”๊พธ๋ฉด๋จ.

 

 

์ด๊ฒŒ ํ—ท๊ฐˆ๋ ธ๋˜๊ฒŒ

_MainTex ํ”„๋กœํผํ‹ฐ๊ฐ€ HDRP Lit shader์— ์‹ค์ œ๋กœ ์žˆ๊ธฐ๋„ ํ•˜๊ณ 

(with Shader 'HDRP/Lit' doesn't have a texture property '_MainText') ์ด๋Ÿฐ ๋กœ๊ทธ๊ฐ€ ์•ˆ๋œฌ๋‹จ์†Œ๋ฆฌ)

์–ด๋–ค ์ฐจ์ด์ธ์ง€๋Š” ๋ชจ๋ฆ„ ๋‚œ ์…ฐ์ด๋”์™€ ์œ ๋‹ˆํ‹ฐ ํ•˜์ˆ˜์ด๊ธฐ ๋•Œ๋ฌธ์—. ๊ณ ์ˆ˜๋‹˜๋“ค์ด ๋Œ“๊ธ€๋กœ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”

 

๋Ÿฐํƒ€์ž„์ค‘์— TIling์„ ์ธ์ŠคํŽ™ํ„ฐ์—์„œ(๋งจ ์ฒซ๋ฒˆ์งธ์‚ฌ์ง„) ์ž„์˜๋กœ ์กฐ์ž‘ํ•ด์ฃผ๋ฉด ๋ณ€๊ฒฝํ•œ ๋Œ€๋กœ ํ”„๋ฆฐํŒ…๋˜๊ธดํ•จ

์ฝ๊ธฐ์ „์šฉ๋„ ์•„๋‹ˆ๊ณ  ์ฐธ๋‚˜

        print(rend.material.GetTextureOffset("_MainTex"));//์ด๋ ‡๊ฒŒํ”„๋ฆฐํŒ…ํ–ˆ์Šต๋‹ˆ๋‹ค

ํ•ด๊ฒฐํ•˜๋Š”์‹œ๊ฐ„๋ณด๋‹ค ํฌ์ŠคํŒ…ํ•˜๋Š”์‹œ๊ฐ„์ด ๋”์˜ค๋ž˜๊ฑธ๋ฆฌ๋„ค

 

 


 

์ฐธ๊ณ ๋งํฌ :

 

https://stackoverflow.com/questions/55372756/how-to-change-a-material-offset-in-hdrp-material-shader-type