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 9079157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:46:44+00:00 2026-06-16T19:46:44+00:00

i’m having difficulties understanding the math between the different shader stages. in the fragment

  • 0

i’m having difficulties understanding the math between the different shader stages.

in the fragment shader from the lights perspective i basically write out the fragDepth to rgb color

#version 330

out vec4 shader_fragmentColor;

void main()
{
    shader_fragmentColor = vec4(gl_FragCoord.z, gl_FragCoord.z, gl_FragCoord.z, 1);
    //shader_fragmentColor = vec4(1, 0.5, 0.5, 1);
}

when rendering the scene using the above shader it displays the scene in an all white color. i suppose thats because gl_FragCoord.z is bigger than 1. hopefully its not maxed out at 1. but we can leave that question alone for now.

in the geometry shader from the cameras perspective i basicly turn all points into quads and write out the probably “incorrect” texture position to lookup in the lightTexture. the math here is the question. im also a bit unsure about if the interpolation value will be correct in the next shader stage.

#version 330
#extension GL_EXT_geometry_shader4 : enable

uniform mat4 p1_modelM;
uniform mat4 p1_cameraPV;
uniform mat4 p1_lightPV;

out vec4 shader_lightTexturePosition;

void main()
{
    float s = 10.00;

    vec4 llCorner = vec4(-s, -s, 0.0, 0.0);
    vec4 llWorldPosition = ((p1_modelM * llCorner) + gl_in[0].gl_Position);
    gl_Position = p1_cameraPV * llWorldPosition;
    shader_lightTexturePosition = p1_lightPV * llWorldPosition;
    EmitVertex();

    vec4 rlCorner = vec4(+s, -s, 0.0, 0.0);
    vec4 rlWorldPosition = ((p1_modelM * rlCorner) + gl_in[0].gl_Position);
    gl_Position = p1_cameraPV * rlWorldPosition;
    shader_lightTexturePosition = p1_lightPV * rlWorldPosition;
    EmitVertex();

    vec4 luCorner = vec4(-s, +s, 0.0, 0.0);
    vec4 luWorldPosition = ((p1_modelM * luCorner) + gl_in[0].gl_Position);
    gl_Position = p1_cameraPV * luWorldPosition;
    shader_lightTexturePosition = p1_lightPV * luWorldPosition;
    EmitVertex();

    vec4 ruCorner = vec4(+s, +s, 0.0, 0.0);
    vec4 ruWorldPosition = ((p1_modelM * ruCorner) + gl_in[0].gl_Position);
    gl_Position = p1_cameraPV * ruWorldPosition;
    shader_lightTexturePosition = p1_lightPV * ruWorldPosition;
    EmitVertex();

    EndPrimitive();
}

in the fragment shader from the cameras perspective i basicly lookup in the lightTexture what color would be shown from the lights perspecive and write out the same color.

#version 330

uniform sampler2D p1_lightTexture;

in vec4 shader_lightTexturePosition;

out vec4 shader_fragmentColor;

void main()
{
    vec4 lightTexel = texture2D(p1_lightTexture, shader_lightTexturePosition.xy);
    shader_fragmentColor = lightTexel;
    /*
    if(lightTexel.x < shader_lightTexturePosition.z)
        shader_fragmentColor = vec4(1, 0, 0, 1);
    else
        shader_fragmentColor = vec4(0, 1, 0, 1);
    */
    //shader_fragmentColor = vec4(1, 1, 1, 1);
}

when rendering from the cameras perspective i see the scene drawn as it should but with the incorrect texture coordinates applied on them that repeats. repeating texture is probably caused by the texture-coordinate being outside the bounds of 0 to 1.

I’ve tried several things but still fail to understand what the math should be. some of out commented code and one example im unsure of is:

shader_lightTexturePosition = normalize(p1_lightPV * llWorldPosition) / 2 + vec4(0.5, 0.5, 0.5, 0.5);

for the lower-left corner. similair code to the other corners

from the solution i expect the scene to be rendered from the cameras perspective with exactly the same color as from the lights perspective. with perhaps some precision error.

  • 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-16T19:46:47+00:00Added an answer on June 16, 2026 at 7:46 pm

    i figured out the texture mapping bit myself. the depth value bit is still a bit strange.
    convert the screenProjectedCoords to normalizedDeviceCoords then add 1 divide by 2.

    vec4 textureNormalizedCoords(vec4 screenProjected)
    {
        vec3 normalizedDeviceCoords = (screenProjected.xyz / screenProjected.w);
        return vec4( (normalizedDeviceCoords.xy + 1.0) / 2.0, screenProjected.z * 0.005, 1/screenProjected.w);
    }
    
    void main()
    {
        float s = 10.00;
    
        vec4 llCorner = vec4(-s, -s, 0.0, 0.0);
        vec4 llWorldPosition = ((p1_modelM * llCorner) + gl_in[0].gl_Position);
        gl_Position = p1_cameraPV * llWorldPosition;
        shader_lightTextureCoords = textureNormalizedCoords(p1_lightPV * llWorldPosition);
        EmitVertex();a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.