Hi,
So I’ve tried with Defold Shadertoy tutorial and it’s ok, everything is clear here for me, more or less. But when it goes to implement different shader for example Raindrops it’s a bit harder. I’ve managed to change resolution and time for Defold but what about other uniform variables like iChannel0? Could you please help me with this one and maybe explain more about how you deal with them in other cases?
Following that, I think I will be able to overcome these warnings and understand what is done in line 67 (creation of vector color, commented now).
WARNING:GRAPHICS: WARNING: 0:13: ‘’ : #version directive missing
ERROR: 0:66: ‘iChannel0’ : undeclared identifier
ERROR: 0:66: ‘texture’ : no matching overloaded function found (using implicit conversion)
ERROR: 0:66: ‘rgb’ : vector field selection out of range
Code:
// Maximum number of cells a ripple can cross.
#define MAX_RADIUS 2
// Set to 1 to hash twice. Slower, but less patterns.
#define DOUBLE_HASH 0
// Hash functions shamefully stolen from:
// https://www.shadertoy.com/view/4djSRW
#define HASHSCALE1 .1031
#define HASHSCALE3 vec3(.1031, .1030, .0973)
#define speed 0.010
float hash12(vec2 p)
{
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);
p3 += dot(p3, p3.yzx + 19.19);
return fract((p3.x + p3.y) * p3.z);
}
vec2 hash22(vec2 p)
{
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE3);
p3 += dot(p3, p3.yzx+19.19);
return fract((p3.xx+p3.yz)*p3.zy);
}
varying mediump vec2 var_texcoord0;
uniform lowp vec4 time;
void main()
{
vec2 res = vec2(1.0, 1.0);
vec2 uv = var_texcoord0.xy * res.xy - 0.5;
vec2 p0 = floor(uv);
float resolution = 0.0;
float time = time.x * speed + 0.25;
float circles = 0.;
for (int j = -MAX_RADIUS; j <= MAX_RADIUS; ++j)
{
for (int i = -MAX_RADIUS; i <= MAX_RADIUS; ++i)
{
vec2 pi = p0 + vec2(i, j);
#if DOUBLE_HASH
vec2 h = hash22(pi);
#else
vec2 h = pi;
#endif
vec2 p = pi + hash22(h);
float t = fract(0.3*time + hash12(h));
float d = length(p - uv) - (float(MAX_RADIUS) + 1.)*t;
circles += (1. - t) * (1. - t)
* mix(sin(31.*d) * 0.5 + 0.5, 1., 0.1)
* smoothstep(-0.6, -0.3, d)
* smoothstep(0., -0.3, d);
}
}
float intensity = mix(0.01, 0.15, smoothstep(0.1, 0.6, abs(fract(0.05*time + 0.5)*2.-1.)));
vec3 n = vec3(dFdx(circles), dFdy(circles), 0.);
n.z = sqrt(1. - dot(n.xy, n.xy));
//vec3 color = texture(iChannel0, uv/resolution - intensity*n.xy).rgb + 5.*pow(clamp(dot(n, normalize(vec3(1., 0.7, 0.5))), 0., 1.), 6.);
//gl_FragColor = vec4(color, 1.0)
gl_FragColor = vec4(var_texcoord0.xy, 0.0, 1.0);
}