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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:31:35+00:00 2026-06-08T07:31:35+00:00

Trying to learn shaders and get a dead simple directional light source working but

  • 0

Trying to learn shaders and get a dead simple directional light source working but I just get black. If I return input.Col all is fine so I know it’s something to do with these normal calcs but have absolutely no idea what is wrong? I’m struggling to understand shaders and specifically where to get/set matWorld from or what it should be (I tried just setting it to the Identity matrix) or if it’s something that magically gets set by itself. worldViewProj I’m setting from code

float4 vecLightDir = normalize(float4(1.0f, 1.0f, 1.0f,0.0f));
float4x4 worldViewProj : WORLDVIEWPROJECTION;
float4x4 matWorld : WORLD;

struct VS_IN
{
    float4 Pos : POSITION;
    float4 Col : COLOR0;
    float3 Norm : NORMAL;
};

struct PS_IN
{
    float4 Pos : POSITION;
    float4 Col : COLOR0;
    float3 Light: TEXCOORD0;
    float3 Norm : TEXCOORD1;
};

PS_IN VS( VS_IN input )
{
    PS_IN Out = (PS_IN)0; 
    Out.Pos = mul(input.Pos, worldViewProj);
    Out.Light = normalize(vecLightDir); 
    Out.Norm = -normalize(mul(input.Norm, matWorld));
    Out.Col = input.Col;
    return Out;
}

float4 PS(PS_IN input) : COLOR
{
    float4 result=input.Col *(dot(input.Norm,input.Light));

    return result;
}

technique TVertexAndPixelShader
{
    pass P0
    {
        // shaders
        VertexShader = compile vs_2_0 VS();
        PixelShader  = compile ps_2_0 PS();
    }  
}
  • 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-08T07:31:36+00:00Added an answer on June 8, 2026 at 7:31 am

    Well you have a couple of issues …

    1) Firstly the pixel shader performs a linear interpolation of your light and normal vectors across the triangle. This means that your vectors are no longer normalised when they reach the light shader.

    2) Why do you pass the light vector through the vertex shader in the vertex component? Why not send it as a constant to the pixel shader and thus bypass any interpolation issues?

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

Sidebar

Related Questions

Trying to learn C++ and working through a simple exercise on arrays. Basically, I've
Im new to shaders and I'm trying to learn the basics. But everytime I
I'm trying to learn to play with OpenGL GLSL shaders. I've written a very
Trying to learn F# but got confused when trying to distinguish between fold and
trying to learn and practice arrays but I have a problem with this small
Just trying to learn C++. I'm starting off with a scraper. The idea is
I trying to learn BDD way for development and just watched RailsCasts lesson for
i am trying to learn building own jquery plugin . with the simple example
While trying to learn the source for GameLibrary sample application I saw a line
just trying to learn asp.net i am able to login and redirect to default.aspx.

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.