Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

행복한 개구리

Unity Shader 21.05.13. 불 효과만들기 본문

Unity/복습

Unity Shader 21.05.13. 불 효과만들기

HappyFrog 2021. 5. 14. 00:17

 

 

 

Shader "Custom/Test1"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}   
        _MainTex2("Albedo2 (RGB)", 2D) = "white" {}
        _MainTex3("Albedo3 (RGB)", 2D) = "white" {}
        _CrushCoef("CrushCoef", Float) = 0
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue" = "Transparent"}
        LOD 200

        CGPROGRAM        
        #pragma surface surf Standard alpha:fade

        sampler2D _MainTex;
        sampler2D _MainTex2;
        sampler2D _MainTex3;
        float _CrushCoef;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_MainTex2;
            float2 uv_MainTex3;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            float4 c3 = tex2D(_MainTex3, float2(IN.uv_MainTex3.x, IN.uv_MainTex3.y - _Time.y));
            float4 c2 = tex2D(_MainTex2, float2(IN.uv_MainTex2.x, IN.uv_MainTex2.y - _Time.y));
            fixed4 c = tex2D(_MainTex, float2(IN.uv_MainTex.x, IN.uv_MainTex.y - 0.035) + c2 * _CrushCoef);

            o.Emission = c.rgb * c3.rgb;
            o.Alpha = c.a * c2.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

1. c는 메인텍스쳐, c2는 데이터텍스쳐, c3는 불 안에서 일렁거림을 주는 텍스쳐이다.

2. alpha:fade를 빼먹지 않도록 조심하자.

3. 겹치는 부분이 더욱 진한 값을 갖게하기위해 c.rgb * c3.rgb를 했고 둘 중 하나라도 알파값이 0인부분은 출력되지 않게(둘이 겹치는 부분만 출력되게끔) c.a* c3.a를 사용했다.

4.그리고 _CrushCoef값의 조절을 통해 일그러짐 정도를 조절할 수 있다.(여기서는 0.5로 설정해놓았다.)

5.마지막으로 c의 y좌표에 0.035를 뺀 이유는 텍스쳐의 기본위치가 잘못되어 위쪽에서 불이 새는 것 처럼 보이길래 위치를 조정한 것이다.

각각의 텍스쳐의 시간값을 뺐을때의 결과
최종 결과물