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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:02:10+00:00 2026-06-17T22:02:10+00:00

I’m a total beginner to HLSL and have got some sample code that renders

  • 0

I’m a total beginner to HLSL and have got some sample code that renders a flat triangle. If I try to replace the PShader function from one that returns an explicit color to one that references a global variable (mycol) below, then it no longer renders the triangle in color but in black.

float4 mycol = float4(1.0f, 1.0f, 0.0f, 1.0f);

float4 VShader(float4 position : POSITION) : SV_POSITION
{
        return position;
}

float4 PShader(float4 position : SV_POSITION) : SV_Target
{
    return mycol; // float4(1.0f, 0.0f, 1.0f, 1.0f);
}

I’ve tried reading the HLSL specs but feel I’m probably missing something obvious?

any help appreciated,
GMan

  • 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-17T22:02:11+00:00Added an answer on June 17, 2026 at 10:02 pm

    I believe you can only pass global values using constant buffers in directx. You need to initiate the constant buffer in the c++ code:

        D3D11_BUFFER_DESC constDesc;
    ZeroMemory( &constDesc, sizeof( constDesc ) );
    constDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
    constDesc.ByteWidth = sizeof(XMFLOAT4);
    constDesc.Usage = D3D11_USAGE_DEFAULT;
    
    d3dResult = d3dDevice_->CreateBuffer( &constDesc, 0, &shaderCB_ );
    
    if( FAILED( d3dResult ) )
    {
        return false;
    }
    

    Then in your rendering code:

    XMFLOAT4 mycol = XMFLOAT4(1,1,0,1);
    d3dContext_->UpdateSubresource(shaderCB_, 0, 0, &mycol, 0, 0);
    

    and in your shader:

    cbuffer colorbuf : register(b0)
    {
        float4 mycol;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a reasonable size flat file database of text documents mostly saved in
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.