Unity实战(9):使用屏幕后处理ScreenPostEffect调整画面亮度、饱和度、对比度

目录

前言

一、贴图的调整

二、Post-Screen屏幕后操作

三、ColorBSC调节亮度、饱和度、对比度

四、说明


前言

本文记录一些方法,使Unity输出的画面可以调整其亮度、饱和度、对比度

一、贴图的调整

该方法是在模型量不大或者模型分层分级比较清晰的情况下最容易也是最节省电脑性能资源的,即将模型本身的贴图在photoshop(不要用不高级的PS)中手动调节亮度、饱和度、对比度。该方法不涉及到Unity自身的操作,因此在此不赘述。

二、Post-Screen屏幕后操作

在Unity项目文件中放入以下脚本,便于下一步脚本调用

using UnityEngine;

//非运行时也触发效果

[ExecuteInEditMode]

//屏幕后处理特效一般都需要绑定在摄像机上

[RequireComponent(typeof(Camera))]

//提供一个后处理的基类,主要功能在于直接通过Inspector面板拖入shader,生成shader对应的材质

public class ScreenPostEffectBase : MonoBehaviour {

    //Inspector面板上直接拖入

    public Shader shader = null;

    private Material _material = null;

    public Material _Material {

        get {

            if (_material == null)

                _material = GenerateMaterial(shader);

            return _material;

        }

    }

    //根据shader创建用于屏幕特效的材质

    protected Material GenerateMaterial(Shader shader) {

        // 系统是否支持

        if (!SystemInfo.supportsImageEffects) {

            return null;

        }

        if (shader == null)

            return null;

        //需要判断shader是否支持

        if (shader.isSupported == false)

            return null;

        Material material = new Material(shader);

        material.hideFlags = HideFlags.DontSave;

        if (material)

            return material;

        return null;

    }

}

三、ColorBSC调节亮度、饱和度、对比度

将下面的脚本挂载到需要输出的相机上即可,在inspector面板中调节亮度、饱和度、对比度

using UnityEngine;

using System.Collections;

//继承自PostEffectBase

public class ColorBSC : ScreenPostEffectBase {

    //通过Range控制可以输入的参数的范围

    [Range(0.0f, 3.0f)]

    public float brightness = 1.0f;//亮度

    [Range(0.0f, 3.0f)]

    public float contrast = 1.0f;  //对比度

    [Range(0.0f, 3.0f)]

    public float saturation = 1.0f;//饱和度

    //覆写OnRenderImage函数

    void OnRenderImage(RenderTexture src, RenderTexture dest) {

        //仅仅当有材质的时候才进行后处理,如果_Material为空,不进行后处理

        if (_Material) {

            //通过Material.SetXXX("name",value)可以设置shader中的参数值

            _Material.SetFloat("_Brightness", brightness);

            _Material.SetFloat("_Saturation", saturation);

            _Material.SetFloat("_Contrast", contrast);

            //使用Material处理Texture,dest不一定是屏幕,后处理效果可以叠加的!

            Graphics.Blit(src, dest, _Material);

        }

        else {

            //直接绘制

            Graphics.Blit(src, dest);

        }

    }

}

四、说明

使用屏幕后处理进行亮度、对比度、饱和度的调节是比较消耗计算机资源的方式,因此原场景尽可能少物体的面数,避免不必要的资源消耗,减少卡顿

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Extends Unity's post processing with 34 additional screen effects. Aiming to provide visual enhancers or feedback effects. Edge detection Highlight the edges of objects or colors Fog Distance and height fog with 2D density noise. As well as single, gradient and skybox color modes. Sunshafts Radiate sun rays from a directional light and skybox Caustics Projects an animated caustics texture over the scene, within a certain height range Color Grading LUT Use any third-party LUT strip, with the option to fade two LUTs over distance. Cloud Shadows Projects a texture over the world (cloud example texture included) Tilt Shift Horizontal or Radial depth of field effect Ripples Make the image appear to wave Lens Flares Draw procedural lens flares on bright spots Colorize Remaps the screen's color to a gradient texture (eg. night or thermal vision) Refraction Create cracked glass, scratches, frost etc. Kuwuhara Transforms the image into a real-time oil-painting Sketch Creates a hatching effect based on luminance Ambient Occlusion 2D Adds self shadowing based on luminance Light streaks JJ-Abrams style lens flares. Extends bloom with light streaks Blur Gaussian and Box blurring methods Speed Lines Anime/cartoon speed effect Color Split Simulates the derefraction of color channels Radial blur Blurs the image towards the edges of the screen (aka Bethesda-style pain effect) Pixelize A retro resolution effect, creates pseudo pixelart Dithering Creates a checker-pattern Lo-Fi shading effect Posterize Limits the screen to old school 1-16bit color depth Sharpen Makes the image appear crisper (useful when using TAA) Double Vision Crosseyed vision, either full-screen or limited to the edges Hue Shift 3D Simulates psychedelic color breathing Overlay Fix an image to the screen, includes blending options Kaleidoscope Splits the screen up into mirrored "pie" pieces Transition Steps through a gradient to transition to a black screen (eg. GBA Pokemen)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值