Jump to content
  • Advertisement
Sign in to follow this  
Owenx92

OpenGL WorldViewProj?

This topic is 2614 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

Hello,
First, sorry for my bad English..

I have question about GLSL,
I have a HLSL shader, In this shader, I use a World and a WorldViewProj matrices.
In DirectX, I can easily get these Matrices with this codes;

World:

D3DXMatrixIdentity(&World);

View:
D3DXMatrixLookAtLH(&View, &Position, &Target, &Up);

Proj:
D3DXMatrixPerspectiveFovLH( &Proj, D3DX_PI /4, ScreenWidth / ScreenHeight, 1.0f, 1000.0f );

WorldViewProj:
World * View * Proj

I've converted my HLSL shader to GLSL with "HLSL2GLSL" tool.
My shader compiles with no errors. But I need this matrices to use my shader..
And I don't know how to get these Matrices in OpenGL.. sad.gif

I've searched but I couldn't find a solution.
Can anyone tell me how can I get these matrices in OpenGL?

Share this post


Link to post
Share on other sites
Advertisement
[color="#FF0000"] D3DXMatrixIdentity(&World); --> [color="#2E8B57"]glLoadIdentity(....

[color="#FF0000"]D3DXMatrixLookAtLH(&View, &Position, &Target, &Up); --> [color="#2E8B57"]gluLookAt(...

[color="#FF0000"]D3DXMatrixPerspectiveFovLH -->[color="#2E8B57"]gluPerspective(....

[color="#FF0000"]World * View * Proj --> [color="#2E8B57"]MODELVIEW * PROJECTION

Share this post


Link to post
Share on other sites
Depends on the opengl version. Older versions of opengl provided them as built in uniforms, in the newer versions of opengl you have to calculate them yourself and pass them to the shader. Most math libs built with graphics in mind should have calls to calculate them.

Share this post


Link to post
Share on other sites
See my link. Look for functions like glhLoadIdentityf2.
Build your matrix and upload to your shader.

Share this post


Link to post
Share on other sites

See my link. Look for functions like glhLoadIdentityf2.
Build your matrix and upload to your shader.



I think this library is for Windows, but i'm using Linux :(

------

I have some matrices in GLSL shader..
For example:
gl_ModelViewProjectionMatrix
gl_ModelViewMatrix
gl_Vertex

What is ModelView Matrix?? is that same with ViewMatrix in DX?
Ok, I think gl_ModelViewProjectionMatrix is WorldViewProj matrix, is it right?

But how can I get the World matrix?

A part of my Shader is like this.. very simple..

---------------------------------------------------------------------------------------------------------------
uniform vec4 LightColor;
uniform vec4 LightPosition;
uniform vec4 MatColor;
uniform mat4 World;
uniform mat4 WorldViewProjection;


void VS( in A2V IN, out V2P OUT ) {

OUT.Pos = [color="#ff0000"]I NEED HELP HERE.. (in DX, it is mul(IN.Position, WorldViewProj); )
OUT.WorldPos = [color="#ff0000"]I NEED HELP HERE TOO.. (in DX it is mul(IN.Position, World); )
OUT.LightDir = vec3( (LightPosition - OUT.WorldPos));
OUT.WorldNormal = normalize( ( IN.Normal * xlat_lib_constructMat3( World) ) );
OUT.Diffuse = (MatColor * LightColor);
OUT.TexCoord0 = IN.Tex0;
}
---------------------------------------------------------------------------------------------------------------

Share this post


Link to post
Share on other sites
Regarding the terminology, with the fixed-function pipeline, the 'world' matrix in D3D corresponds to the 'model' matrix in OpenGL, so:

D3D: world->view->projection
OpenGL: model->view->projection

Furthermore, OpenGL collapses the model and view matrices into a single 'modelview' matrix, whereas D3D keeps the world and view matrices separate, so:

D3D: world->view->projection
OpenGL: modelview->projection

With modern shader code, all of this disappears and you just construct and use whatever matrices you need. Typically there'll still be 'model', 'view', and 'projection' transforms in one form or another, but which ones you upload and what you do with them exactly is up to you. (That said, the simplest possible vertex program will typically transform all incoming geometry by a single matrix that represents a concatenation of the model/world, camera/view, and projection transforms.)

Share this post


Link to post
Share on other sites
Ok, Its working smile.gif

I used so, and I don't need Model Matrix anymore smile.gif
-------------------------------

OUT.Pos = gl_ModelViewProjectionMatrix * gl_Vertex;
OUT.WorldPos = gl_ModelViewMatrix * gl_Vertex;
OUT.LightDir = LightPosition - OUT.WorldPos;
OUT.WorldNormal = normalize(gl_NormalMatrix * gl_Normal);
OUT.Diffuse = LightColor;
OUT.TexCoord0 = IN.Tex0;
-------------------------------

Thanks guys..

Share this post


Link to post
Share on other sites
The only problem with that is that you are using built in variables. Why don't you use a math library instead?
From http://opengl.org/wiki/Related_toolkits_and_APIs, there is the GLM library that is available for *nix. It is object orientated (compared to mine which is a C library). I don't like the OO approach but have a look. There are a lot of others too if you look at the big list at http://www.gamedev.net/topic/339189-unofficial-alternative-game-libraries-faq-updated-20308/

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!