{!See https://docs.google.com/document/d/1takg_GmIBBKKTj-GHZCwzxohpQz7Bhekivkk72kYMtE/edit for reference implementation of OneTrust, dataLayer and GTM} {!OneTrust Cookies Consent} {!OneTrust Cookies Consent end} {!dataLayer initialization push} {!dataLayer initialization push end} {!Google Tag Manager} {!Google Tag Manager end} URP 언릿 기본 셰이더 | Universal RP | 8.2.0
docs.unity3d.com
"{0}"의 검색 결과

    목차 표시/숨기기

    URP 언릿 기본 셰이더

    이 예제는 기본 URP 호환 셰이더를 보여줍니다. 이 셰이더는 셰이더 코드에 사전 정의된 컬러로 메시 모양을 채웁니다.

    동작 중인 셰이더를 확인하려면 다음 ShaderLab 코드를 복사하여 셰이더 에셋에 붙여 넣으십시오.

    // This shader fills the mesh shape with a color predefined in the code.
    Shader "Example/URPUnlitShaderBasic"
    {
        // The properties block of the Unity shader. In this example this block is empty
        // because the output color is predefined in the fragment shader code.
        Properties
        { }
    
        // The SubShader block containing the Shader code. 
        SubShader
        {
            // SubShader Tags define when and under which conditions a SubShader block or
            // a pass is executed.
            Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
            
            Pass
            {
                // The HLSL code block. Unity SRP uses the HLSL language.
                HLSLPROGRAM
                // This line defines the name of the vertex shader. 
                #pragma vertex vert
                // This line defines the name of the fragment shader. 
                #pragma fragment frag
    
                // The Core.hlsl file contains definitions of frequently used HLSL
                // macros and functions, and also contains #include references to other
                // HLSL files (for example, Common.hlsl, SpaceTransforms.hlsl, etc.).
                #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"            
                
                // The structure definition defines which variables it contains.
                // This example uses the Attributes structure as an input structure in
                // the vertex shader.
                struct Attributes
                {
                    // The positionOS variable contains the vertex positions in object
                    // space.
                    float4 positionOS   : POSITION;                 
                };
    
                struct Varyings
                {
                    // The positions in this struct must have the SV_POSITION semantic.
                    float4 positionHCS  : SV_POSITION;
                };            
    
                // The vertex shader definition with properties defined in the Varyings 
                // structure. The type of the vert function must match the type (struct)
                // that it returns.
                Varyings vert(Attributes IN)
                {
                    // Declaring the output object (OUT) with the Varyings struct.
                    Varyings OUT;
                    // The TransformObjectToHClip function transforms vertex positions
                    // from object space to homogenous space
                    OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
                    // Returning the output.
                    return OUT;
                }
    
                // The fragment shader definition.            
                half4 frag() : SV_Target
                {
                    // Defining the color variable and returning it.
                    half4 customColor;
                    customColor = half4(0.5, 0, 0, 1);
                    return customColor;
                }
                ENDHLSL
            }
        }
    }
    

    프래그먼트 셰이더는 게임 오브젝트에 암적색(RGB 값(0.5, 0, 0))을 지정합니다.

    셰이더가 게임 오브젝트를 암적색으로 페인트함

    다음 섹션에서는 기본 Unity 셰이더의 구조에 대해 소개합니다.

    기본 ShaderLab 구조

    Unity 셰이더는 ShaderLab이라는 Unity 전용 언어로 작성됩니다.

    이 예제의 Unity 셰이더에는 다음의 블록이 포함되어 있습니다.

    • 셰이더
    • 프로퍼티
    • 서브셰이더
    • 패스
    • HLSLPROGRAM

    셰이더 블록

    ShaderLab 코드는 Shader 선언으로 시작합니다.

    셰이더 "Example/URPUnlitShaderBasic"
    

    이 선언의 경로는 머티리얼의 셰이더 메뉴에 있는 Unity 셰이더의 표시 이름과 위치를 결정합니다.

    머티리얼의 셰이더 메뉴에 있는 셰이더 위치

    프로퍼티 블록

    프로퍼티 블록에는 사용자가 머티리얼의 인스펙터 창에서 설정할 수 있는 프로퍼티의 선언이 포함되어 있습니다.

    이 예제의 프로퍼티 블록은 비어 있는데, 이는 Unity 셰이더가 사용자가 정의할 수 있는 Material 프로퍼티를 노출하지 않기 때문입니다.

    서브셰이더 블록

    Unity 셰이더 소스 파일에는 하나 이상의 서브셰이더 블록이 포함되어 있습니다. 메시를 렌더링할 때 Unity는 타겟 디바이스의 GPU와 호환되는 첫 번째 서브셰이더를 선택합니다.

    서브셰이더 블록은 선택적으로 서브셰이더 태그 블록을 포함할 수 있습니다. 서브셰이더 태그 블록을 선언하려면 Tags 키워드를 사용하십시오.

    Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
    

    이름이 RenderPipeline인 서브셰이더 태그는 이 서브셰이더를 사용할 렌더 파이프라인을 Unity에 알려 주며, UniversalRenderPipeline 값은 Unity가 이 서브셰이더를 URP에 사용해야 함을 나타냅니다.

    서브셰이더 태그에 대한 자세한 내용은 ShaderLab: 서브셰이더 태그를 참조하십시오.

    패스 블록

    이 예제에는 HLSL 프로그램 코드를 포함하는 하나의 패스 블록이 있습니다. 패스 블록에 대한 자세한 내용은 ShaderLab: 패스를 참조하십시오.

    HLSLPROGRAM 블록

    이 블록에는 HLSL 프로그램 코드가 포함되어 있습니다.

    참고: URP 셰이더는 HLSL 언어만 지원합니다.

    이 블록에는 Core.hlsl 파일을 참조하는 #include 선언이 포함되어 있습니다.

    # include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    

    Core.hlsl 파일에는 HLSL 매크로와 함수에서 자주 사용되는 정의뿐만 아니라 다른 HLSL 파일에 대한 레퍼런스(예: Common.hlsl 및 SpaceTransforms.hlsl)도 포함되어 있습니다.

    예를 들어 HLSL 코드의 버텍스 셰이더는 SpaceTransforms.hlsl 파일의 TransformObjectToHClip 함수를 사용합니다. 이 함수는 오브젝트 공간의 버텍스 포지션을 균일한 공간으로 변환합니다.

    Varyings vert(Attributes IN)
    {
        Varyings OUT;
        OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
        return OUT;
    }
    

    이 기본 HLSL 코드의 프래그먼트 셰이더는 코드에 사전 정의된 단일 컬러를 출력합니다.

    half4 frag() : SV_Target
    {
        half4 customColor;
        customColor = half4(0.5, 0, 0, 1);
        return customColor;
    }
    

    컬러 입력을 제공하는 URP 언릿 셰이더 섹션에서는 머티리얼의 인스펙터 창에 편집 가능한 컬러 프로퍼티를 추가하는 방법을 설명합니다.

    문서 개요
    맨 위로
    Copyright © 2023 Unity Technologies — 상표 및 이용약관
    • 법률정보
    • 개인정보처리방침
    • 쿠키
    • 내 개인정보 판매 금지
    • Your Privacy Choices (Cookie Settings)