首页 > 其他 > 详细

【OpenGL】Shader实用工具(二)-照片闪光

时间:2014-04-01 13:43:11      阅读:676      评论:0      收藏:0      [点我收藏+]

在游戏中,当战斗结束后,对一些获取的宝贝需要进行闪光处理。这篇文章介绍一个进行闪光处理的shader,运行效果如下:

bubuko.com,布布扣 bubuko.com,布布扣 bubuko.com,布布扣

下面是shader的实现:

Shader "stalendp/imageShine" {
	Properties {
		_image ("image", 2D) = "white" {}
		_percent ("_percent", Range(-5, 5)) = 1
	}
	
	CGINCLUDE
        #include "UnityCG.cginc"           
        
        sampler2D _image;
		float _percent;
		
        struct v2f {    
            float4 pos:SV_POSITION;    
            float2 uv : TEXCOORD0;   
        };  
  
        v2f vert(appdata_base v) {  
            v2f o;  
            o.pos = mul (UNITY_MATRIX_MVP, v.vertex);  
            o.uv = v.texcoord.xy;  
            return o;  
        }  
  
        fixed4 frag(v2f i) : COLOR0 {
        	fixed2x2 rotMat = fixed2x2(0.866,0.5,-0.5,0.866);  // 旋转30度
        	
       	 	fixed4 k = tex2D(_image, i.uv);
       	 	fixed2 uv = (i.uv - fixed2(_percent)) * 2; // 缩放并位移
       	 	uv = mul(rotMat, uv); //旋转
       	 	
       	 	k +=  fixed4(saturate(lerp(fixed(1),fixed(0),abs(uv.y)))); // 加上光线
            return k;  
        }  
    ENDCG    
  
    SubShader {   
        Pass {    
            CGPROGRAM    
            #pragma vertex vert    
            #pragma fragment frag    
            #pragma fragmentoption ARB_precision_hint_fastest     
  
            ENDCG    
        }
    }
    FallBack Off  
}

 

【OpenGL】Shader实用工具(二)-照片闪光,布布扣,bubuko.com

【OpenGL】Shader实用工具(二)-照片闪光

原文:http://blog.csdn.net/stalendp/article/details/22720295

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!