Different shaders for geometry, lines and text?
in
Core Library Questions
•
8 months ago
Hi!
I'm trying to add some basic fog effect through the new PShader object. Found this fairly simple glsl shader and adapted to my purposes. I would like to replace only the fragment shader and keep using the "default" vertex shader, but I couldn't find how to do it, so I made a basic vertex shader using the minimum attributes, which fall in the FLAT shader type.
Here is my test code:
The fragment shader:
Cheers!
I'm trying to add some basic fog effect through the new PShader object. Found this fairly simple glsl shader and adapted to my purposes. I would like to replace only the fragment shader and keep using the "default" vertex shader, but I couldn't find how to do it, so I made a basic vertex shader using the minimum attributes, which fall in the FLAT shader type.
Here is my test code:
Copy code
-
PShader fog;
void setup() {
size(640, 360, P3D);
fog = loadShader("fogF.glsl", "fogV.glsl"); - fog.set("fogNear", 0.0);
fog.set("fogFar", 500.0);
hint(DISABLE_DEPTH_TEST);
}
void draw() {
shader(fog);
background(0);
noStroke();
translate(mouseX, mouseY, -100);
box(200);
fill(255,0,0);
box(100);
stroke(255);
strokeWeight(10);
line(0,0,0, width/2, height/2, 100);
line(0,0,0, -width/2, height/2, 100);
text("shader", 100,0,100);
}
Copy code
- uniform mat4 projmodelviewMatrix;
attribute vec4 inVertex;
attribute vec4 inColor;
varying vec4 vColor;
void main() {
// Vertex in clip coordinates
gl_Position = projmodelviewMatrix * inVertex;
vColor = inColor;
}
The fragment shader:
Copy code
- #ifdef GL_ES
precision highp float;
#endif
uniform float fogNear;
uniform float fogFar;
varying vec4 vColor;
void main(){
vec3 fogColor = vec3(1.0,1.0,1.0);
gl_FragColor = vColor;
float depth = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = smoothstep(fogNear, fogFar, depth);
gl_FragColor = mix(gl_FragColor, vec4(fogColor, gl_FragColor.w), fogFactor);
}
Cheers!
2