GLSL pre-processing step changes names of variables named textureXX to texMapXX #3968

Closed
clankill3r opened this Issue Oct 7, 2015 · 6 comments

Comments

Projects
None yet
3 participants
@clankill3r

The shader doesn't have a uniform called "textureB" OR the uniform was removed during compilation because it was unused.

It's used for sure!

Mac OS X, Processing 3

PShader psBlendLightest;

PGraphics pg;
PGraphics textureB;


void settings() {
  size(512, 512, P2D);
}

void setup() {

  pg = createGraphics(512, 512, P2D);  
  pg.beginDraw();
  pg.background(0);
  pg.fill(255);
  pg.quad(25, 25, 400, 40, 450, 500, 40, 300);
  pg.endDraw();

  textureB = createGraphics(512, 512, P2D); 
  textureB.beginDraw();
  textureB.background(0);
  textureB.fill(255);
  textureB.ellipse(256, 256, 400, 400);
  textureB.endDraw();

  //psBlendLightest = loadShader("http://localhost:8888/shaders/blendLightest.glsl");
  psBlendLightest = new PShader(this, "http://localhost:8888/shaders/blendLightest.vert", "http://localhost:8888/shaders/blendLightest.frag");

}


void draw() {
  image(textureB, 0, 0);  
  psBlendLightest.set("textureB", textureB);
  filter(psBlendLightest);
}

blendLightest.frag

uniform sampler2D texture;
uniform sampler2D textureB;

varying vec4 vertTexCoord;

void main() {
    vec3 texColorA = texture2D(texture, vertTexCoord.xy).rgb;
    vec3 texColorB = texture2D(textureB, vertTexCoord.xy).rgb;
    gl_FragColor = vec4(max(texColorA, texColorB), 1.0);
}

blendLightest.vert

uniform mat4 transform;

attribute vec4 vertex;
attribute vec4 texCoord;

varying vec4 vertTexCoord;

void main() {
    vertTexCoord = vec4(vec2(texCoord.x, 1.0 - texCoord.y), 1.0, 1.0);
    gl_Position = transform * vertex;
}

@codeanticode codeanticode added the opengl label Oct 7, 2015

@codeanticode codeanticode self-assigned this Oct 7, 2015

@codeanticode

This comment has been minimized.

Show comment
Hide comment
@codeanticode

codeanticode Oct 7, 2015

Member

I see. This is the result of Processing automatically replacing the instances of "texture" because the GLSL version supported by your hardware is 1.30 or higher, and all the textureXXX() functions are just called texture(). The textureB uniform should be getting renamed as texMapB. What happens if you add #version 120 to your shaders?

@JakubValtar this and #3961 makes think we need a better way to deal different GLSL versions.

Member

codeanticode commented Oct 7, 2015

I see. This is the result of Processing automatically replacing the instances of "texture" because the GLSL version supported by your hardware is 1.30 or higher, and all the textureXXX() functions are just called texture(). The textureB uniform should be getting renamed as texMapB. What happens if you add #version 120 to your shaders?

@JakubValtar this and #3961 makes think we need a better way to deal different GLSL versions.

@clankill3r

This comment has been minimized.

Show comment
Hide comment
@clankill3r

clankill3r Oct 7, 2015

Cannot compile vertex shader:ERROR: 0:1: ": version '120' is not supportedERROR: 0:2: ": #version required and missing.ERROR:0:5: 'attribute' :syntax error: syntax error

Cannot compile vertex shader:ERROR: 0:1: ": version '120' is not supportedERROR: 0:2: ": #version required and missing.ERROR:0:5: 'attribute' :syntax error: syntax error

@JakubValtar

This comment has been minimized.

Show comment
Hide comment
@JakubValtar

JakubValtar Oct 7, 2015

Contributor

I'm taking note to handle this in fixed preprocessor.

On Wed, 7 Oct 2015 17:01 Doeke Wartena notifications@github.com wrote:

Cannot compile vertex shader:ERROR: 0:1: ": version '120' is not
supportedERROR: 0:2: ": #version required and missing.ERROR:0:5:
'attribute' :syntax error: syntax error


Reply to this email directly or view it on GitHub
#3968 (comment)
.

Contributor

JakubValtar commented Oct 7, 2015

I'm taking note to handle this in fixed preprocessor.

On Wed, 7 Oct 2015 17:01 Doeke Wartena notifications@github.com wrote:

Cannot compile vertex shader:ERROR: 0:1: ": version '120' is not
supportedERROR: 0:2: ": #version required and missing.ERROR:0:5:
'attribute' :syntax error: syntax error


Reply to this email directly or view it on GitHub
#3968 (comment)
.

@clankill3r

This comment has been minimized.

Show comment
Hide comment
@clankill3r

clankill3r Oct 7, 2015

Should this be ok? It does run but I don't get the excepted blend LIGHTEST result and I'm a bit lost on what are my bugs and what are processings :) .

PShader psBlendLightest;

PGraphics pg;
PGraphics textureB;


void settings() {
  size(512, 512, P2D);
}

void setup() {

  pg = createGraphics(512, 512, P2D);  
  pg.beginDraw();
  pg.background(0);
  pg.fill(255);
  pg.quad(25, 25, 400, 40, 450, 500, 40, 300);
  pg.endDraw();

  textureB = createGraphics(512, 512, P2D); 
  textureB.beginDraw();
  textureB.background(0);
  textureB.fill(255);
  textureB.ellipse(256, 256, 400, 400);
  textureB.endDraw();

  //psBlendLightest = loadShader("http://localhost:8888/shaders/blendLightest2.glsl");
  psBlendLightest = new PShader(this, "http://localhost:8888/shaders/blendLightest2.vert", "http://localhost:8888/shaders/blendLightest2.frag");

}

void draw() {
  image(textureB, 0, 0);  
  psBlendLightest.set("texMapB", textureB);
  filter(psBlendLightest);
}

// vert shader

#version 410

uniform mat4 transform;

in vec4 vertex;
in vec4 color;
in vec4 texCoord;

out vec4 vertColor; 
out vec4 vertTexCoord;

void main() {
    gl_Position = transform * vertex;
    vertColor = color;
    vertTexCoord = texCoord;
}

frag shader:

#version 410

uniform sampler2D texture;
uniform sampler2D texMapB;

in vec4 vertTexCoord;

out vec4 fragColor; 

void main() {
    fragColor = max(texture(texture, vertTexCoord.xy).rgba, texture(texMapB, vertTexCoord.xy).rgba);
}

Should this be ok? It does run but I don't get the excepted blend LIGHTEST result and I'm a bit lost on what are my bugs and what are processings :) .

PShader psBlendLightest;

PGraphics pg;
PGraphics textureB;


void settings() {
  size(512, 512, P2D);
}

void setup() {

  pg = createGraphics(512, 512, P2D);  
  pg.beginDraw();
  pg.background(0);
  pg.fill(255);
  pg.quad(25, 25, 400, 40, 450, 500, 40, 300);
  pg.endDraw();

  textureB = createGraphics(512, 512, P2D); 
  textureB.beginDraw();
  textureB.background(0);
  textureB.fill(255);
  textureB.ellipse(256, 256, 400, 400);
  textureB.endDraw();

  //psBlendLightest = loadShader("http://localhost:8888/shaders/blendLightest2.glsl");
  psBlendLightest = new PShader(this, "http://localhost:8888/shaders/blendLightest2.vert", "http://localhost:8888/shaders/blendLightest2.frag");

}

void draw() {
  image(textureB, 0, 0);  
  psBlendLightest.set("texMapB", textureB);
  filter(psBlendLightest);
}

// vert shader

#version 410

uniform mat4 transform;

in vec4 vertex;
in vec4 color;
in vec4 texCoord;

out vec4 vertColor; 
out vec4 vertTexCoord;

void main() {
    gl_Position = transform * vertex;
    vertColor = color;
    vertTexCoord = texCoord;
}

frag shader:

#version 410

uniform sampler2D texture;
uniform sampler2D texMapB;

in vec4 vertTexCoord;

out vec4 fragColor; 

void main() {
    fragColor = max(texture(texture, vertTexCoord.xy).rgba, texture(texMapB, vertTexCoord.xy).rgba);
}
@codeanticode

This comment has been minimized.

Show comment
Hide comment
@codeanticode

codeanticode Oct 7, 2015

Member

You need to draw your pg object first, the texture sampler in a filter shader is filled with the contents of the screen at the moment the function filter() is called:

void draw() {
  image(pg, 0, 0);
  psBlendLightest.set("texMapB", textureB);
  filter(psBlendLightest);
}

But this is a topic for further discussion in the forum.

Member

codeanticode commented Oct 7, 2015

You need to draw your pg object first, the texture sampler in a filter shader is filled with the contents of the screen at the moment the function filter() is called:

void draw() {
  image(pg, 0, 0);
  psBlendLightest.set("texMapB", textureB);
  filter(psBlendLightest);
}

But this is a topic for further discussion in the forum.

@codeanticode codeanticode changed the title from uniform sampler2D get's optimized away to GLSL pre-processing step changes names of variables named textureXX to texMapXX Oct 7, 2015

@clankill3r

This comment has been minimized.

Show comment
Hide comment
@clankill3r

clankill3r Oct 7, 2015

Thanks, I need sleep :)

Thanks, I need sleep :)

JakubValtar added a commit to JakubValtar/processing that referenced this issue Oct 23, 2015

@benfry benfry closed this in #4052 Oct 23, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment