Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Pulsing rainbow glow effect — Gideros Forum

Pulsing rainbow glow effect

hgy29hgy29 Maintainer
edited November 2017 in Code snippets
Another shader I've just made and which might be useful below. It creates an animated rainbow colored glow around a Bitmap sprite. I made it for my platformer game to show that the player is allmighty (as when Mario takes a star).
If you use it in your games, it would be great if you could acknowledge me.

Here is the code (GLSL, that its all platforms except WinRT)
local shaderV=[[
attribute highp vec3 vVertex;
attribute mediump vec2 vTexCoord;
uniform highp mat4 vMatrix;
varying mediump vec2 fTexCoord;
 
void main() {
  vec4 vertex = vec4(vVertex,1.0);
  gl_Position = vMatrix*vertex;
  fTexCoord=vTexCoord;
}	
]]
 
local scanlinesF=[[
uniform lowp sampler2D fTexture;
varying mediump vec2 fTexCoord;
uniform mediump vec4 fTextureSize;
uniform mediump float fTime;
 
lowp vec3 hsv2rgb(vec3 c) {
  lowp vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
  lowp vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
  return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
 
void main() {
 mediump vec4 pixel=texture2D(fTexture, fTexCoord);
 mediump vec4 frag=pixel; 
 mediump vec2 centerDir=normalize((fTextureSize.xy/2.0-fTexCoord)/fTextureSize.xy)*fTextureSize.zw;
 for (int k=-5;k<=5;k++)
	frag=frag+texture2D(fTexture, fTexCoord-centerDir*float(k));
 frag=frag/12.0;
 if (frag.a<=0.0) discard;
 if (pixel.a>=1.0)
	gl_FragColor = pixel;
 else
	gl_FragColor = vec4(hsv2rgb(vec3(frag.a/2.0+fTime*2.0,0.7,1.0)),frag.a);
}
]]
 
local result,reply=pcall(Shader.new,shaderV,scanlinesF,Shader.FLAG_FROM_CODE,{
	{name="vMatrix",type=Shader.CMATRIX,sys=Shader.SYS_WVP,vertex=true}, 
	{name="fColor",type=Shader.CFLOAT4,sys=Shader.SYS_COLOR,vertex=false}, 
	{name="fTexture",type=Shader.CTEXTURE,vertex=false},  
	{name="fTextureSize",type=Shader.CFLOAT4,sys=Shader.SYS_TEXTUREINFO,vertex=false},  
	{name="fTime",type=Shader.CFLOAT,sys=Shader.SYS_TIMER,vertex=false},  
	}, 
	{{name="vVertex",type=Shader.DFLOAT,mult=3,slot=0,offset=0}, 
	{name="vColor",type=Shader.DUBYTE,mult=4,slot=1,offset=0}, 
	{name="vTexCoord",type=Shader.DFLOAT,mult=2,slot=2,offset=0}, })
 
PulsingEffect=reply
if not result then print("Shader Compilation error:"..reply) end
+1 -1 (+7 / -0 )Share on Facebook

Comments

Sign In or Register to comment.