개념
Built-in 즉 내장된 렌더링 파이프라인이라 신규 렌더링 파이프라인인 URP랑은 별개임 따라서 URP 환경에서 Built-in 셰이더 사용 시 마젠타로 변함.
URP는 주된 파일들이 필수다 HLSLSupport.hlsl, CoreRP.hlsl 그리고 Lighting.hlsl
주요 컴포넌트들도 명칭도 구현 방법도 다르다.
주요 차이점
- CGPROGRAM 대신 HLSLPROGRAM 사용함
- 셰이더 변수들 fixed4는 half4로 대체됨
- Built-in 기본 함수들은 URP에서도 기능이 같은게 존재함, 예로) UnityObjectToClipPos()를 TransformObjectToClip()
- URP는 SRP Batcher 내에 있는 CBUFFER 구조를 따름
- TEXTURE2D와 SAMPLER 메크로를 사용함
코드 (스킬 쿨타임 UI)
Built-in
Shader "UI/RadialCooldown"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_FillAmount ("Fill Amount", Range(0, 1)) = 1
}
SubShader
{
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float _FillAmount;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// Calculate angle from center
float2 center = float2(0.5, 0.5);
float2 dir = i.uv - center;
float angle = atan2(dir.y, dir.x);
// Normalize to 0-1, starting from top
float normalized = frac((angle / (3.14159 * 2.0)) + 0.75);
// Sample texture
fixed4 col = tex2D(_MainTex, i.uv);
// Apply radial mask
if (normalized > _FillAmount)
col.a = 0.3; // Semi-transparent for cooldown area
return col;
}
ENDCG
}
}
}
URP
Shader "UI/RadialCooldown_URP"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_FillAmount ("Fill Amount", Range(0, 1)) = 1
}
SubShader
{
Tags
{
"Queue"="Transparent"
"RenderType"="Transparent"
"RenderPipeline"="UniversalPipeline"
}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Cull Off
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
float2 uv : TEXCOORD0;
};
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
CBUFFER_START(UnityPerMaterial)
float4 _MainTex_ST;
float _FillAmount;
CBUFFER_END
Varyings vert(Attributes IN)
{
Varyings OUT;
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.uv = TRANSFORM_TEX(IN.uv, _MainTex);
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
// Calculate angle from center
float2 center = float2(0.5, 0.5);
float2 dir = IN.uv - center;
float angle = atan2(dir.y, dir.x);
// Normalize to 0-1, starting from top (12 o'clock)
float normalized = frac((angle / (PI * 2.0)) + 0.75);
// Sample texture
half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uv);
// Apply radial mask
if (normalized > _FillAmount)
{
col.a *= 0.3; // Darken cooldown area
}
return col;
}
ENDHLSL
}
}
}'게임엔진 > Unity' 카테고리의 다른 글
| [Unity] fps 로그창 GUI (0) | 2025.12.13 |
|---|---|
| [Unity] ServiceLocatorManager > 구조 변경 / indexer, Type (0) | 2025.11.30 |
| [Unity] 애니메이션 마지막 프레임에서 이벤트 호출안되는 이유 (0) | 2025.11.23 |
| [Unity] 로그 (Log) 출력시 스택 트레이스 (Stack Trace) 관리하기 (0) | 2025.10.07 |
| [Unity] PlayerInput을 활용한 캐릭터 움직이는 방법 (0) | 2025.08.04 |