In my current project I need prefabs with lightmaps, but from everything I’ve researched… that is not possible because the Beast code is tied to scenes.
So I have hacked together this idea.
Problem: I have a prefab road section that will sometimes be placed at y=0, y=90, y=-90, or y=180 rotation angles. I want the shadows from the trees to be correct for each section’s rotation, as in the image below:
But… I don’t want to have full 2048 res textures for each orientation. So I am adding 512 res 8 bit RGB “lightmaps” as shader decals for each orientation.
Here are the maps:
Color:
Lightmap for 0 Degree Rotation:
Lightmap for 90 Degree rotation:
And… Here is the shader I’ve hacked together, based on Unity’s Mobile/Diffuse shader:
Shader "Mobile/Diffuse-Decal" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_DecalTex ("Decal (RGB)", 2D) = "black" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 150
CGPROGRAM
#pragma surface surf Lambert noforwardadd
sampler2D _MainTex;
sampler2D _DecalTex;
struct Input {
float2 uv_MainTex;
float2 uv_DecalTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
fixed4 decal = tex2D(_DecalTex, IN.uv_DecalTex);
c.rgb *= decal.rgb;
o.Albedo = c.rgb;
}
ENDCG
}
Fallback "Mobile/VertexLit"
}
However, I know very little about shaders, and I imagine somebody has already thought of something similar, but better. So, is there a better way to do this? This is for an iOS game.
I’ve been searching around the forums all day, but I may not know the good words to search for if this has already been discussed.