{!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 언릿 셰이더

    이 예제에서 Unity 셰이더는 머티리얼에 Base Color 프로퍼티를 추가합니다. 해당 프로퍼티를 사용하여 컬러를 선택하면, 셰이더가 메시 모양을 해당 컬러로 채웁니다.

    URP 언릿 기본 셰이더 섹션의 Unity 셰이더 소스 파일을 사용하고 ShaderLab 코드에 다음 변경 사항을 적용하십시오.

    1. 프로퍼티 블록에 _BaseColor 프로퍼티 정의를 추가합니다.

      Properties
      { 
          _BaseColor("Base Color", Color) = (1, 1, 1, 1)
      }
      

      이 선언은 Base Color 레이블이 있는 _BaseColor 프로퍼티를 머티리얼에 추가합니다.

      머티리얼의 기본 컬러 프로퍼티

      _BaseColor 프로퍼티 이름은 예약된 이름입니다. 이 이름으로 프로퍼티를 선언하면 Unity는 이 프로퍼티를 머티리얼의 메인 컬러로 사용합니다.

    2. 프로퍼티 블록에서 프로퍼티를 선언할 경우 HLSL 코드에서도 선언해야 합니다.

      참고: Unity 셰이더가 SRP 배처와 호환되려면 이름이 UnityPerMaterial인 단일 CBUFFER 블록 내에 모든 Material 프로퍼티를 선언해야 합니다. SRP 배처에 대한 자세한 내용은 스크립터블 렌더 파이프라인(SRP) 배처 페이지를 참조하십시오.

      버텍스 셰이더 앞에 다음 코드를 추가하십시오.

      CBUFFER_START(UnityPerMaterial)
          half4 _BaseColor;            
      CBUFFER_END
      
    3. 프래그먼트 셰이더의 코드를 변경하여 _BaseColor 프로퍼티를 반환하도록 만듭니다.

      half4 frag() : SV_Target
      {
          return _BaseColor;
      }
      

    이제 인스펙터 창의 Base Color 필드에서 컬러를 선택할 수 있습니다. 프래그먼트 셰이더가 선택된 컬러로 메시를 채웁니다.

    머티리얼의 Base Color 필드

    아래는 이 예제의 완전한 ShaderLab 코드입니다.

    // This shader fills the mesh shape with a color that a user can change using the
    // Inspector window on a Material.
    Shader "Example/URPUnlitShaderColor"
    {    
        // The _BaseColor variable is visible in the Material's Inspector, as a field 
        // called Base Color. You can use it to select a custom color. This variable
        // has the default value (1, 1, 1, 1).
        Properties
        { 
            _BaseColor("Base Color", Color) = (1, 1, 1, 1)
        }
        
        SubShader
        {        
            Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
                    
            Pass
            {            
                HLSLPROGRAM
                #pragma vertex vert
                #pragma fragment frag
    
                #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"            
                
                struct Attributes
                {
                    float4 positionOS   : POSITION;                 
                };
    
                struct Varyings
                {
                    float4 positionHCS  : SV_POSITION;
                };
    
                // To make the Unity shader SRP Batcher compatible, declare all
                // properties related to a Material in a a single CBUFFER block with 
                // the name UnityPerMaterial.
                CBUFFER_START(UnityPerMaterial)
                    // The following line declares the _BaseColor variable, so that you
                    // can use it in the fragment shader.
                    half4 _BaseColor;            
                CBUFFER_END
    
                Varyings vert(Attributes IN)
                {
                    Varyings OUT;
                    OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
                    return OUT;
                }
    
                half4 frag() : SV_Target
                {
                    // Returning the _BaseColor value.                
                    return _BaseColor;
                }
                ENDHLSL
            }
        }
    }
    

    텍스처 그리기 섹션에서는 메시에 텍스처를 그리는 방법을 설명합니다.

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