Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocessor support #8

Open
stefan1000 opened this issue Apr 6, 2017 · 1 comment
Open

Preprocessor support #8

stefan1000 opened this issue Apr 6, 2017 · 1 comment

Comments

@stefan1000
Copy link

Since glslx doesn't support preprocessing, how to check e.g. if highp is available in a fragment shader ?

#ifndef GL_FRAGMENT_PRECISION_HIGH
precision mediump float;
#else
precision highp float;
#endif
@bramtechs
Copy link

bramtechs commented Aug 11, 2024

Usage of #define is detected as a syntax error.

<stdin>:7:1: error: Unexpected PRAGMA
#define ITERATIONS 8
#version 100
precision highp float;

#define ITERATIONS 8

varying vec2 fragTexCoord;
varying vec4 fragColor;

uniform sampler2D texture0;
uniform vec4 colDiffuse;

uniform sampler2D texture1;
uniform float power;

float map(float value, float min1, float max1, float min2, float max2) {
    return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
}

int modulo(int value, int interval) {
	while (value >= interval) {
		value -= interval;
	}
	return value;
}

vec2 getPos(vec2 uv, float scale, int iter) {
    float shuffle = float(iter / 4);
    vec2 mapped = uv + vec2(shuffle * -5.4894, shuffle * 12.546);
    vec4 color = texture2D(texture1, mapped);

    float x = color[modulo(iter+0, 4)];
    float y = color[modulo(iter+1, 4)];

    return uv + vec2(x,y) * scale;
}

void main() {
    float scale = map(power, 0.0, 1.0, 0.0, 0.12);

    vec4 col = vec4(0.0, 0.0, 0.0, 0.0);
    for (int i = 0; i < ITERATIONS; i++) {
        col += texture2D(texture0, getPos(fragTexCoord, scale, i));
    }

    vec4 outputColor = col / float(ITERATIONS);
    gl_FragColor = vec4(outputColor.xyz, 1.0);
}

Workaround is just declaring a variable. ¯\(ツ)

int ITERATIONS = 8;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants