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

Unable to access normals in shader #138

Open
azul3d-bot opened this issue Mar 6, 2016 · 2 comments
Open

Unable to access normals in shader #138

azul3d-bot opened this issue Mar 6, 2016 · 2 comments
Labels
Milestone

Comments

@azul3d-bot
Copy link

Issue by oal
Monday Dec 29, 2014 at 19:47 GMT
Originally opened as azul3d-legacy/gfx#87


I pulled v2-dev earlier today, as I couldn't get vertex colors working with v1. Now, colors are working, but I can't seem to access normals in my shader.

Vertex shader:

#version 120

attribute vec3 Vertex;
attribute vec3 Normal;
attribute vec4 Color;

uniform mat4 MVP;
varying vec4 frontColor;
varying vec3 normal;

void main()
{
    normal = Normal;
    frontColor = Color;
    gl_Position = MVP * vec4(Vertex, 1.0);
}

Fragment shader:

#version 120

varying vec4 frontColor;
varying vec3 normal;

void main()
{
    gl_FragColor = frontColor + vec4(normal, 1.0); // just to test
}

I append gfx.Vec3s to mesh.Normals, and I have one normal per vertex. When I try to add the normal to gl_FragColor, the mesh disappears, but when I only use frontColor, it shows up as usual.

Do you have any idea what's wrong?

@azul3d-bot azul3d-bot added this to the Version 2 milestone Mar 6, 2016
@azul3d-bot
Copy link
Author

Comment by slimsag
Monday Dec 29, 2014 at 20:28 GMT


@oal Thank you for testing v2 and for raising this issue, I really appreciate it.

It looks like the previous issue #11 was incorrectly closed, I apologize for this. It looks like the proper code to support this was never added to the gl2 device backend.

You should be able to (even using v1) use a custom vertex attribute in addition to your shader above:

normals := make([]gfx.Vec3, len(mesh.Vertices))
mesh.Attribs["Normals"] = gfx.VertexAttrib{
    Data: normals,
}

If you can share your code via e.g. a GitHub repository (even if it's large) I can dig in further if you need more help.

Side note: v2 is still in development and there are some changes that must be made to gfx.Mesh in order to support WebGL -- so beware that v2 isn't stable yet (in case you did not know).

@azul3d-bot
Copy link
Author

Comment by oal
Monday Dec 29, 2014 at 21:17 GMT


Thanks for your quick response. Using mesh.Attribs works. Yes, I'm aware that v2 isn't stable yet, but my project is still pretty small, so I'm not too worried about breaking changes at the moment. 😄

@slimsag slimsag added the gfx label Mar 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants