passing variables to GLSL
-
-
I have been working with GLSL for a couple days and I understand the basic concept. I know how to get specific values from my openGL applicaiton to the shader but I don't know how to pass in my own variables. I appreciate your help with this problem.
Could you be more specific, please? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Could you be more specific, please? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]I know that values such as light position can be passed into either the fragment shader or the vertex shader using gl_lightsource, but what if I wanted to use a variable from my code such as an eye vector for a phong equation. In the information on GLSL I have read I have not seen a mention as to how to do something like this. All I have seen is being able to pass data in that would normally be used in OpenGL's lighting model, such as the functions glMaterialfv and glLightfv. I hope this better explains my problem.
-
I know that values such as light position can be passed into either the fragment shader or the vertex shader using gl_lightsource, but what if I wanted to use a variable from my code such as an eye vector for a phong equation. In the information on GLSL I have read I have not seen a mention as to how to do something like this. All I have seen is being able to pass data in that would normally be used in OpenGL's lighting model, such as the functions glMaterialfv and glLightfv. I hope this better explains my problem.
Been a couple years but IIRC ... If you have a vertex shader with: attribute float myAttrib; Then in the C++ source you would: GLint loc = glGetAttribLocation(progId, "myAttrib"); or, GLint loc = 20; glBindAttribLocation(progId, loc, "myAttrib"); then to set myAttrib, glVertexAttrib1f(loc, 0.432); So you can set per-vertex in C++ and read (only) in shader. ... uniforms are similar. If you want to bind then do so after glAttachShader and before glLinkProgram. I think OpenGL 3+ changes the above slightly, haven't gotten up to speed on it yet.
...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack
-
Been a couple years but IIRC ... If you have a vertex shader with: attribute float myAttrib; Then in the C++ source you would: GLint loc = glGetAttribLocation(progId, "myAttrib"); or, GLint loc = 20; glBindAttribLocation(progId, loc, "myAttrib"); then to set myAttrib, glVertexAttrib1f(loc, 0.432); So you can set per-vertex in C++ and read (only) in shader. ... uniforms are similar. If you want to bind then do so after glAttachShader and before glLinkProgram. I think OpenGL 3+ changes the above slightly, haven't gotten up to speed on it yet.
...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack
-
Thank you, this has been very helpful, I just have one more question; what about vec3, vec4, etc. This might be a stupid question, there might be a data structure in opengl that can handle data from these types, but what do i do about these data types?
glBindAttrib*() has versions that accept all types of values. See examples at: http://www.lighthouse3d.com/opengl/glsl/index.php?ogluniform[^]
...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack
modified on Wednesday, April 21, 2010 2:29 PM