纳金网

标题: simple bloom effect,一个shader [打印本页]

作者: 晃晃    时间: 2011-9-8 08:02
标题: simple bloom effect,一个shader
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
}


作者: Asen    时间: 2011-9-8 09:30

作者: 奇    时间: 2012-3-4 23:21
其实楼主所说的这些,俺支很少用!

作者: 奇    时间: 2012-3-5 23:31
好`我顶``顶顶

作者: C.R.CAN    时间: 2012-3-13 23:31
先顶上去,偶要高亮加精鸟!

作者: 彬彬    时间: 2012-3-16 19:40

   

作者: 晃晃    时间: 2012-5-3 23:18
已阵亡的 蝶 随 风 舞 说过  偶尔按一下 CTRL A 会发现 世界还有另一面

作者: markq    时间: 2012-5-4 23:22
谢谢分享



爱生活 爱3D 爱纳金网



www.narkii.com
作者: 奇    时间: 2012-5-8 23:22
你们都躲开,我来顶

作者: 菜刀吻电线    时间: 2012-5-15 23:23
不错哦,顶一下......

作者: C.R.CAN    时间: 2012-12-1 23:26
水……生命之源……灌……

作者: 菜刀吻电线    时间: 2013-1-25 12:52
顶!学习了!阅!

作者: 晃晃    时间: 2013-1-27 23:27
凡系斑竹滴话要听;凡系朋友滴帖要顶!

作者: 晃晃    时间: 2013-2-8 23:20
再看一看,再顶楼主

作者: 1250    时间: 2014-2-28 10:48
感谢分享!
作者: 川流不息    时间: 2014-3-3 12:43
感谢楼主的无私分享




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5