【Shader】游戏屏幕黑白特效
来源:互联网 发布:景安代理平台源码 编辑:程序博客网 时间:2024/04/27 06:28
.cs脚本挂载到MainCamera
using System.Collections;using System.Collections.Generic;using UnityEngine;[ExecuteInEditMode]public class TestImage : MonoBehaviour { #region public Shader curShader; private float grayScaleAmount = 1.0f; private Material curMaterial; #endregion #region Properties Material material { get{ if (curMaterial == null) { curMaterial = new Material(curShader); curMaterial.hideFlags = HideFlags.HideAndDontSave; } return curMaterial; } } #endregion // Use this for initialization void Start () { if (!SystemInfo.supportsImageEffects) { enabled = false; return; } if (!curShader && !curShader.isSupported) { enabled = false; } } // // Update is called once per frame // void Update () { // grayScaleAmount = Mathf.Clamp(grayScaleAmount, 0.0f, 1.0f); //} private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (curShader != null) { material.SetFloat("_LuminosityAmount",grayScaleAmount); Graphics.Blit(source,destination,material); } else { Graphics.Blit(source,destination); } } private void OnDisable() { if (curMaterial) { DestroyImmediate(curMaterial); } }}
.shader脚本附加到上面的属性中
Shader "Hidden/NewImageEffectShader"{ Properties { _MainTex ("Texture", 2D) = "white" {} _LuminosityAmount("GrayScale Amount",Range(0.0,1)) = 1.0 } SubShader { Pass { CGPROGRAM #pragma vertex vert_img #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest #include "UnityCG.cginc" uniform sampler2D _MainTex; fixed _LuminosityAmount; fixed4 frag (v2f_img i) : COLOR { fixed4 renderTex = tex2D(_MainTex,i.uv); float luminosity = 0.299 * renderTex.r + 0.587 * renderTex.g + 0.114 * renderTex.b; fixed4 finalColor = lerp(renderTex,luminosity,_LuminosityAmount); return finalColor; } ENDCG } }}
阅读全文
0 0
- 【Shader】游戏屏幕黑白特效
- Unity shader实现屏幕模糊特效
- Shader特效——实现“抗锯齿的黑白格”并原理解析【GLSL】
- Unity制作游戏在部分手机上显示黑白屏幕
- Shader创建老电影风格的屏幕特效
- Shader学习案例三---屏幕特效之色彩调节
- unity 黑白shader
- Unity3d 屏幕特效实现类似死亡之后的全屏黑白效果
- Unity3d 屏幕特效实现类似死亡之后的全屏黑白效果
- Shader学习案例一---屏幕特效之黑白化当前屏幕
- 《着色器和屏幕特效》读书笔记第九章-游戏可玩性和屏幕特效
- cocos shader 之 黑白滤镜
- 网页上实现黑白特效
- 【浅墨Unity3D Shader编程】之八 Unity5新版Shader模板源码解析&运动模糊(径向模糊)屏幕特效的实现
- 【浅墨Unity3D Shader编程】之九 深入理解Unity5中的Standard Shader (一)&屏幕水幕特效的实现
- 【浅墨Unity3D Shader编程】之十 深入理解Unity5中的Standard Shader(二)&屏幕油画特效的实现
- 【浅墨Unity3D Shader编程】之十一 深入理解Unity5中的Standard Shader(三)&屏幕像素化特效的实现
- 【浅墨Unity3D Shader编程】之八 Unity5新版Shader模板源码解析&运动模糊(径向模糊)屏幕特效的实现
- PDF预览之PDF.js的常见问答翻译
- web项目Log4j日志输出路径配置问题
- 自定义服务
- 敏感字
- angular中的路由的基础使用
- 【Shader】游戏屏幕黑白特效
- Reflection2017.12.17
- MVP 模式 淘宝分类
- np.dot函数
- 20171211循环结构总结
- java 基本类型转换 字符char 转 数字int
- itertools.chain()
- mybatis详解-(14)参数处理#和$
- java中获取类加载路径和项目根路径的5种方法