Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 452357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:03:52+00:00 2026-05-12T22:03:52+00:00

From this site: http://www.catalinzima.com/?page_id=14 I’ve always been confused about how the depth map is

  • 0

From this site: http://www.catalinzima.com/?page_id=14

I’ve always been confused about how the depth map is calculated.

The vertex shader function calculates position as follows:

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)

{

    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);

    float4 viewPosition = mul(worldPosition, View);

    output.Position = mul(viewPosition, Projection);

    output.TexCoord = input.TexCoord;                            //pass the texture coordinates further

    output.Normal =mul(input.Normal,World);                   //get normal into world space

    output.Depth.x = output.Position.z;

    output.Depth.y = output.Position.w;

    return output;

}

What are output.Position.z and output.Position.w? I’m not sure as to the maths behind this.

And in the pixel shader there is this line: output.Depth = input.Depth.x / input.Depth.y;

So output.Depth is output.Position.z / outputPOsition.w? Why do we do this?

Finally in the point light shader (http://www.catalinzima.com/?page_id=55) to convert this output to be a position the code is:

 //read depth

    float depthVal = tex2D(depthSampler,texCoord).r;

    //compute screen-space position

    float4 position;

    position.xy = input.ScreenPosition.xy;

    position.z = depthVal;

    position.w = 1.0f;

    //transform to world space

    position = mul(position, InvertViewProjection);

    position /= position.w;

again I don’t understand this. I sort of see why we use InvertViewProjection as we multiply by the view projection previously, but the whole z and now w being made to equal 1, after which the whole position is divided by w confuses me quite a bit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:03:52+00:00Added an answer on May 12, 2026 at 10:03 pm

    To understand this completely, you’ll need to understand how the algebra that underpins 3D transforms works. SO does not really help (or I don’t know how to use it) to do matrix math, so it’ll have to be without fancy formulaes. Here is some high level explanation though:

    If you look closely, you’ll notice that all transformations that happen to a vertex position (from model to world to view to clip coordinates) happens to be using 4D vectors. That’s right. 4D. Why, when we live in a 3D world ? Because in that 4D representation, all the transformations we usually want to do to vertices are expressible as a matrix multiplication. This is not the case if we stay in 3D representation. And matrix multiplications are what a GPU is good at.

    What does a vertex in 3D correspond to in 4D ? This is where it gets interesting. The (x, y, z) point corresponds to the line (a.x, a.y, a.z, a). We can grab any point on this line to do the math we need, and we usually pick the easiest one, a=1 (that way, we don’t have to do any multiplication, just set w=1).

    So that answers pretty much all the math you’re looking at. To project a 3D point in 4D we set w=1, to get back a component from a 4D vector, that we want to compare against our standard sizes in 3D, we have to divide that component by w.

    This coordinate system, if you want to dive deeper, is called homogeneous coordinates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get information from this site: http://www.gocrimson.com/sports/mbkb/2011-12/roster If you look at that
from this site there is header compress.h http://www.fredosaurus.com/notes-cpp/examples/compress/compress.html i am using visual c++ 2010
I have downloaded the sample code from this site for FTP Client http://www.lysesoft.com/products/andftp/index.html But
using code from this site: http://www.saltycrane.com/blog/2008/09/simplistic-python-thread-example/ The code is import time from threading import
I downloaded the font from this site: http://www.fontsquirrel.com/fonts/Hattori-Hanzo Here's my code: <style type=text/css> @font-face
From this site (http://www.ipv6.com/articles/general/IPv6-Header.htm) , it says: Packet priority/Traffic class (8 bits) The 8-bit
I got this code from this site: http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx But I'm just a beginner so
I have replicated a toggle functionality from this site: http://www.williamsprofessionalpainting.com/FAQ.php Here is the updated
I am using a CSS Tree Menu from this site: http://www.thecssninja.com/css/css-tree-menu I can't seems
So I am trying to implement the repeating feature from this site - http://www.java2s.com/Code/Android/Core-Class/Exampleofschedulingoneshotandrepeatingalarms.htm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.