{!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} 노멀 벡터 시각화 | Universal RP | 8.2.0
docs.unity3d.com
"{0}"의 검색 결과

    목차 표시/숨기기

    노멀 벡터 시각화

    이 예제의 Unity 셰이더는 메시의 노멀 벡터 값을 시각화합니다.

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

    1. 이 예제의 버텍스 셰이더에 대한 입력 구조인 struct Attributes에서 각 버텍스의 노멀 벡터가 포함되어 있는 변수를 선언합니다.

      struct Attributes
      {
          float4 positionOS   : POSITION;
          // Declaring the variable containing the normal vector for each vertex.
          half3 normal        : NORMAL;
      };
      
    2. 이 예제의 프래그먼트 셰이더에 대한 입력 구조인 struct Varyings에서 각 프래그먼트의 노멀 벡터 값을 저장하기 위한 변수를 선언합니다.

      struct Varyings
      {
          float4 positionHCS  : SV_POSITION;
          // The variable for storing the normal vector values.
          half3 normal        : TEXCOORD0;
      };
      

      이 예제는 각 프래그먼트의 RGB 컬러 값으로 노멀 벡터의 세 가지 컴포넌트를 사용합니다.

    3. 메시의 노멀 벡터 값을 렌더링하기 위해 다음 코드를 프래그먼트 셰이더로 사용합니다.

      half4 frag(Varyings IN) : SV_Target
      {                
          half4 color = 0;
          color.rgb = IN.normal;
          return color;
      }
      
    4. Unity가 메시의 노멀 벡터 값을 렌더링합니다.

      압축 없이 노멀을 렌더링

      캡슐의 일부가 검게 보이는데, 이는 해당 포인트에서 노멀 벡터 컴포넌트의 세 가지 컴포넌트가 모두 음수이기 때문입니다. 다음 단계에서 이 영역의 값을 렌더링하는 방법도 보여드리겠습니다.

    5. 음수 노멀 벡터 컴포넌트를 렌더링하려면 압축 기술을 사용합니다. 노멀 컴포넌트 값 (-1..1) 범위를 컬러 값 범위 (0..1)로 압축하려면 다음 줄을 변경합니다.

      color.rgb = IN.normal;
      

      위 줄을 아래 줄로 변경하십시오.

      color.rgb = IN.normal * 0.5 + 0.5;
      

    이제 Unity가 메시에서 노멀 벡터 값을 컬러로 렌더링합니다.

    압축을 사용하여 노멀을 렌더링

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

    // This shader visuzlizes the normal vector values on the mesh.
    Shader "Example/URPUnlitShaderNormal"
    {    
        Properties
        { }
        
        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;
                    // Declaring the variable containing the normal vector for each
                    // vertex.
                    half3 normal        : NORMAL;
                };
    
                struct Varyings
                {
                    float4 positionHCS  : SV_POSITION;
                    half3 normal        : TEXCOORD0;
                };                                   
                
                Varyings vert(Attributes IN)
                {                
                    Varyings OUT;                
                    OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);       
                    // Use the TransformObjectToWorldNormal function to transform the
                    // normals from object to world space. This function is from the 
                    // SpaceTransforms.hlsl file, which is referenced in Core.hlsl.
                    OUT.normal = TransformObjectToWorldNormal(IN.normal);                
                    return OUT;
                }
    
                half4 frag(Varyings IN) : SV_Target
                {                
                    half4 color = 0;
                    // IN.normal is a 3D vector. Each vector component has the range
                    // -1..1. To show all vector elements as color, including the
                    // negative values, compress each value into the range 0..1.
                    color.rgb = IN.normal * 0.5 + 0.5;                
                    return color;
                }
                ENDHLSL
            }
        }
    }
    
    문서 개요
    맨 위로
    Copyright © 2023 Unity Technologies — 상표 및 이용약관
    • 법률정보
    • 개인정보처리방침
    • 쿠키
    • 내 개인정보 판매 금지
    • Your Privacy Choices (Cookie Settings)