오오 서피스로 이런것도 되는구낭..
유니티 라이트 프로브 셰이더 예제
플레그먼트
Shader "Probes" {
Properties {
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_SHLightingScale("LightProbe influence scale",float) = 1
}
SubShader {
Tags { "RenderType"="Opaque" "LightMode"="ForwardBase"}
LOD 100
CGINCLUDE
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
float _SHLightingScale;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
fixed3 spec : TEXCOORD1;
fixed3 SHLighting: TEXCOORD2;
};
v2f vert (appdata_full v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord;
float3 worldNormal = mul((float3x3)_Object2World, v.normal);
float3 shl = ShadeSH9(float4(worldNormal,1));
o.SHLighting = shl * _SHLightingScale;
return o;
}
ENDCG
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
fixed4 frag (v2f i) : COLOR
{
fixed4 c = tex2D (_MainTex, i.uv);
c.rgb *= i.SHLighting;
return c;
}
ENDCG
}
}
}
서피스
Shader "Custom/ModifyLightProbes" {
Properties { _Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Amount ("SH scale", Float) = 1
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert noambient vertex:vert
#pragma debug
sampler2D _MainTex;
fixed4 _Color;
float _Amount;
struct Input {
float2 uv_MainTex;
float3 shLight;
};
void vert (inout appdata_full v, out Input o) {
// evaluate SH light
float3 worldN = mul ((float3x3)_Object2World, SCALED_NORMAL);
o.shLight = ShadeSH9 (float4 (worldN, 1.0));
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
// modify the SH lighting anyway you want,
// here's just simple scaling
float3 shLight = _Amount * IN.shLight;
// emission is just added to the final color,
// so SH light needs to be multiplied by albedo
o.Emission = o.Albedo * shLight;
}
ENDCG
}
FallBack "Diffuse"
}
'Shader ' 카테고리의 다른 글
Surface shader 로 vertexlit 전용 shader나 SH Light 전용 shader를 만들 수 있는가? (1) | 2014.05.13 |
---|---|
Unity surface shader 에서 No light 모드 만들기 (0) | 2014.05.13 |
유니티 물 쉐이더 강의용 예제 (0) | 2014.04.10 |
스터디용 Normal Map 예습 (0) | 2014.02.02 |
Unity shader Queue (0) | 2014.01.27 |
댓글