본문 바로가기

셰이더 (Shader)89

[Unity/Shader] 파트8-2 : Metalic과 Smoothness 기본 코드에서 Metallic과 Smoothness가 어떤 역할을 하는지 설명한다. 코드 Shader "Custom/part8-2" { Properties { _MainTex ("Albedo (RGB)", 2D) = "white" {} _Metallic ("Metalic", Range(0,1)) = 0 _Smoothness("Smoothness", Range(0,1)) = 0.5 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma surface surf Standard fullforw.. 2023. 8. 7.
[Unity/Shader] 파트5-2 : 텍스쳐 입출력 해석 텍스쳐 받아서 그대로 출력하는 쉐이더이다. 추가된 코드는 없다. 단지 해석할 뿐이다. 코드 Shader "Custom/part5-2" { Properties { _MainTex ("Albedo (RGB)", 2D) = "white" {} // 2D 텍스쳐를 받는다. 기본값은 흰색 텍스쳐이다. } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma surface surf Standard fullforwardshadows // Use shader model 3.0 target, to get .. 2023. 8. 7.
[Unity/Shader] 파트5-1 : 코드 정리 기본 (불필요 코드 삭제2) 앞으로의 내용에서, 기본 시작 코드가 된다. 텍스쳐 한장 받는 것 외에는 모두 지운다. 코드 Shader "Custom/chap06" { Properties { _MainTex ("Albedo (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } CGPROGRAM #pragma surface surf Standard fullforwardshadows sampler2D _MainTex; struct Input { float2 uv_MainTex; }; // GPU 인스턴싱 기능 관련. 유니티 5.6부터 추가되었다. (삭제 가능) UNITY_INSTANCING_BUFFER_START(Props) // put more per-instanc.. 2023. 8. 6.
[Unity/Shader] 파트4-7 : 불필요 코드 삭제 불필요한 프로퍼티, 코드를 삭제하여 깔끔하게 만든다. 코드 Shader "Custom/chap05" { Properties { _TestColor ("testcolor", Color) = (1,1,1,1) } SubShader { Tags { "RenderType"="Opaque" } LOD 200 // 옵션 값 (삭제 가능) CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma surface surf Standard fullforwardshadows // Use shader model 3.0 target, to get nicer looking lighting #pragma ta.. 2023. 8. 6.
[Unity/Shader] 파트4-6 : 외부의 입력값 출력 (프로퍼티로 색 지정) 프로퍼티를 만들고, 색을 받아 적용하는 것을 실습한다. 코드 Shader "Custom/chap05" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _Glossiness ("Smoothness", Range(0,1)) = 0.5 _Metallic ("Metallic", Range(0,1)) = 0.0 _TestColor ("testcolor", Color) = (1,1,1,1) // 1. 프로퍼티 추가 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM // Physically based Standard lighting mo.. 2023. 8. 6.
[Unity/Shader] 파트4-5 : 변수 이용 변수 사용 기초를 다룬다. 스위즐링하는 법을 배운다. 코드 void surf (Input IN, inout SurfaceOutputStandard o) { float4 test = float4(1,0,0,1); fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; o.Albedo = test.rgb; o.Albedo = test.grb; o.Alpha = c.a; } test 변수의 사용과 o.Albedo 부분만 보면 된다. 2023. 8. 6.
[Unity/Shader] 파트4-4 : 색상 출력 빨간색 구를 출력해본다. Albedo는 빛의 영향을 받는다. Emission은 빛의 영향을 받지 않는다. 코드 void surf (Input IN, inout SurfaceOutputStandard o) { // Albedo comes from a texture tinted by color fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; //o.Albedo = float3(1,0,0); o.Emission = float3(1,0,0); o.Alpha = c.a; } 소수점 정밀도 float > half > fixed half는 float의 반 크기이다. fixed는 그보다 더 작다. float으로 사용 후, 최적화 작업시 줄여나가도 된다. 2023. 8. 6.
[Unity/Shader] 파트4-3 : 쉐이더 Properties 제작 설명 쉐이더를 생성한다. 머티리얼을 생성한다. 머티리얼에 쉐이더를 적용한다. 오브젝트에 머티리얼을 적용한다. 쉐이더를 더블클릭하여 아래와 같이 작성한다. 쉐이더에 프로퍼티가 생성된다. 2023. 8. 3.
[Unity/Shader] 실습 전 세팅 Gamma Correction 설명 모니터는 어두운 영역에 집중되어 출력되도록 세팅돼있다. 그래서 컴퓨터는 이미지를 더 밝게 저장한다. 따라서 연산 전, 이미지를 원래처럼 어둡힌 후 연산한다. 연산이 끝나면 다시 밝게 되돌린다. 이 과정을 리니어 워크플로우라고 한다. 리니어 워크플로우 세팅법 책에서는 리니어 워크플로우 상태로 설명한다. 따라서 다음과 같은 세팅을 해준다. Edit > Project Settings 클릭 > 아래 그림 참고 2023. 8. 3.