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

  • Home
  • SEARCH
  • 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 9153975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:21:31+00:00 2026-06-17T12:21:31+00:00

I am working on my own deffered rendering engine. I am rendering the scene

  • 0

I am working on my own deffered rendering engine. I am rendering the scene to the g-buffer containing diffuse color, view space normals and depth (for now). I have implemented directional light for the second rendering stage and it works great. Now I want to render a point light, which is a bit harder.

I need the point light position for the shader in view space because I have only depth in the g-buffer and I can’t afford a matrix multiplication in every pixel. I took the light position and transformed it by the same matrix, by which I transform every vertex in shader, so it should align with verices in the scene (using D3DXVec3Transform). But that isn’t the case: transformed position doesn’t represent viewspace position nearly at all. It’s x,y coordinates are off the charts, they are often way out of the (-1,1) range. The transformed position respects the camera orientation somewhat, but the light moves too quick and the y-axis is inverted. Only if the camera is at (0,0,0), the light stands at (0,0) in the center of the screen. Here is my relevant rendering code executed every frame:

D3DXMATRIX matView;    // the view transform matrix
D3DXMATRIX matProjection;    // the projection transform matrix

D3DXMatrixLookAtLH(&matView,
                   &D3DXVECTOR3 (x,y,z),    // the camera position
                   &D3DXVECTOR3 (xt,yt,zt),    // the look-at position
                   &D3DXVECTOR3 (0.0f, 0.0f, 1.0f));    // the up direction

D3DXMatrixPerspectiveFovLH(&matProjection,
                           fov,    // the horizontal field of view
                           asp,    // aspect ratio
                           znear,    // the near view-plane
                           zfar);    // the far view-plane

D3DXMATRIX vysl=matView*matProjection;

eff->SetMatrix("worldViewProj",&vysl); //vertices are transformed ok ín shader

//render g-buffer

D3DXVECTOR4 lpos; D3DXVECTOR3 lpos2(0,0,0);

D3DXVec3Transform(&lpos,&lpos2,&vysl); //transforming lpos into lpos2 using vysl, still the same matrix
eff->SetVector("poslight",&lpos); //but there is already a mess in lpos at this time

//render the fullscreen quad with wrong lighting

Not that relevant shader code, but still, I see the light position this way (passing IN.texture is just me being lazy):

float dist=length(float2(IN.texture0*2-1)-float2(poslight.xy));
OUT.col=tex2D(Sdiff,IN.texture0)/dist;

I have tried to transform a light only by matView without projection, but the problem is still the same. If I transform the light in a shader, it’s the same result, so the problem is the matrix itself. But it is the same matrix as is transforming the vertices! How differently are vertices treated?

Can you please take a look at the code and tell me where the mistake is? It seems to me it should work ok, but it doesn’t. Thanks in advance.

  • 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-06-17T12:21:31+00:00Added an answer on June 17, 2026 at 12:21 pm

    You don’t need a matrix multiplication to reconstruct view position, here is a code snippet (from andrew lauritzen deffered light example)

    tP is the projection transform, position screen is -1/1 pixel coordinate and viewspaceZ is linear depth that you sample from your texture.

    float3 ViewPosFromDepth(float2 positionScreen,
                                float viewSpaceZ)
    {
        float2 screenSpaceRay = float2(positionScreen.x / tP._11,
                                   positionScreen.y / tP._22);
    
        float3 positionView;
        positionView.z = viewSpaceZ;
        positionView.xy = screenSpaceRay.xy * positionView.z;
    
        return positionView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on my own tile bliting engine, this one is using hexagonal tiles
I've been working on my own implementation of ECMAScript for quite some time now.
I writing my own text editor plugin for eclipse. I am now working on
I am working on my own storage engine for MySQL. So far this storage
Here's the scene: I'm currently working on my own framework and on a client's
I'm working on my own toy programming language. For now I'm interpreting the source
I'm working on my own chess engine in C#. Actually I'm searching bugs on
I'm currently working on my own little online pixel editor. Now I'm trying to
I've been working on my own personal JavaScript library for a while now, and
I am working on my own Lorem Ipsum generator, with the added bonus of

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.