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

Trying to write shader with lines from OBJ file #333

Open
snibbe opened this issue Mar 23, 2023 · 4 comments
Open

Trying to write shader with lines from OBJ file #333

snibbe opened this issue Mar 23, 2023 · 4 comments

Comments

@snibbe
Copy link
Sponsor

snibbe commented Mar 23, 2023

Hi,
I'm just getting started with glslViewer (thanks @patriciogonzalezvivo!). I'm trying to work with an OBJ file consisting only of lines, but the lines won't render using a minimal shader. It looks like it might be an issue with the clipping planes and not computing a bounding box for line objects? But I am not certain. Any advice welcome. Minimal files include inline below.
Scott

test.obj:

g body
v   0 0 0 
v 500 0 0
v 500 500 0
v 0 500 0
l 1 2 2 3 3 4 4 1

test.frag:

#ifdef GL_ES
precision mediump float;
#endif

uniform vec3        u_camera;
uniform vec3        u_light;

uniform vec2        u_resolution;
uniform vec2        u_mouse;
uniform float       u_time;

varying vec4        v_position;
varying vec3        v_normal;

#if defined(MODEL_VERTEX_TEXCOORD)
varying vec2        v_texcoord;
#endif

void main(void) {
    vec4 color = vec4(1.0, 0.0, 0.0, 1.0);
    gl_FragColor = color;
}
@patriciogonzalezvivo
Copy link
Owner

Hi @snibbe! So happy and honored seeing you here! Just send you a quick mail, this is one of those cases. GlslViewer geometry loaders mostly know to work with points and triangles at the moment. I usually work with lines them by creating collapsed geometry composed of triangles.
The trick require:

  • creating a spline (a line constructed of triangles). where each pair of vertices at each side of the spline is send to the same position.
  • using the a_texcoord attribute then I extrude it dynamically on the vertex shader.

I know a bit convoluted.
I will try to bring supporting for them when I have some time.

@snibbe
Copy link
Sponsor Author

snibbe commented Mar 23, 2023

I'll use the workaround. Thanks for such a quick answer!

@snibbe
Copy link
Sponsor Author

snibbe commented Mar 23, 2023

If you happen to have an example vertex shader that does this, I would be very grateful if you posted it here. The solution I just tried uses gl_VertexID, but for some reason the glsl version on my Mac in glsViewer is limited to 1.2 and doesn't support gl_VertexID.

@patriciogonzalezvivo
Copy link
Owner

patriciogonzalezvivo commented Mar 23, 2023

I found this example, is slightly different because it encode the direction that the vertex needs to take on the a_normal vertex attribute.

shader.vert

#ifdef GL_ES
precision mediump float;
#endif

uniform mat4    u_projectionViewMatrix;

uniform float   u_radius;
uniform float   u_width;

attribute vec4  a_position;
attribute vec4  a_color;
attribute vec3  a_normal;
attribute vec2  a_texcoord;

varying vec4    v_position;
varying vec4    v_color;
varying vec2    v_texcoord;

void main() {
    v_texcoord = a_texcoord;
    v_position = a_position;
    v_color = a_color;
 
    v_position.xyz += a_normal * u_width;

    gl_Position = u_projectionViewMatrix * v_position;
}

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