Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 3개 있습니다.)

Unity - LightMode의 ForwardBase에 따른 _WorldSpaceLightPos0 값 변화

_WorldSpaceLightPos0 내장 변수를 사용한 지난 글들을 실습해 보면,

Unity로 실습하는 Shader (2) - 고로 셰이딩(gouraud shading) + 퐁 모델(Phong model)
; https://www.sysnet.pe.kr/2/0/11609

Unity로 실습하는 Shader (3) - 고로 셰이딩(gouraud shading) + 퐁 모델(Phong model) + Texture
; https://www.sysnet.pe.kr/2/0/11610

Unity로 실습하는 Shader (4) - 퐁 셰이딩(phong shading)
; https://www.sysnet.pe.kr/2/0/11611

이상한 현상이 하나 눈에 띕니다. 바로 다음과 같이 색상의 반전이 일어나는 것입니다.

[그림: 앞에서 2개는 고로 셰이딩, 제일 뒤에 있는 6면체는 unity 기본 셰이딩 적용]
unity_light_pos_0.png

위에서 볼 수 있는 것처럼, (Game 뷰 화면에서) Unity 기본 셰이딩은 정상적으로 조명값이 적용되었지만 제가 만든 shader를 적용한 앞의 2개는 조명이 반전되었습니다. 도대체 왜 이런 것인지, shader 소스 코드를 천천히 들여다봤지만 이런 현상에 대한 변수라고는 _WorldSpaceLightPos0 밖에는 없다는 판단이 들었습니다. 그래서 그 값을 확인하기 위해 다음과 같이 (디버깅을 위해) 설정하고,

v2f vert (appdata v)
{
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.illumination = _WorldSpaceLightPos0;

    return o;
}
			
fixed4 frag (v2f i) : SV_Target
{
    fixed4 col = _Color * i.illumination;
    return col;
}

실행 후 다음과 같은 결과를 얻었습니다.

unity_light_pos_1.png

Unity Scene 뷰와 Game 뷰의 출력이 다릅니다. 재미있는 것은, 이 상태에서 Unity 기본 shader를 적용한 물체를 가까이 끌어오면,

unity_light_pos_2.png

위와 같이 제가 만든 shader를 적용한 물체의 색상이 정상적으로 바뀌었습니다. 당연히 다른 객체에도 가까이 가져왔더니,

unity_light_pos_3.png

보는 바와 같이 정상적으로 _WorldSpaceLightPos0 값이 적용되었습니다. 테스트를 몇 번 하다 보면, Unity shader가 적용된 객체가 (화면에 보여야 하고) 제가 만든 shader의 객체보다 z-축 기준으로 카메라 방향으로 앞에 있게 되면 _WorldSpaceLightPos0가 정상적인 값을 반환한다는 것을 알 수 있습니다.

현상은 일단 그렇고, 이런 문제를 해결하려면 LightMode의 값을 "ForwardBase"로 해야 합니다.

SubShader
{
    Pass
    {
        Tags{ "LightMode" = "ForwardBase" }

        // ...[생략]...
    }
}

Unity 문서와,

ShaderLab: Pass Tags
; https://docs.unity3d.com/Manual/SL-PassTags.html

ForwardBase: Used in Forward rendering, ambient, main directional light, vertex/SH lights and lightmaps


다음의 shader에 있는 주석을 종합해 봤을 때,

psicomante/gouraud.shader 
; https://gist.github.com/psicomante/2109b947a681804f8ba5625238895a2a#file-gouraud-shader-L70

// indicate that our pass is the "base" pass in forward
// rendering pipeline. It gets ambient and main directional
// light data set up; light direction in _WorldSpaceLightPos0
// and color in _LightColor0


_WorldSpaceLightPos0와 _LightColor0 값은 저 모드로 설정된 shader에 한해 정상적인 값을 보장받을 수 있는 것 같습니다. 그나저나 "Forward rendering"이 뭔지 검색해 보면,

[Kgc2012] deferred forward 이창희 
; https://www.slideshare.net/cagetu/kgc2012-deferred-forward

forward rendering이란, 전통적인 렌더링 파이프라인을 통해서 shading되는 방식을 말한다

- Vertex Generation
- Vertex Processing
- Primitive Generation
- Primitive Processing
- Rasterization (Fragment Generation)
- Fragment Processing
- Frame-Buffer Ops
- Frame Buffer


라고 합니다. ^^ 제가 더 이상 comment할 만한 내용의 것이 아닌 듯합니다.

참고로, 테스트 삼아 "ShaderLab: Pass Tags" 문서에 있는 가능한 Mode 들에 대해 테스트해보니, ForwardBase 이외의 모든 값은 정상적인 동작을 하지 않았습니다. 가령, 다음의 2개는 이 글에서 설명한 것과 동일한 현상을 발생시켰고,

  • Always
  • Vertex

다음의 모드들은 아예 객체를 화면에서 사라지게 만들었습니다.

  • ForwardAdd
  • Deferred
  • MotionVectors
  • PrepassBase
  • PrepassFinal
  • VertexLMRGBM
  • VertexLM

암튼... 모르는 저 너머의 것들이 너무나 많군요. ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 8/3/2018]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 31  32  33  34  [35]  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12744정성태7/30/20217227개발 환경 구성: 586. Azure Active Directory에 연결된 App 목록을 확인하는 방법?
12743정성태7/30/20217914.NET Framework: 1083. Azure Active Directory - 외부 Token Cache 저장소를 사용하는 방법파일 다운로드1
12742정성태7/30/20217215개발 환경 구성: 585. Azure AD 인증을 위한 사용자 인증 유형
12741정성태7/29/20218367.NET Framework: 1082. Azure Active Directory - Microsoft Graph API 호출 방법파일 다운로드1
12740정성태7/29/20217058오류 유형: 747. SharePoint - InvalidOperationException 0x80131509
12739정성태7/28/20217020오류 유형: 746. Azure Active Directory - IDW10106: The 'ClientId' option must be provided.
12738정성태7/28/20217594오류 유형: 745. Azure Active Directory - Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI).
12737정성태7/28/20216562오류 유형: 744. Azure Active Directory - The resource principal named api://...[client_id]... was not found in the tenant
12736정성태7/28/20217048오류 유형: 743. Active Azure Directory에서 "API permissions"의 권한 설정이 "Not granted for ..."로 나오는 문제
12735정성태7/27/20217555.NET Framework: 1081. C# - Azure AD 인증을 지원하는 데스크톱 애플리케이션 예제(Windows Forms) [2]파일 다운로드1
12734정성태7/26/202123514스크립트: 20. 특정 단어로 시작하거나/끝나는 문자열을 포함/제외하는 정규 표현식 - Look-around
12733정성태7/23/202110921.NET Framework: 1081. Self-Contained/SingleFile 유형의 .NET Core/5+ 실행 파일을 임베딩한다면? [1]파일 다운로드2
12732정성태7/23/20216228오류 유형: 742. SharePoint - The super user account utilized by the cache is not configured.
12731정성태7/23/20217329개발 환경 구성: 584. Add Internal URLs 화면에서 "Save" 버튼이 비활성화 된 경우
12730정성태7/23/20218862개발 환경 구성: 583. Visual Studio Code - Go 코드에서 입력을 받는 경우
12729정성태7/22/20217853.NET Framework: 1080. xUnit 단위 테스트에 메서드/클래스 수준의 문맥 제공 - Fixture
12728정성태7/22/20217331.NET Framework: 1079. MSTestv2 단위 테스트에 메서드/클래스/어셈블리 수준의 문맥 제공
12727정성태7/21/20218273.NET Framework: 1078. C# 단위 테스트 - MSTestv2/NUnit의 Assert.Inconclusive 사용법(?) [1]
12726정성태7/21/20218101VS.NET IDE: 169. 비주얼 스튜디오 - 단위 테스트 선택 시 MSTestv2 외의 xUnit, NUnit 사용법 [1]
12725정성태7/21/20216877오류 유형: 741. Failed to find the "go" binary in either GOROOT() or PATH
12724정성태7/21/20219519개발 환경 구성: 582. 윈도우 환경에서 Visual Studio Code + Go (Zip) 개발 환경 [1]
12723정성태7/21/20217154오류 유형: 740. SharePoint - Alternate access mappings have not been configured 경고
12722정성태7/20/20217014오류 유형: 739. MSVCR110.dll이 없어 exe 실행이 안 되는 경우
12721정성태7/20/20217636오류 유형: 738. The trust relationship between this workstation and the primary domain failed. - 세 번째 이야기
12720정성태7/19/20216970Linux: 43. .NET Core/5+ 응용 프로그램의 Ubuntu (Debian) 패키지 준비
12719정성태7/19/20216128오류 유형: 737. SharePoint 설치 시 "0x800710D8 The object identifier does not represent a valid object." 오류 발생
... 31  32  33  34  [35]  36  37  38  39  40  41  42  43  44  45  ...