We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello! its me again. im in a hardest process of learning GLSL. As i can see, exist many types of sintaxis and versions for writing a shader program and its a little bit confuse writing a shader for Processing. In this time, i`ve two questions.
1) im reading OpenGl 4.0 Shading Lenguaje Cookbook. One of the first examples, use it a block of uniforms. How do i set a uniform block in Processing? cos if i set one by one it doesnt work.
in fragment shader;
uniform BlobSettings {
vec4 InnerColor;
vec4 OuterColor;
float RadiusInner;
float RadiusOuter;
};
In processing:
sh.set("RadiusOuter", 10.0 );
sh.set("RadiusInner", 20.0 );
sh.set("InnerColor", c);
sh.set("OuterColor", b);
2) Following this light house tutorial http://www.lighthouse3d.com/tutorials/glsl-tutorial/texture-coordinates/ im trying to do the example of textCoord, and it doesnt work... here the code:
PShader sh;
PShape t;
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.*;
PeasyCam cam;
void setup(){
cam = new PeasyCam(this, 800);
size(500,500, P3D);
t = trian();
sh = loadShader("basicShaderFrag.glsl", "basicShader.glsl");
}
void draw(){
background(0);
shader(sh);
shape(t);
}
PShape trian (){
PShape t = createShape();
t.beginShape(QUAD_STRIP);
// t.fill(random(255),0,0);
t.vertex(-200, -200);
// t.fill(0,255,0);
t.vertex(-200, 200);
// t.fill(0,0,255);
t.vertex(200,-200);
t.vertex(200, 200);
t.endShape();
return t;
}
vertexShader:
#version 330
uniform mat4 transform;
in vec4 position;
in vec3 color;
in vec2 texCoord;
out vec3 vertColor;
out vec2 TexCoord;
void main(){
TexCoord = texCoord;
vertColor = color;
gl_Position = transform * position;
}
fragmentShader:
#ifdef GL_ES
precision mediump float;
#endif
in vec3 vertColor;
in vec2 TexCoord;
void main() {
gl_FragColor = vec4(TexCoord,1.0,1.0);
}
was suppossed to be this result:
http://www.lighthouse3d.com/wp-content/uploads/2013/02/texturecoordinates.jpg
but its only a blue rect. and its becouse TexCoord value is 0 and im lost why... how fragCoord works?
thanks.
Answers
1.)
you have to use low level jogl mode. no uniform blocks in processing.
2.)
https://processing.org/reference/vertex_.html
vertex(x, y, z, u, v)
Note: your fragmentShader no version means in processing #version 100 (es) so ifdef GL_ES only needed if you want to target OpenGL ES Version 2.0
https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_03#OpenGL_ES_2_portability
your vertexShader:
#version 330 so you targeting different versions. And it still work. Thx Java!
their is a compatibility vs core preprocessor directive behind the scenes you can add it if you like for whatever reason
#version 330 compatibility
#version 330 core
https://jogamp.org/jogl/doc/Overview-OpenGL-Evolution-And-JOGL.html
the default processing is GL2ES2
https://github.com/processing/processing/wiki/Advanced-OpenGL
how fragCoord works? google it, their are much greater tutorials and explanation as i got time :)
Yes just to be complete:
#version 100
is becoming #version 300 es in OpenGL ES Version 3.0
this old back then (~10years) smartphones coming slowly to regular use. that is why you use ifdef GL_ES with #version 120 and in the newer versions only es But their are still quite few older smartphones around that only support OpenGL ES Version 2.0. So if you programing a simpel Game, and not the next Battelfield Game for Android you want to program in GL2ES2 and check ifdef GL_ES (Not for WEBGL) My smartphone is 5years old, i just use it to make a call, so i got max OpenGL ES Version 3.1
Also note that on the CPU side in JOGL the things are changing too. So it's not only the shader version.
And that is why your question is self explaining, becourse GL2ES2 has no Uniform Blocks.
update a progress, maybe it help anybody:
(thanks @nabr, im gonna to drive you insane);
Ok, so after hours and hours (think im a little bit stupid) i made a little progress with shaders and processing. I finally could use the texCoord in lightHouse tutorial:
processing:
vertexShader:
version 150
fragmentShader:
what happens me now is that i cant found the center of the QUAD, im trying following bookofShader algorithm:
in fragment:
result:
what im doing wrong? maybe set the UV coordinates in vertex? follow my instint, dont know exactly what that numbers mean. any suggestion?
EDIT:
got it, but still dont get it;
change the UV coordinate.
@vjjv Hello
man what can i say, remember learing all this stuff, i look at your code and i know - you skip the very basics and now you are running in some "bugs".
Read a very basic hello triangle: line by line and experiment with it for 1 or two weeks :)
https://learnopengl.com/#!Getting-started/Hello-Triangle ( skip the C++ Code )
off course @narbs. Thanks!