- Home /
Dividng clip space by "w" warps the output?
Edit: Thanks to Bunny83 for the explanation. It seems I skipped an important piece of information about projections somewhere along the way and because of that I didn't plan out my approach correctly.
Hello, so I'm writing a special effect and I need the NDC coordinates (the coordinates automatically calculated from clip space coordinates by graphics API). I read that what happens under the hood is a division clipCoord /= clipCoord.w
, however, doing so in the vertex shader warps the result and does other weird things. Am I not understanding something correctly?
Images (upper / only warped image is clipCoord /= abs(clipCoord.w)
): https://imgur.com/a/R6c51uI
Sorry but's it's completely unclear what you're actually doing in your shader. The homogeneous divide will still happen after your shader. The image isn't really helpful either. The floor (or whatever that should be) looks like it has some wrong UV in both images.
The uvs are perfectly fine, all I'm doing in the shader is dividing resulting clip coordinates by w myself (so w is obviously 1 after that) in the vertex shader, this is literally the last step in vertex shader, if I remove that division everything is correct. This is not how I need those coordinates before fragment stage, but it's how I debugged it.
All transforms should keep the w coordinate at 1. It's only the projection matrix that actually modifies w in order to achieve a perspective projection. I explained that over here. Why do you use abs(clipCoord.w) and not clipCoord.w? It would be much easier to help you or to understand your issue if you would provide more information on what "special effect" you're working on and if we could see the relefant parts of your code. Debugging is an inherent part of program$$anonymous$$g. However without the code we can't debug it.
Answer by GrowingTurtle54 · Oct 15, 2020 at 12:22 AM
WOW. I understood absoulutly nothing. This made me realize how much of a newbie I am......
Your answer
Follow this Question
Related Questions
Render object with different shader depending on the camera 2 Answers
Render into cubemap with a camera that has a replacement shader and convert to equirectangular 0 Answers
Render group of objects in front? 0 Answers
Is there a way to render a single object with a unique color per active camera? 1 Answer
Get the screen coordinates of an object altered by Fisheye 0 Answers