Emissive not baking

Hello,

Maybe I’m doing something wrong, but :

  • I have Pro
  • I’m working on Android workspace (but for baking this shouldn’t care ?)
  • I’m trying to bake an object who got a custom SelfIlluminated material (working good in editor)
  • when I bake, the self illum portion is not baked
  • I put a screenshot of my bake settings

Also, the material is a Surface Shader I wrote, consisting of this :

Shader "_Shaders/_SelfIllum" {
Properties {
      _MainTex ("Texture", 2D) = "white" {}
      _Selfillum ("Self Illum", 2D) = "white" {}
	_Color ("Main Color", Color) = (1,1,1,1)
    }
    SubShader {
      Tags { "RenderType" = "Opaque" }
      CGPROGRAM
      #pragma surface surf Lambert

      sampler2D _MainTex;
      sampler2D _Selfillum;
      
       struct Input {
          float2 uv_MainTex;
      };
     


      void surf (Input IN, inout SurfaceOutput o) {
       half4 _lightmap = tex2D (_Selfillum, IN.uv_MainTex);
       
          o.Albedo = tex2D ( _MainTex, IN.uv_MainTex).rgb;
         o.Emission = o.Albedo.rgb*_lightmap.rgb;

      }


      
      ENDCG
    } 
    Fallback "_Shaders1.1/_SelfIllum"

	
}

Thank you for your attention :slight_smile:

unhappily a bug in the mobile targets. you need to bake on a desktop incarnation of the project where you enabled deferred to bake it (I think it was deferred, dual lightmapping might have been involved too) and then take it over to the mobile with you (cause there deferred etc are not present which impacts the building of emissive and GI)

Oh, thank you very much Dreamora :slight_smile:

Well, I tried in Desktop targetting, Deferred, but still no emissive baking :confused:

Ok got an answer here :

http://forum.unity3d.com/threads/62660-Beast-Lightmapping-Self-Illumination-Problem?highlight=bake+emissive#11

Seems like a bug :confused:

edit : and it doens’t work either.

What happens if you use one of the standard Self-Illuminated shaders?

Trying right now, and GI calculation is taking forever suddenly. I guess this was the deal (will confirm when over).

edit : confirmed.

Would it come from my shader lacking of a LightingName_PrePass() function, as it’s needed for Deferred ? (even if it’s not baked in Deferred mode)

edit 2 : doesn’t need prepass function anyway, as it’s a buit-in light model (Lambert)

Although, it doesn’t need to be used in Desktop Mode (tried the built-in selfIllum shader in Android workspace, baking worked).

So to sum it up :

  • emissive baking is not working in “Bake Selected” mode on object.
  • is not working with custom surface emissive shaders

I can deal with it, as it’s just a one-shot procedure. Thanks for your help, gents.

Just to clarify… it’s not working with your custom shader :wink:

I believe you need to add the Emission properties found in the standard Self-Illum shaders so that they are properly sent to Beast.

Shader "Self-Illumin/Diffuse" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
	_Illum ("Illumin (A)", 2D) = "white" {}
	_EmissionLM ("Emission (Lightmapper)", Float) = 0
}
SubShader {
	Tags { "RenderType"="Opaque" }
	LOD 200
	
CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
sampler2D _Illum;
float4 _Color;

struct Input {
	float2 uv_MainTex;
	float2 uv_Illum;
};

void surf (Input IN, inout SurfaceOutput o) {
	half4 tex = tex2D(_MainTex, IN.uv_MainTex);
	half4 c = tex * _Color;
	o.Albedo = c.rgb;
	o.Emission = c.rgb * tex2D(_Illum, IN.uv_Illum).a;
	o.Alpha = c.a;
}
ENDCG
} 
FallBack "Self-Illumin/VertexLit"
}

Oops, yeah sorry :wink:

Unfortunately, doesn’t work either :confused:

No, this doesn’t work. I want the same thing, custom emissive shaders that work with lightmaps. It can’t be done. I suspect you need to overwrite an internal shader to get this to work.

It can be done. Almost every shader in AngryBots is a custom shader and a few of them use Emission (which properly bakes into the lightmap). Have a look at those shaders and see what you are doing differently.

Wow, old topic ^^

Ethan is right, it’s working, just have to write the right surface shader.

Just need to specify the Emission component though, something like this :

o.Emission = myOriginalTexture.rgb*myCustomLightmap.rgb;

(Ethan’s first shader example was right too, it was just using the Alpha channel of the texture, I don’t know why I couldn’t make it work at the time)