엔비디아 사이트
floor : 내림 ( 0.1 -> 0, 0.9999 -> 0 )
frac : 소수 에서 자연수 제거 ( 12.34 -> 0.34 )
clip : frag 함수에서 value 가 음이면 즉각 랜더링 중지
reflect : view 와 normal을 이용해서 리플렉션 벡터를 구한다.
saturate : Returns x saturated to the range [0,1] as follows:
1) Returns 0 if x is less than 0; else
2) Returns 1 if x is greater than 1; else
3) Returns x otherwise.
any :
- 사용 방법( floor, frac, clip )
screenPos.xy = floor(screenPos.xy * 0.25) * 0.5;
//스크린 좌표를 정수로 만들고 인위적으로 끝이 .0 이나 .5로 끝나게 함
float checker = -frac(screenPos.x + screenPos.y);
//소수점 수치가 있다면 랜더링 중지
clip(checker);
- 사용 방법( reflect )
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f
{
half3 worldRefl : NORMAL;
fixed4 pos : SV_POSITION;
};
v2f vert(float4 vertex : POSITION, float3 normal : NORMAL)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, vertex);
// compute world space position of the vertex
float3 worldPos = mul(_Object2World, vertex).xyz;
// compute world space view direction
float3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPos));
// world space normal
float3 worldNormal = UnityObjectToWorldNormal(normal);
// world space reflection vector
o.worldRefl = reflect(-worldViewDir, worldNormal);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
// sample the default reflection cubemap, using the reflection vector
half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
// decode cubemap data into actual color
half3 skyColor = DecodeHDR(skyData, unity_SpecCube0_HDR);
// output it!
fixed4 c = 0;
c.rgb = skyColor;
return c;
}
ENDCG
}
- 사용 방법( saturate )
half4 frag( v2f i ) : SV_Target
{
half4 c = frac( i.uv );
if (any(saturate(i.uv) - i.uv))
c.b = 0.5;
return c;
}
=================================================================================
5. 유니티 내장
#include "UnityCG.cginc"
- 함수
UnityWorldSpaceViewDir(worldPos) : 월드 포지션으로 뷰 벡터를 구한다.
UnityObjectToWorldNormal(i.normal) : 노말을 월드 노말로
UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl) : 디폴트 리플렉션 큐브맵을 뽑는다.
half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
- 변수
UNITY_MATRIX_MVP : vertex와 곱하면 스크린 스페이스의 포지션이 나오나 보다
_Object2World : vertex와 곱하면 월드 스페이스의 포지션이 나온다.
unity_SpecCube0 :
unity_SpecCube0_HDR
댓글 없음:
댓글 쓰기