-5
\$\begingroup\$

In my vertex shader, I'd like to set the w component to 1.

How can this be done, after

gl_Position =  MVP * vec4(vertexPosition_modelspace, 1);
\$\endgroup\$
6
  • 5
    \$\begingroup\$ why do you think you need to? \$\endgroup\$ – ratchet freak Jan 29 '18 at 14:49
  • \$\begingroup\$ I wanted to switch off perspective divide. \$\endgroup\$ – Edward Jan 29 '18 at 19:41
  • 1
    \$\begingroup\$ @Edward - "how do I switch off perspective divide?" might have been a better question then; ask about what you want to do, not how you want to do it. Further reading: meta.stackexchange.com/questions/66377/what-is-the-xy-problem \$\endgroup\$ – Maximus Minimus Jan 29 '18 at 19:46
  • \$\begingroup\$ Then don't use a perspective projection but an orthographic projection matrix instead \$\endgroup\$ – ratchet freak Jan 29 '18 at 20:37
  • \$\begingroup\$ I just wanted to see the effect switching it off had on a perspective projection. Seems to yield very similar results to an orthographic projection, when rendering a simple coloured cube. \$\endgroup\$ – Edward Jan 29 '18 at 22:30
4
\$\begingroup\$

You can use swizzles to access specific coordinates in the vector.

gl_Position.w = 1.0;

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.