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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:27:12+00:00 2026-06-15T16:27:12+00:00

I have been working on a shader program, and one of the weirdest things

  • 0

I have been working on a shader program, and one of the weirdest things is happening.
I have a method called PositionLightPS, which essentially performs computations for positional lights (omni and spotlights) and returns a struct containing both the intensity and the diffuse colour of the light.

It used to work in a previous revision of the program, however it stopped working for some reason…

Let me explain why. But first, here is the code for the PositionPS method. I have no doubt that the calculations of this method are correct, but more on that later.

struct LightFragment {
    float4 diffuse;
    float intensity;
};

LightFragment PositionLightPS(PositionLightVOut pin, float3 lightToPixelVec)
{
    LightFragment result;

    pin.normal = normalize(pin.normal);

    float4 diffuse = shaderTexture.Sample( textureSampler, pin.tex0 );
    float3 finalDiffuse = float3(0.0f, 0.0f, 0.0f);

    float d = length(lightToPixelVec);
    if( d > plRange )
    {
        result.diffuse = float4(finalDiffuse, 0);
        result.intensity = 0; 
        return result;
    }

    lightToPixelVec /= d; 

    result.intensity = dot(lightToPixelVec, pin.normal);

    if( result.intensity > 0.0f )
    {   
        finalDiffuse = result.intensity * diffuse.xyz;
        finalDiffuse.xyz *= clColour.xyz;
        finalDiffuse.xyz *= clColour.w;

        finalDiffuse /= plAttenuation[0] + (plAttenuation[1] * d) + (plAttenuation[2] * (d*d));
    }   

    result.diffuse = float4(finalDiffuse, diffuse.a) * diffuseColour;
    return result;
}

Here is the omni light pixel shader.

float4 OmniLightDiffusePS(PositionLightVOut pin) : SV_TARGET0
{
    float3 lightToPixelVec = plPosition.xyz - pin.worldPos.xyz;
    return = PositionLightPS(pin, lightToPixelVec).diffuse;
}

For some reason, this does not work, although it had been for a long time. But this is not the focus of my question. What is definitely strange, is that these two methods yield different results.

float4 OmniLightDiffusePS(PositionLightVOut pin) : SV_TARGET0
{
    //return float4(1,1,1,1);
    float3 lightToPixelVec = plPosition.xyz - pin.worldPos.xyz;
    LightFragment fragment = PositionLightPS(pin, lightToPixelVec);
    return float4(1,1,1,1);
}

This one will return a black pixel

float4 OmniLightDiffusePS(PositionLightVOut pin) : SV_TARGET0
{
    return float4(1,1,1,1);
    float3 lightToPixelVec = plPosition.xyz - pin.worldPos.xyz;
    LightFragment fragment = PositionLightPS(pin, lightToPixelVec);
    //return float4(1,1,1,1);
}

This one will return a white pixel

So this means that calling the PositionLightPS method has an influence on the value returned… but why? Why would it? What is happening? Is it a memory error?

(Note: Copying the PositionLightPS method code directly in the OmniLightDiffuse method solves the problem, and the light displays normally. This means that the calculations performed in PositionLightPS are correct. The question is then, does using LightFragment struct have an impact on the shader program somehow?)

  • 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-15T16:27:13+00:00Added an answer on June 15, 2026 at 4:27 pm

    I found the cause of the problem. My computer uses CUDA and locked itself into using the integrated graphics chip without my knowledge. Forcing the NVidia card solved the problem.

    However, I did find this very useful blog post which details what was essentially my problem. Calling a user define function causes the inlining by the compiler to delete the pixels it treats, when two specific compiler flags are simultaneously active.
    I do not know if the integrated graphics chip reproduced this exact error, but the symptoms seemed to correspond perfectly (ie calling a function with no incidence on the return value will change what is being returned).

    For more details, here is the link to the blog post, by Nico Shertler: http://nicoschertler.wordpress.com/2012/01/02/hlsl-4-calls-to-user-defined-functions-will-crash/

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

Sidebar

Related Questions

I have been working on a widget for Android. One of the things it
I have been working with a script by Scripterlative called CursorDivScroll, which scrolls the
I have been working with SQL Server as a Developer a while. One thing
have been working and wearing out my fingers doing google searches with this one:
i have been working on a small demo and i wrote a function which
I have been working Quartz framework in my grails project with lib called quartz-all-1.7.3.
I have been working on a program in windows VC++ 2008. I started by
I have been working on a system which I'm using protobuf-net (version 2.0.0.480) for
I have been working with some sort of validation in which i need to
I have been working on a method to sync core data stored in an

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.