处理下在材质就好 https://baddogzz.github.io/2020/05/26/Emission-Bake/
shader
Shader "URP/Emission"
{
Properties
{
_BaseMap("BaseColor(RGB) E(A)",2D) = "white"{}
[HDR]_EmissionColor("Emission Color",Color) = (0,0,0,0)
[Space(10)]
_ID("Stencil Mask ID",int) = 0
}
SubShader
{
Tags
{
"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"
}
Pass
{
Tags
{
"LightMode" = "UniversalForward"
}
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ LIGHTMAP_ON
#pragma shader_feature_local_fragment _EMISSION
#pragma multi_compile_fog
...
half4 Frag(VertexOutput IN) : SV_Target
{
half4 color = _EmissionColor;
color.a = saturate(color.a);
return color;
}
ENDHLSL
}
UsePass "Universal Render Pipeline/Simple Lit/Meta"
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class LightmapEmission : MonoBehaviour
{
[MenuItem ("MyCustomBake/Bake")]
static void Bake ()
{
GameObject[] _emissiveObjs = GameObject.FindGameObjectsWithTag("Emissive_to_baked");
foreach (GameObject tmpObj in _emissiveObjs)
{
Material tmpMaterial = tmpObj.GetComponent<Renderer> ().sharedMaterial;
tmpMaterial.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive;
tmpMaterial.EnableKeyword("_EMISSION");
}
Lightmapping.Bake ();
}
}
|