Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to get gl_Position.w ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 polyfrag   Crossbones+   -  Reputation: 1825

Like
0Likes
Like

Posted 11 February 2013 - 04:59 AM

I copied the OpenGL ES 2.0 style of specifying vertices with an "attribute vec4 position;" along with other things (is this how it's supposed to be done in OpenGL 4?).

 

But now my shadow mapping is messed up as the shadows aren't effected by the camera's rotation/movement.

 

I think it might be caused by the w component of "position" not matching what it would be in gl_Position.

 

What should I be setting the w component to?

 

Here is my shader code:

 

Vertex shader

attribute vec4 position;

uniform mat4 projection;
uniform mat4 model;
uniform mat4 view;
uniform mat4 modelViewInv;

uniform mat4 lightMatrix;
uniform vec3 lightPos;
uniform vec3 lightDir;

varying vec4 lpos;

attribute vec3 normalIn;
varying vec3 normalOut;

attribute vec2 texCoordIn0;
varying vec2 texCoordOut0;

void main(void)
{
  vec4 vpos = (view * (model * position));
  lpos = lightMatrix * vpos;
  gl_Position = projection * (view * (model * position));

  vec3 normalEyeSpace = vec3( modelViewInv * vec4(normalIn, 0.0) );
  normalOut = normalize(normalEyeSpace);

  texCoordOut0 = texCoordIn0;
}

 

 

Fragment shader


uniform vec4 color;

uniform sampler2D texture0;
uniform sampler2D shadowMap;

varying vec4 lpos;

varying vec2 texCoordOut0;

void main (void)
{
  vec3 smcoord = lpos.xyz / lpos.w;
  float shadow = max(0.5, float(smcoord.z <= texture2D(shadowMap, smcoord.xy).x));

  vec4 texColor = texture2D(texture0, texCoordOut0);

  gl_FragColor = vec4(color.xyz * texColor.xyz * shadow, color.w * texColor.w);
}

 

 



Sponsor:

#2 Sik_the_hedgehog   Crossbones+   -  Reputation: 1608

Like
0Likes
Like

Posted 11 February 2013 - 06:49 AM

What should I be setting the w component to?

1 (the projection matrix will take care about the rest)


Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

#3 polyfrag   Crossbones+   -  Reputation: 1825

Like
0Likes
Like

Posted 11 February 2013 - 08:55 PM

Never mind, got it working.



#4 TheChubu   Crossbones+   -  Reputation: 4138

Like
0Likes
Like

Posted 11 February 2013 - 09:15 PM

I think varying is deprecated. Don't take my word for that though.


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#5 Sik_the_hedgehog   Crossbones+   -  Reputation: 1608

Like
0Likes
Like

Posted 12 February 2013 - 06:53 AM

I think varying is deprecated. Don't take my word for that though.

All uniform, varying and attribute were removed and instead in, out and inout are used. The problem is that GL < 3 only supports the former, while GL >= 3 only supports the latter (compatibility profile aside), unless I misunderstood something, so what keywords you use depends on how much old hardware do you pretend to support.


Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS