--图片溶解消失:
--spr:需要溶解的图片
--speed:溶解速度
--sp2:按某个纹理溶解(可为nil,默认spr的纹理)
--finishCall:消失后回调(可为nil)
function UICommon.rongJieXiaoshi(spr,Speed,spr2,finishCall)
local vertSource1 = [[
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;
#ifdef GL_ES
varying lowp vec4 v_fragmentColor;
varying mediump vec2 v_texCoord;
#else
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
#endif
void main()
{
gl_Position = CC_PMatrix * a_position;
v_fragmentColor = a_color;
v_texCoord = a_texCoord;
}
]]
local fragSource1 = [[
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform sampler2D u_texture1;
uniform float Threshold;
void main(void)
{
vec4 col=texture2D(u_texture1,v_texCoord);
if(col.g>Threshold){
discard;
}
gl_FragColor=texture2D(CC_Texture0,v_texCoord);
}
]]
if spr2 and (spr2:getDescription() == "ImageView" or spr2:getDescription() == "Button") then
spr2 = spr2:getVirtualRenderer():getSprite()
end
if spr:getDescription() == "ImageView" or spr:getDescription() == "Button" then
spr = spr:getVirtualRenderer():getSprite()
end
local Texture = spr2 and spr2:getTexture() or spr:getTexture()
local cache = cc.GLProgramCache:getInstance()
local pProgram = cc.GLProgram:createWithByteArrays(vertSource1,fragSource1)
local Speed = Speed or 1
gl.deleteShader(pProgram)
pProgram:link()
pProgram:updateUniforms()
pProgram:use()
cache:addGLProgram(glProgram, "rongJieXiaoshi")
local glProgramState = cc.GLProgramState:getOrCreateWithGLProgram(pProgram)
glProgramState:setUniformTexture("u_texture1",Texture);
spr:setGLProgram(pProgram)
spr:setGLProgramState(glProgramState)
local Threshold = 1
local scheduleId
_callback = function ( ... )
glProgramState:setUniformFloat("Threshold",Threshold);
Threshold = Threshold-0.1
if Threshold<=0 then
cc.Director:getInstance():getScheduler():unscheduleScriptEntry(scheduleId)
scheduleId = nil
if finishCall and type(finishCall) == "function" then
finishCall()
end
return
end
end
scheduleId = cc.Director:getInstance():getScheduler():scheduleScriptFunc(_callback, 0.1*Speed, false)
_callback()
end
shader图片溶解消失
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 原因 面试了一家VR房地产公司,给了几张图片,要求做出VR漫游效果。通过3个小时研究,我发现问题还是在shader...
- 最终效果: 步骤1、在ps中创建一个新文档(最好保持垂直形状并且有透明的背景),设置参照下图: 步骤2、需要找一张...
- 你见过多少才貌双全的星座女,你又服多少才貌双全的星座女,那些女孩或是明媚动人,或是温柔和驯,或是俏皮可爱,或是任性...