Question I have this 2D Shader which works
#ifdef GL_ES
precision mediump float;
#endif
#extension GL_OES_standard_derivatives : enable
#define NUM_OCTAVES 16
uniform float time;
uniform vec2 resolution;
mat3 rotX(float a) {
float c = cos(a);
float s = sin(a);
return mat3(
1, 0, 0,
0, c, -s,
0, s, c
);
}
mat3 rotY(float a) {
float c = cos(a);
float s = sin(a);
return mat3(
c, 0, -s,
0, 1, 0,
s, 0, c
);
}
float random(vec2 pos) {
return fract(sin(dot(pos.xy, vec2(12.9898, 78.233))) * 43758.5453123);
}
float noise(vec2 pos) {
vec2 i = floor(pos);
vec2 f = fract(pos);
float a = random(i + vec2(0.0, 0.0));
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
}
float fbm(vec2 pos) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.5));
for (int i=0; i<NUM_OCTAVES; i++) {
v += a * noise(pos);
pos = rot * pos * 2.0 + shift;
a *= 0.5;
}
return v;
}
void main(void) {
vec2 p = (gl_FragCoord.xy * 2.0 - resolution.xy) / min(resolution.x, resolution.y);
float t = 0.0, d;
float time2 = 3.0 * time / 2.0;
vec2 q = vec2(0.0);
q.x = fbm(p + 0.00 * time2);
q.y = fbm(p + vec2(1.0));
vec2 r = vec2(0.0);
r.x = fbm(p + 1.0 * q + vec2(1.7, 9.2) + 0.15 * time2);
r.y = fbm(p + 1.0 * q + vec2(8.3, 2.8) + 0.126 * time2);
float f = fbm(p + r);
vec3 color = mix(
vec3(0.101961, 1.866667, 0.319608),
vec3(0.366667, 1.598039, 0.366667),
clamp((f * f) * 4.0, 0.0, 1.0)
);
color = mix(
color,
vec3(0, 0, 0.164706),
clamp(length(q), 0.0, 1.0)
);
color = mix(
color,
vec3(0.666667, 1, 1),
clamp(length(r.x), 0.0, 1.0)
);
color = (f *f * f + 0.6 * f * f + 0.5 * f) * color;
gl_FragColor = vec4(color, 1.0);
}
And I have been trying to convert to a 3D shader but get the error that gl_FragColor is not reachable in vs shader at line 25
this is the vs shader
attribute highp vec3 position;
attribute mediump vec3 normal;
attribute mediump vec2 uv;
varying highp vec3 posVarying;
varying mediump vec3 normalVarying;
varying mediump vec2 uvVarying;
varying mediump vec3 lightVarying;
uniform highp mat3 agk_WorldNormal;
uniform highp mat4 agk_World;
uniform highp mat4 agk_ViewProj;
uniform mediump vec4 uvBounds;
mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );
void main()
{
uvVarying = uv * uvBounds.xy + uvBounds.zw;
highp vec4 pos = agk_World * vec4(position,1.0);
gl_Position = agk_ViewProj * pos;
mediump vec3 norm = normalize(agk_WorldNormal * normal);
posVarying = pos.xyz;
normalVarying = norm;
lightVarying = GetVSLighting( norm, posVarying );
}
the ps shader to hopefully match
#ifdef GL_ES
precision mediump float;
#endif
#extension GL_OES_standard_derivatives : enable
#define NUM_OCTAVES 16
uniform float time;
uniform vec2 resolution;
varying highp vec3 posVarying;
varying mediump vec3 normalVarying;
varying mediump vec2 uvVarying;
varying mediump vec3 lightVarying;
mediump vec3 GetPSLighting( mediump vec3 normal, highp vec3 pos );
mediump vec3 ApplyFog( mediump vec3 color, highp vec3 pointPos );
uniform vec4 myColor;
uniform mediump vec4 agk_MeshDiffuse;
mat3 rotX(float a) {
float c = cos(a);
float s = sin(a);
return mat3(
1, 0, 0,
0, c, -s,
0, s, c
);
}
mat3 rotY(float a) {
float c = cos(a);
float s = sin(a);
return mat3(
c, 0, -s,
0, 1, 0,
s, 0, c
);
}
float random(vec2 pos) {
return fract(sin(dot(pos.xy, vec2(12.9898, 78.233))) * 43758.5453123);
}
float noise(vec2 pos) {
vec2 i = floor(pos);
vec2 f = fract(pos);
float a = random(i + vec2(0.0, 0.0));
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
}
float fbm(vec2 pos) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.5));
for (int i=0; i<NUM_OCTAVES; i++) {
v += a * noise(pos);
pos = rot * pos * 2.0 + shift;
a *= 0.5;
}
return v;
}
void main(void) {
mediump vec3 norm = normalize(normalVarying);
mediump vec3 light = lightVarying + GetPSLighting( norm, posVarying );
vec2 p = (uvVarying.xy * 2.0 - resolution.xy) / min(resolution.x, resolution.y);
float t = 0.0, d;
float time2 = 3.0 * time / 2.0;
vec2 q = vec2(0.0);
q.x = fbm(p + 0.00 * time2);
q.y = fbm(p + vec2(1.0));
vec2 r = vec2(0.0);
r.x = fbm(p + 1.0 * q + vec2(1.7, 9.2) + 0.15 * time2);
r.y = fbm(p + 1.0 * q + vec2(8.3, 2.8) + 0.126 * time2);
float f = fbm(p + r);
vec3 color = mix(
vec3(0.101961, 1.666667, 0.119608),
vec3(0.666667, 1.498039, 0.166667),
clamp((f * f) * 4.0, 0.0, 1.0)
);
color = mix(
color,
vec3(0, 0.164706,0),
clamp(length(q), 0.0, 1.0)
);
color = mix(
color,
vec3(0.666667, 1, 1),
clamp(length(r.x), 0.0, 1.0)
);
color = (f *f * f + 0.6 * f * f + 0.5 * f) * color;
gl_FragColor = vec4(color, 1.0);
}
Any help would be greatly appreciated
fubar