Shader "Custom/05/Fire" { Properties { _MainTex ("Albedo (RGB)", 2D) = "white" {} _MainTex2("Albedo (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } LOD 200 CGPROGRAM #pragma surface surf Standard alpha:fade sampler2D _MainTex; sampler2D _MainTex2; struct Input { float2 uv_MainTex; float2 uv_MainTex2; }; void surf (Input IN, inout SurfaceOutput..
Unity/Unity_Shader
유니티 내부의 _Time을 이용하여 UV 변경해보기 _Time : float4형 변수로 씬이 열린 다음으로부터의 시간 float4인 이유 _Time.x = 1/20 속도, _Time.y = 원래 시간 속도 _Time.z = 2배 시간 속도 _Time.w = 3배 시간 속도 _Time 이외에도 _SinTime, _CosTime, unity_DeltaTime 등의 시간 변수가 있다. fixed4 c = tex2D (_MainTex, IN.uv_MainTex + _Time.y); Always Refresh를 체크하면 에디터내에서 플레이 하지 않아도 이미지가 시간에 따라 변경되는 걸 볼 수 있다. fixed4 c = tex2D (_MainTex, float2(IN.uv_MainTex.x + _Time.y, IN..
void surf (Input IN, inout SurfaceOutputStandard o) { // Albedo comes from a texture tinted by color fixed4 c = tex2D (_MainTex, IN.uv_MainTex + 0.5); o.Emission = c.rgb; o.Alpha = c.a; } 이는 텍스쳐의 WrapMode 옵션이 Repeat상태이기에 UV가 1이 넘는 값이 입력되면 0부터 다시 연결되도록 만들어지게 된다. WarpMode의 값 Repeat : 1이 넘는 값이 입력되면 0부터 다시 시작한다. 반대로 0 미만의 값이 들어가면 1부터 다시 시작한다. Clamp : 1이 넘는 값이 입력되면 1로 만든다. 반대로 0 미만의 값이 들어가면 1부터 다시 시작..
UV맵이란? 텍스쳐링을 위한 3D 모델의 표면 UV는 2차원 좌표값으로 float2로 이루어진 숫자이며, (0~1)까지 표현할 수 있는 정규화된 좌표값이라고 볼 수 있다. 유니티는 좌측 하단이 (0, 0) 이며 우측 상단이 (1, 1) 이다. (언리얼은 좌측 상단이 (0, 0) 이며 우측 하단이 (1, 1) 이다.) UV는 float2로 이루어진 좌표값이기 때문에 XY로 변환이 가능하고 또한 RG(색상)으로도 변환이 가능하다. struct Input { float2 uv_MainTex; }; 유니티 내부로부터 받는 데이터는 Input 구조체 안에 선언해야 한다. fixed4 c = tex2D (_MainTex, IN.uv_MainTex); => IN.uv_MainTex.x 가 U => IN.uv_Main..
Lerp : 선형 보간 형식 lerp(X, Y, s) Shader "Custom/texShader" { Properties { _MainTex ("Albedo (RGB)", 2D) = "white" {} _MainTex2 ("Albedo (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } CGPROGRAM #pragma surface surf Standard fullforwardshadows sampler2D _MainTex; sampler2D _MainTex2; struct Input { float2 uv_MainTex; float2 uv_MainTex2; }; UNITY_INSTANCING_BUFFER_START(Props) U..
흑백으로 만드는 코드 Shader "Custom/texShader" { Properties { _MainTex ("Albedo (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } CGPROGRAM #pragma surface surf Standard fullforwardshadows sampler2D _MainTex; struct Input { float2 uv_MainTex; }; UNITY_INSTANCING_BUFFER_START(Props) UNITY_INSTANCING_BUFFER_END(Props) void surf (Input IN, inout SurfaceOutputStandard o) { fixed4 c = tex2..
텍스처 출력 부분을 제외한 코드 삭제 Shader "Custom/texShader" { Properties { _MainTex ("Albedo (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } CGPROGRAM #pragma surface surf Standard fullforwardshadows sampler2D _MainTex; struct Input { float2 uv_MainTex; }; UNITY_INSTANCING_BUFFER_START(Props) UNITY_INSTANCING_BUFFER_END(Props) void surf (Input IN, inout SurfaceOutputStandard o) { fixed4..
프로퍼티 선언 _BrightDark("Brightness $ Darkness", Range(-1,1)) = 0 -1 부터인 이유는 어둡게 하기 위해서 쉐이더 변수 선언 float _BrightDark; 쉐이더 함수내 선언 o.Albedo = _TestColor. + _BrightDark;
기본 형식 데이터타입 변수명; float4.rgb => float3 형태로 변환 float4 test = float4(1, 0, 0, 1); o.Albedo = test.rgb; float4 test = float4(1, 0, 0, 1); o.Albedo = test.gbr; 외부 입력값 출력 _TestColor("testColor",Color) = (1,1,1,1) = 프로퍼티에 신규 값 설정 float4 _TestColor; = 쉐이더 언어 내부에 선언(쉐이더 언어 내부 : CGPROGRAM ~ ENDCG) o.Albedo = _TestColor.gbr; = 쉐이더 언어 함수 영역에 선언
함수의 구조 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 = c.rgb; // Metallic and smoothness come from slider variables o.Metallic = _Metallic; o.Smoothness = _Glossiness; o.Alpha = c.a; } 형식 이름 (입력값) { ... } 상수로 색상 변경 void surf(Input IN, inout SurfaceOutputStandard o) { //..
방금 만든 쉐이더 코드 (만든 쉐이더를 더블클릭하면 볼 수 있다.) Shader "Custom/NewSurfaceShader" { 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 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #..