본문 바로가기
Shader/Unity Shader

Unity Shader Code 구조

by Dev_Cat 2025. 1. 19.
728x90
반응형

* 해당 코드는 복사 후 여러 방향으로 수정하여 사용하셔도 됩니다.

 

Shader "HughShaders/01TestShader"
{
    Properties
    {
    	// Shader에서 사용할 변수를 선언한다.
        // 선언된 변수들은 Material Inspector에 노출된다.
    }
    SubShader
    {
    	// 렌더링 순서 및 기타 매개 변수를 통해 Shader를 구현하는 부분
        
        Tags 
        { 
        	// Render Type, Render Queue를 결정하는 곳
            "RednerPipeline="UniversalPipeline"
        	"RenderType"="Opaque" 
            "Queue"="Geometry"
        }
        
        // Load Of Distance
        LOD 100

        Pass
        {
            HLSLPROGRAM // RenderPipeline에 URP 이므로 이렇게 선언
            #pragma vertex vert // Runs on every vert
            #pragma fragment frag // Runs on every single pixel
            
            // urp shader는 hlsl shader로 .hlsl을 include한다.
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"      
            
            struct appdata // Object Data or Mesh
            {
                float4 vertex : POSITION; // vertex position
            };

            struct v2f // Vertex to frag, passa data from the vert shader to fragment
            {
                float4 vertex : SV_POSITION;
                fixed4 color : COLOR;
            };

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex); // Model Vier Projection
                o.color.xyz = v.normal * 0.5f + 0.5;
                o.color.w = 1.0;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
            	return fixed4(1,1,1,1);
            }
            ENDCG
        }
    }
}
728x90
반응형

'Shader > Unity Shader' 카테고리의 다른 글

Erosion Shader  (0) 2025.01.26