Unity URP自定义Emission材质

处理下在材质就好
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
{
    // The menu item.
    [MenuItem ("MyCustomBake/Bake")]
    static void Bake ()
    {
        // Find all objects with the tag <Emissive_to_baked>
        // We have to set the tag “Emissive_to_baked” on each GO to be baked.
        GameObject[] _emissiveObjs = GameObject.FindGameObjectsWithTag("Emissive_to_baked");

        // Then, by each object, set the globalIllumiationFlags to BakedEmissive.
        foreach (GameObject tmpObj in _emissiveObjs)
        {
            Material tmpMaterial = tmpObj.GetComponent<Renderer> ().sharedMaterial;
            tmpMaterial.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive;
            tmpMaterial.EnableKeyword("_EMISSION");
        }

        // Bake the lightmap.
        Lightmapping.Bake ();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值