Unity3D Shader:高亮

这篇博客探讨了如何使用Unity3D的Shader来创建高亮效果。通过C#代码和Shader的结合,详细解释了如何在游戏物体表面实现高光效果,包括原图对比和开启泛光后的视觉差异,为Unity3D开发者提供了实用的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C#代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bloom : MonoBehaviour {
    //全屏泛光
    public Material mat;

    public int downscale;//分辨率

    public int sampleScale = 1;//高斯模糊半径

    public Color colorHold = Color.gray;//颜色阙值,提取高光点

    public Color bloomColor = Color.white;//高光颜色

    [Range(0.0f, 1.0f)]
    public float bloomFactor = 0.5f;//高光权重值

    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        RenderTexture temp1 = RenderTexture.GetTemporary(source.width >> downscale, source.height >> downscale, 0, source.format);
        RenderTexture temp2 = RenderTexture.GetTemporary(source.width >> downscale, source.height >> downscale, 0, source.format);

        Graphics.Blit(source, temp1);

        mat.SetVector("_colorHold", colorHold);
        Graphics.Blit(temp1, temp2, mat, 0);

        mat.SetVector("_offset", new Vector4(0, sampleScale, 0, 0));
        Graphics.Blit(temp2, temp1, mat, 1);
        mat.SetVector("_offset", new Vector4(sampleScale, 0, 0, 0));
        Graphics.Blit(temp1, temp2, mat, 1);

        mat.SetTexture("_BlurTex", temp2);
        mat.SetVector("_bloomColor", bloomColor);
        mat.SetFloat("_bloomFactor", bloomFactor);
        Graphics.Blit(source, destination
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值