Jump to content
  • Advertisement
Sign in to follow this  
fosh

OpenGL misc glsl stuff

This topic is 5008 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have a couple of questions about glsl. gl_Vertex and gl_Position are vec4's....whats up with that? is it just so you can multiply them by 4x4 matrices? im trying to write a pair of shaders that emulate the standard opengl lighting styles...to generate hilights on a surface, and not having much luck. vertex shader varying float intensity; void main() { vec3 ld = gl_Vertex - vec4(LightPosition) ; intensity = dot(ld,gl_Normal); gl_Position = ftransform() ; } Cant get this to work for a number of reasons, namely the vec3/vec4 thing mentioned above. also, how do you retrieve information about light positions ? im using rendermonkey to mess with these, if it makes any difference... if someone could just point me in the direction of a vertex/pixel shader combo that does that sort of basic lighting, i could take it from there :P cheers Scott

Share this post


Link to post
Share on other sites
Advertisement
The vec4 is coz it has an x, y, z _and_ a w.

If you need to multiplay a vec3 with a mat4x4.. do something like:
vec4(myVec3, 1) * MyMat4x4

The OpenGL lightposisitons you can get from the gl_LightSource array.
gl_LightSource[0].position is position for light 0 and so on.

You could really use the book "OpenGL Shading Language".
It deals with everything GLSL.
There are quite a few examples on 3d-labs site.. and if you use google you find a few more examples/tutorials.

Good luck!

Share this post


Link to post
Share on other sites
its 4 numbers cause they use homogenized coordinates (check out a maths textbook why they do this)
also to use only the xyz part of a vec4 is simple just do
vec3 ll = jj.xyz

Share this post


Link to post
Share on other sites
As gulgi said, get the OpenGL Shading Language book. It even has a chapter on how you would implement features from the fixed function pipeline - including lighting.



Also have a look at 3DLabs' ShaderGen.



dave j

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
cheers guys

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!