Jump to content

glsl world space to local space


hfl

Recommended Posts

Hi,
I am trying to transform an geometry from world space to local space in glsl shader, but not get an expected result.

image.png.aa12f0b3a416fefe0a382d3cd383393f.png

What i'm looking for is like what i get in unreal editor.

image.png.cf8e05ab8a7d154684e3de0860df7b2b.png

image.png.3a7faef0ac252c715df38fe23d5c6567.png

 

As described in HDK_ViewportGL3_Intro: "glH_InvObjectMatrix (mat4) - inverse transform matrix for the current object (world->local)".

I thought it may help to accomplish the transform task, but failed.

 

Any help is appreciated!

Thanks in advance!!

 

Vert:

in vec3 P;

uniform mat4    glH_ObjectMatrix;
uniform mat4    glH_ViewMatrix;
uniform mat4    glH_ProjectMatrix;
uniform mat4    glH_InvObjectMatrix;

out parms
{
    vec4  pos;
} vsOut;                       
                       
void main()
{
    vec4 pos;   
    pos = vec4(P, 1.0);
    vsOut.pos = glH_InvObjectMatrix * pos;
    gl_Position  = glH_ProjectMatrix * glH_ViewMatrix * pos;
}

frag:

in wparms
{
    vec4 pos;
} fsIn;

uniform mat4 glH_InvObjectMatrix;

out vec4 color;

void main()
{
    color = vec4(fsIn.pos.xyz, 1.0);
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...