jit.gl.mesh with jit.gl.shader
Hi there,
I am trying to make some first steps with OpenGL Shaders. At the beginning i have a patch with a jit.gl.mesh object. It contains 3 Lines with different colors on the end and a line_width set to 2. The Output looks how it is expected:
In the next Step i have tried to write a shader which does contain vertex, geometry and fragment shaders:
And i added a jit.gl.shader object to use with jit.gl.mesh.
So how you can See the results between the patch without and with the shader looks different:
The @line_width argument of jit.gl.mesh seems not to work with the shader.
The transition of the color from one Vertex to another Vertex does not Work with the shader.
I guess the Problems are in my Shader Code. I would be glad when someone could take a look on my shader Code and give me some hints.
Best Regards,
C.
You can send a get_gl3_shader
to your [jit.gl.mesh] to get the actual shader and start from here.
You should get something like below. Oh and mind that this shader shoud change depending on your [jit.gl.mesh] attributes. So if you want to dynamicaly change some attributes (let's say the draw mode) with your custom shader, make sure to export the built-in shader for any situation and re-assemble everything yourself.
<jittershader name="linewidth-flat-line_strip-color_vao">
<description>
An auto-generated shader for simulating deprecated OpenGL features in OpenGL 3.2+
</description>
<param name="position" type="vec3" state="POSITION" />
<param name="modelViewProjectionMatrix" type="mat4" state="MODELVIEW_PROJECTION_MATRIX" />
<param name="color" type="vec4" state="COLOR" />
<param name="viewport" type="vec2" state="VIEWPORT" />
<param name="line_width" type="float" state="LINE_WIDTH" />
<language name="glsl" version="1.5">
<bind param="position" program="vp" />
<bind param="modelViewProjectionMatrix" program="vp" />
<bind param="color" program="vp" />
<bind param="viewport" program="gp" />
<bind param="line_width" program="gp" />
<program name="vp" type="vertex">
<![CDATA[
// Preprocessor
#version 330 core
// Definitions
// Uniforms
uniform mat4 modelViewProjectionMatrix;
// Attributes
in vec3 position;
in vec4 color;
// Output
out jit_PerVertex {
flat vec4 color;
} jit_out;
// Library functions
void main() {
vec4 pos4 = vec4(position.xyz, 1.);
gl_Position = modelViewProjectionMatrix * pos4;
jit_out.color = color;
}
]]>
</program>
<program name="gp" vertices_out="4" input_type="lines" output_type="triangle_strip" type="geometry">
<![CDATA[
#version 330 core
layout( lines ) in;
layout( triangle_strip, max_vertices = 4 ) out;
in jit_PerVertex {
flat vec4 color;
} jit_in[];
out jit_PerVertex {
flat vec4 color;
};
uniform float line_width;
uniform vec2 viewport;
vec2 toScreenSpace( vec4 vertex )
{
return vec2( vertex.xy / vertex.w ) * viewport;
}
vec4 toWorldSpace( vec4 vertex )
{
return vec4(( vertex.xy * vertex.w ) / viewport, vertex.zw);
}
void main() {
vec2 p0 = toScreenSpace( gl_in[0].gl_Position );
vec2 p1 = toScreenSpace( gl_in[1].gl_Position );
vec2 v0 = normalize( p1 - p0 );
vec2 n0 = vec2( -v0.y, v0.x ) * line_width;
gl_Position = toWorldSpace(vec4( ( p0 + n0 ), gl_in[0].gl_Position.zw ));
color = jit_in[0].color;
EmitVertex();
gl_Position = toWorldSpace(vec4( ( p0 - n0 ), gl_in[0].gl_Position.zw ));
color = jit_in[0].color;
EmitVertex();
gl_Position = toWorldSpace(vec4( ( p1 + n0 ), gl_in[1].gl_Position.zw ));
color = jit_in[1].color;
EmitVertex();
gl_Position = toWorldSpace(vec4( ( p1 - n0 ), gl_in[1].gl_Position.zw ));
color = jit_in[1].color;
EmitVertex();
EndPrimitive();
}
]]>
</program>
<program name="fp" type="fragment">
<![CDATA[
#version 330 core
in jit_PerVertex {
flat vec4 color;
} jit_in;
out vec4 color;
void main() {
color = jit_in.color;
}
]]>
</program>
</language>
</jittershader>
Alright. Thanks!
All good now? Any update?
Yes, i got my shader to work.