Hi!
I read lots of tutorials about shaders so I could port some sort of drug effect from shadertoy to my game.
This is the shader I am trying to port:
https://www.shadertoy.com/view/4l3GDN
This is the vertex shader I created myself, since ShaderToy don’t provide any:
#version 330 core
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord;
uniform mat4 u_projTrans;
uniform vec3 iResolution;
uniform float iGlobalTime;
uniform vec4 iDate;
varying vec4 v_color;
varying vec2 v_texCoords;
void main()
{
v_color = a_color;
v_color.a = v_color.a * (256.0/255.0);
v_texCoords = a_texCoord + 0;
gl_Position = u_projTrans * a_position;
}
The ported fragment shader:
#version 330 core
const float speed = .05;
const float icount = 300.;
const float size = .2;
in vec4 v_color;
in vec2 v_texCoords;
uniform vec4 iDate;
uniform vec3 iResolution;
uniform float iGlobalTime;
out vec4 fragColor;
void main() {
vec2 res = vec2(min(iResolution.x, iResolution.y), max(iResolution.x, iResolution.y));
vec2 uv = v_texCoords.xy /res.x;
uv-=.5;
if (res.x == iResolution.x) {
uv.y -= .5*res.y / res.x-.5;
} else {
uv.x -= .5*res.y / res.x-.5;
}
float t = iGlobalTime * speed;
for(float i =0.; i<2.*icount; i++) {
if (i >= floor(icount * length(mod(uv, size) - size/2.))) {
break;
}
uv *= mat2(cos(t), sin(t), -sin(t), cos(t));
}
float c=0.;
if (uv.x * uv.y > 0.) {
c=1.0;
}
fragColor = vec4(mod(iDate.w+1.-(2.*abs(uv)),1.5),c,1.);
}
This is in my game loop:
Date date = new Date();
drugShader.setUniformf("iResolution", screen.width, screen.height, 0);
drugShader.setUniformf("iGlobalTime", (float) getEngine().getTimeInSeconds());
drugShader.setUniformf("iDate", date.getYear(), date.getMonth(), date.getDay(), (int)getEngine().getTimeInSeconds());
batch.setShader(drugShader);
batch.draw(transparentImage, screen.width, screen.height);
batch.setShader(null);
I see no effect of the shader. transparentImage is image with dimension screen.width x screen.height with color 0,0,0,1 (BLACK).