- 最后登录
- 2018-6-29
- 注册时间
- 2011-7-1
- 阅读权限
- 20
- 积分
- 359

- 纳金币
- 335582
- 精华
- 0
|
Here is a simple bloom effect, sort of faking it as cheap as possible. I would appreciate if anyone with ios or android capabilities to test it and tell me if it works on mobile platforms.
This is the effect file itself, save it as PP_BloomSimple.cs file
using UnityEngine;
[ExecuteInEditMode]
[AddComponentMenu("Image Effects/Aubergine/BloomSimple")]
public class PP_BloomSimple : MonoBehaviour {
//Color
public float strength = 0.5f;
public Shader shader;
private Material m_Material;
//Properties
protected Material material {
get {
if (m_Material == null) {
m_Material = new Material(shader);
m_Material.hideFlags = HideFlags.HideAndDontSave;
}
return m_Material;
}
}
//Methods
protected void Start () {
// Disable if we don't support image effects
if (!SystemInfo.supportsImageEffects) {
enabled = false;
return;
}
// Disable the image effect if the shader can't***n on the users graphics card
if (!shader || !shader.isSupported) enabled = false;
}
protected void OnDisable () {
if( m_Material ) {
DestroyImmediate(m_Material);
}
}
void Awake () {
material.SetFloat("_Strength", strength);
}
void OnEnable () {
shader = Shader.Find("Hidden/Aubergine/BloomSimple");
}
// Called by camera to apply image effect
void OnRenderImage (RenderTexture source, RenderTexture destination) {
material.SetFloat("_Strength", strength);
Graphics.Blit (source, destination, material);
}
}
This is the shader file.
Shader "Hidden/Aubergine/BloomSimple" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Strength ("Bloom Strength", Float) = 0.5
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off Lighting Off Fog { Mode off }
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
sampler2D _MainTex;
float _Strength;
float4 frag (v2f_img i) : COLOR {
float4 col = tex2D(_MainTex, i.uv);
float4 bloom = col;
col.rgb = pow(bloom.rgb, _Strength);
col.rgb *= bloom;
col.rgb += bloom;
return col;
}
ENDCG
}
}
Fallback off
}
|
|