본문 바로가기
Unity/수업 내용

[게임 그래픽] Shader - UV(Fire)

by 이지훈26 2021. 11. 18.

Qued 오브젝트생성

Fire Meterial 만들고 Fire Shader 만들어 Shader -> Meterial에 넣어주고

Meterial -> Qued를 넣어준다

Texture 넣어준다

 

코드

Shader "Custom/Fire"
{
    Properties
    {
        
        _MainTex ("Albedo (RGB)", 2D) = "white" { }
        _Texture2 ("texture2", 2D) = "white" { }
        
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" "Queue"="Transparent"}
        

        CGPROGRAM
        
        #pragma surface surf Standard alpha:fade

        sampler2D _MainTex;
        sampler2D _Texture2;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_Texture2;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            float4 d = tex2D(_Texture2, float2(IN.uv_Texture2.r, IN.uv_Texture2.g - _Time.y));
            o.Emission = c.rgb * d.rgb;
            o.Alpha = c.a * d.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 


불만 남기고 뒤에 배경을 없애는 코드

Tags { "RenderType"="Transparent" "Queue"="Transparent" }

유니티 - 매뉴얼: 서피스 쉐이더 작성 (unity3d.com)

 

유니티 - 매뉴얼: 서피스 쉐이더 작성

서피스 쉐이더 작성 라이팅과 상호 작용하는 쉐이더 기술은 복잡합니다. 각종 라이트, 각종 그림자 옵션, 각종 렌더링 패스(포워드 및 지연 렌더링)가 있으며, 쉐이더는 그 복잡성을 처리해야 합

docs.unity3d.com

▶ alpha:fade - 기존의 페이드 투명도를 활성화합니다.

#pragma surface surf Standard alpha:fade

fixed4 d = tex2D (_Texture2, float2(IN.uv_Texture2.r, IN.uv_Texture2.g - _Time.y)); 에서

_Time.y 를 써주면 위로 올라간다(시간의 흐름 느낌)

 


Shader "Custom/Fire"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Texture2 ("Texture2", 2D) = "white" {}
        _NoiseIntensity("Noise Intensity", Range(0, 2)) = 0
        _Test ("Test", Range(-1, 1)) = 0
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        //Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Standard alpha:fade

        sampler2D _MainTex;
        sampler2D _Texture2;
        float _NoiseIntensity;
        float _Test;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_Texture2;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            //data
            float4 d = tex2D(_Texture2, float2(IN.uv_Texture2.r, IN.uv_Texture2.g - _Time.y));    

            //texture
            float2 e = float2(IN.uv_MainTex.r + (d.r * _NoiseIntensity), (IN.uv_MainTex.g + _Test) + (d.r * _NoiseIntensity));
            fixed4 c = tex2D (_MainTex, e);
            
            //o.Emission = c.rgb * d.rgb;
            //o.Alpha = c.a * d.a;
            o.Emission = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}