TA/Unity2013. 6. 20. 10:59

유니티 라이트 프로브 셰이더 예제

 

 

 

 

플레그먼트

 

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"

}

 

 

 

'TA > Unity' 카테고리의 다른 글

iTween Path collider 충돌시 멈추기  (0) 2013.06.21
ITween Example Tutorial  (0) 2013.06.21
TD CameraControl C#  (0) 2013.05.09
유니티 C# 공부 모음  (0) 2013.05.07
Texture Matrix in Fixed Function  (0) 2012.07.18
Posted by 프리랜서 디자이너