The problems come from the mandelbrot function:
vec3 mandelbrot (vec2 coord){
vec2 z0 = vec2(0.0, 0.0);
int number = fractal (z0, coord, 10000);
float v = float(number);
float factor = 0.0;
return paletize (v, factor);
}
int fractal (vec2 z0, vec2 c, int maxIterations){
//doesn't matter
}
vec3 paletize (float v, float factor){
doesn't matter
}
and here is the error message: https://gyazo.com/5516853ee2600b58a303fd609530fafe
fragment shader failed to compile: the error log is: ERROR:0:13 ´fractal´:no matching overloaded function found
ERROR:0.13: '=' : cannot convert from const float to mediump int
ERROR:0:19: ´paletize´: no matching overloaded function found
ERROR:0:19: ´return´: function return is not matching type:
Try moving your fractal and paletize functions over mandelbrot.
Related
The shader I've converted below throws the following errors in LibGDX with Opengl 2.0:
ERROR: 0:08: '<<' does not operate on 'int' and 'int'
ERROR: 0:23: No matching function for call to mod(int, int)
ERROR: 0:24: Invalid call of undeclared identifier 'textureLod'
Obviously I commented out and replaced certain parts to see the errors further down but the errors should be all the problems it has.
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform vec2 resolution;
const int samples = 35, LOD = 2, sLOD = 1 << LOD;//error here
const float sigma = float(samples) * .25;
float gaussian(vec2 i) {
return exp( -.5* dot(i/=sigma,i) ) / ( 6.28 * sigma*sigma );
}
void main() {
vec2 u = gl_FragCoord.xy/resolution.xy;
vec4 o = vec4(0);
int s = samples/sLOD;
vec2 scale = vec2(1,1);
for ( int i = 0; i < s*s; i++ ) {
vec2 d = vec2(mod(i,s), i/s)*float(sLOD) - float(samples)/2.;//error here
o += gaussian(d) * textureLod( u_texture, u + scale * d , float(LOD) );//error here
}
gl_FragColor = v_color * texture2D(u_texture, v_texCoords);//simply outputs default image at the moment since the above has errors
}
There's not really any easy or good way to use anything higher than opengl 2.0 in LibGDX but I'm wondering if there's a workaround or alternative to any of these commands. Not sure particularly why mod doesn't work - it only works with float ?
What obvious thing am I missing? I'm trying to compile/run this vertex shader:
// an attribute will receive data from a buffer
attribute vec2 a_position;
uniform vec2 u_resolution;
varying vec4 v_color;
// all shaders have a main function
void main() {
// convert the position from pixels to 0.0 to 1.0
vec2 zeroToOne = a_position / u_resolution;
// convert from 0->1 to 0->2
vec2 zeroToTwo = zeroToOne * 2.0;
// convert from 0->2 to -1->+1 (clip space)
vec2 clipSpace = zeroToTwo - 1.0;
gl_Position = vec4(clipSpace, 0, 1);
vec3 c = hsv2rgb(vec3(0.5, 0.5, 0.5));
/*temporary*/ v_color = gl_Position * 0.5 + 0.5;
gl_PointSize = 1.0;
}
// All components are in the range [0…1], including hue.
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
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);
}
using code I found at From RGB to HSV in OpenGL GLSL but get the error:
https://webglfundamentals.org/webgl/lessons/webgl-boilerplate.html
webgl-utils.js:66 *** Error compiling shader '[object WebGLShader]':ERROR: 0:19: 'hsv2rgb' : no matching overloaded function found
ERROR: 0:19: '=' : dimension mismatch
ERROR: 0:19: '=' : cannot convert from 'const mediump float' to 'highp 3-component vector of float'
The error is specific to the hsv2rgb call. I have tried a number of things, including making the parameter a variable (i.e. adding vec3 v = vec3(0.5, 0.5, 0.5) and passing v into hsv2rgb), and making a skeleton hbv2rgb that simply returns its parameter. In the referenced SO post, I saw that another user seemed to have exactly the same problem, but I am properly passing in a vec3 rather than 3 floats.
If it makes any difference, here is the fragment shader as well:
// fragment shaders don't have a default precision so we need
// to pick one. mediump is a good default
precision mediump float;
varying vec4 v_color;
void main() {
// gl_FragColor is a special variable a fragment shader
// is responsible for setting
gl_FragColor = v_color;
}
From OpenGL ES Shading Language 1.00 Specification - 6.1 Function Definitions:
All functions must be either declared with a prototype or defined with a body before they are called.
Hence, you have to declare the function hsv2rgb before it is used the first time or you have to declare a function prototype:
vec3 hsv2rgb(vec3 c);
void main() {
// [...]
vec3 c = hsv2rgb(vec3(0.5, 0.5, 0.5));
// [...]
}
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
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);
}
I'm looking for a noise function wich is working on a none highp fragment shader.
What I have tried:
//http://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl
float snoise(vec2 co)
{
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
//http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
float snoise(vec2 co)
{
float a = 12.9898;
float b = 78.233;
float c = 43758.5453;
float dt= dot(co.xy ,vec2(a,b));
float sn= mod(dt,3.14);
return fract(sin(sn) * c);
}
Main:
void main()
{
vec4 texCol = texture2D(uTexDiffuse, vTexCoord.xy);
float n = snoise(vec2(vTexCoord.x*cos(uTime),vTexCoord.y*sin(uTime)));
gl_FragColor = texCol;
gl_FragColor.rgb *= n;
}
both are working fine on a device which supports high point fragmentshader precision. But on a device like the nexus 7 this is not working.
I also tried the shader from this repository: webgl-noise
But even they are not working.
Result on highp supporting fragment shader (looking fine):
Result on Nexus 7 2012:
I have a fragment shader, it has structs and a uniform of those structs. When I tried to compile them, OpenGL gave me this error:
0(30) : error C0000: syntax error, unexpected identifier, expecting '{' at token "lights_a"
0(31) : error C0000: syntax error, unexpected identifier, expecting '{' at token "material"
I don't know what the problem is here. I have been searching for the problem... I looked at line 30 and 31, I did everything I could imagine, but without success.
Here is the code:
#version 330 core
struct LightBase
{
int renderit;
vec4 ambient_light;
vec4 specular_light;
vec4 diffuse_light;
float radius;
vec3 light_position;
vec3 light_direction;
int light_type;
};
struct MaterialBase
{
vec4 ambient_affect;
vec4 specular_affect;
vec4 diffuse_affect;
float shining;
float mirror;
int light_affect;
};
in vec3 VertexPos;
in vec3 Normal;
uniform int light_quantity;
uniform LightBase lights_a[50];
uniform MaterialBase material;
uniform float usingTex;
uniform sampler2D texturemap;
in vec2 UVs;
in vec4 Colors;
out vec4 color;
void main() {
vec4 texture_u = texture(texturemap,UVs).rgba * usingTex;
vec4 color_u = Colors * (1.0f-usingTex);
vec4 final_color = color_u+texture_u;
// Light
for(int i=0;i<light_quantity;i++) {
if(lights_a[i].renderit==1) {
if(lights_a[i].light_type==1) {
float attenuation = max(0.0,1.0-dot(lights_a[i].light_direction,lights_a[i].light_direction));
vec3 L = normalize(lights_a[i].light_direction);
vec3 N = normalize(Normal);
vec3 V = normalize(-VertexPos);
vec3 R = normalize(-reflect(L,N));
float nDotL = max(0.0,dot(N,L));
float rDotV = max(0.0,dot(R,V));
float ambient_result = lights_a[i].ambient_light * material.ambient_affect * attenuation;
float diffuse_result = lights_a[i].diffuse_light * material.diffuse_affect * nDotL * attenuation;
float specular_result = lights_a[i].specular_light * material.specular_affect * pow(rDotV,material.shining) * attenuation;
vec4 this_colour = (ambient_result + diffuse_result + specular_result) * final_color;
final_color = this_colour;
}
}
}
color = final_color;
}
What's wrong about the code?
I don't see an error when I compile your code -- only a couple of warnings:
0(62) : error C7011: implicit cast from "vec4" to "float"
0(63) : error C7011: implicit cast from "vec4" to "float"
0(64) : error C7011: implicit cast from "vec4" to "float"
I can almost reproduce the error you see by commenting out the declarations of struct LightBase and struct MaterialBase -- except they show up on lines 33 and 34. which are the lines with the noted tokens lights_a and material
This leads me to believe that your problem is that you're not actually compiling the program you think you are. Perhaps you're reading it from a file into memory, but the memory gets corrupted somehow before you call glShaderSource...
So I have this fragment shader, which was working great until I refactored some logic out into a separate function. I want to be able to call it multiple times to layer different versions of the effect on top of each other.
However, as soon as I created this custom function, the shader starts throwing the error:
ERROR: 0:33: 'grid' : no matching overloaded function found
Which is wierd, because it appears to be compiling it as function. If I remove the return from grid() I get this error too:
ERROR: 0:36: '' : function does not return a value: grid
So what am I missing here about declaring functions?
Full shader here:
uniform float brightness;
uniform float shiftX;
uniform float shiftY;
uniform vec4 color;
varying vec3 vPos;
void main() {
gl_FragColor = vec4( grid(200.0), 0.0, 0.0, 1.0 );
}
float grid(float size) {
float x = pow(abs(0.5 - mod(vPos.x + shiftX, 200.0) / 200.0), 4.0);
float y = pow(abs(0.5 - mod(vPos.y + shiftY, 200.0) / 200.0), 4.0);
return (x+y) * 5.0 * pow(brightness, 2.0);
}
You either have to put the grid function before the main or forward declare it as you would in c.
Such as:
float grid(float size);
before the main method.