애니메이터

Unity5.x 에서 Unity4.x 라이트맵 쓰기 3탄 본문

Game Engine/Unity3D

Unity5.x 에서 Unity4.x 라이트맵 쓰기 3탄

욤마핫 2019. 11. 29. 13:53

연산량을 줄이기 위해서 b채널만 연산에 넣었다.

 

Shader "Shader Forge/Unlit_Lightmapped4_House" {
Properties{
        _Tint("Tint", Color) = (1,1,1,1)
        _Main("Main", 2D) = "white" {}
        _Lightmap("Lightmap", 2D) = "white" {}
}


SubShader{
        Tags{ "RenderType" = "Opaque" }
        Pass{ Name "FORWARD"
        Tags{ "LightMode" = "ForwardBase" }


CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDBASE
#include "UnityCG.cginc"


//#pragma multi_compile_fwdbase
//#pragma only_renderers d3d9 d3d11 glcore gles metal
#pragma target 3.0
uniform fixed4 _Tint;
uniform sampler2D _Main; uniform fixed4 _Main_ST;
uniform sampler2D _Lightmap; uniform fixed4 _Lightmap_ST;


struct VertexInput {
        float4 vertex : POSITION;
        float2 texcoord0 : TEXCOORD0;
        float2 texcoord1 : TEXCOORD1;
};


struct VertexOutput {
        float4 pos : SV_POSITION;
        float2 uv0 : TEXCOORD0;
        float2 uv1 : TEXCOORD1;
};


VertexOutput vert(VertexInput v) {
        VertexOutput o = (VertexOutput)0;
        o.uv0 = v.texcoord0;
        o.uv1 = v.texcoord1;
        o.pos = UnityObjectToClipPos(v.vertex);
        return o;
}


fixed4 frag(VertexOutput i) : COLOR{
        fixed4 _Main_var = tex2D(_Main,TRANSFORM_TEX(i.uv0, _Main));
        fixed3 _Lightmap_var = tex2D(_Lightmap,TRANSFORM_TEX(i.uv1, _Lightmap));
        fixed3 LightCal = 1.22 * _Lightmap_var.b * _Lightmap_var.rgb;
        fixed3 LightmapDobbled = LightCal * LightCal;

        //#if SHADER_API_MOBILE
        //fixed3 LightCal = 5.0 * _Lightmap_var.a * _Lightmap_var.rgb;
        //fixed3 LightmapDobbled = LightCal * LightCal;
        //fixed3 emissive = (_Tint.rgb*(_Main_var.rgb*LightmapDobbled));
        //#else
        //fixed3 emissive = (_Tint.rgb*(_Main_var.rgb*(_Lightmap_var.rgb*_Lightmap_var.rgb)));


        fixed3 emissive = (_Tint.rgb*(_Main_var.rgb*LightmapDobbled));


        //#endif

       fixed3 finalColor = emissive;
       return fixed4(finalColor,1);
}

 

ENDCG
}
}
FallBack "Diffuse"
CustomEditor "ShaderForgeMaterialInspector"
}