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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:13:40+00:00 2026-05-27T22:13:40+00:00

I am setting an HLSL effect variable in the following way in a number

  • 0

I am setting an HLSL effect variable in the following way in a number of places.

extern ID3D10EffectVectorVariable* pColour;

pColour = pEffect->GetVariableByName("Colour")->AsVector();

pColour->SetFloatVector(temporaryLines[i].colour);

In one of the places it is set in a loop, each line in the vector temporaryLines has a D3DXCOLOR variable associated with it. The most annoying thing about this problem is that it actually works on rare occasions, but most of the time it doesn’t. Are there any known issues with this kind of code?

Here it works:

void GameObject::Draw(D3DMATRIX matView, D3DMATRIX matProjection)
{
device->IASetInputLayout(pVertexLayout);

mesh.SetTopology();//TODO should not be done multiple times

// select which vertex buffer and index buffer to display
UINT stride = sizeof(VERTEX);
UINT offset = 0;
device->IASetVertexBuffers(0, 1, mesh.PBuffer(), &stride, &offset);
device->IASetIndexBuffer(mesh.IBuffer(), DXGI_FORMAT_R32_UINT, 0);

pColour->SetFloatVector(colour);

// create a scale matrix
D3DXMatrixScaling(&matScale, scale.x, scale.y, scale.z);

// create a rotation matrix
D3DXMatrixRotationYawPitchRoll(&matRotate, rotation.y, rotation.x, rotation.z);

// create a position matrix
D3DXMatrixTranslation(&matTranslation, position.x, position.y, position.z);

// combine the matrices and render
matFinal = 
    matScale        * 
    matRotate       * 
    matTranslation  * 
    matView * matProjection;
pTransform->SetMatrix(&matFinal._11); 
pRotation->SetMatrix(&matRotate._11);    // set the rotation matrix in the effect
pPass->Apply(0);
device->DrawIndexed(mesh.Indices(), 0, 0);   //input specific
}

Here is occasionally works:

void BatchLineRenderer::RenderLines(D3DXMATRIX matView, D3DXMATRIX matProjection)
{
device->IASetInputLayout(pVertexLayout);

device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP);

// select which vertex buffer and index buffer to display
UINT stride = sizeof(LINE);
UINT offset = 0;
device->IASetVertexBuffers(0, 1, &pBuffer, &stride, &offset);
device->IASetIndexBuffer(iBuffer, DXGI_FORMAT_R32_UINT, 0);

allLines = temporaryLines.size();

for(int i = 0; i < allLines; i++)
{
    pColour->SetFloatVector(temporaryLines[i].colour); // in the line loop too?

    // combine the matrices and render
    D3DXMATRIX matFinal = 
        temporaryLines[i].scale * 
        temporaryLines[i].rotation * 
        temporaryLines[i].position * 
        matView * matProjection;

    pTransform->SetMatrix(&matFinal._11); 
    pRotation->SetMatrix(&temporaryLines[i].rotation._11);    // set the rotation matrix in the effect

    pPass->Apply(0);

    device->DrawIndexed(2, 0, 0);
}

temporaryLines.clear();
}

the effect file:

float4x4 Transform;    // a matrix to store the transform
float4x4 Rotation;     // a matrix to store the rotation transform
float4   LightVec   = {0.612f, 0.3535f, 0.612f, 0.0f};    // the light's vector
float4   LightCol   = {1.0f,   1.0f,    1.0f,   1.0f};    // the light's color
float4   AmbientCol = {0.3f,   0.3f,    0.3f,   1.0f};    // the ambient light's color
float4   Colour;

// a struct for the vertex shader return value
struct VSOut
{
    float4 Col : COLOR;    // vertex normal
    float4 Pos : SV_POSITION;    // vertex screen coordinates
};

// the vertex shader
VSOut VS(float4 Norm : NORMAL, float4 Pos : POSITION)
{
    VSOut Output;

    Output.Pos = mul(Pos, Transform);    // transform the vertex from 3D to 2D

    Output.Col = AmbientCol;    // set the vertex color to the input's color

    float4 Normal = mul(Norm, Rotation);

    Output.Col += saturate(dot(Normal, LightVec)) * LightCol * Colour; // add the diffuse and passed in light

    return Output;    // send the modified vertex data to the Rasterizer Stage
}

// the pixel shader
float4 PS(float4 Col : COLOR) : SV_TARGET
{
    return Col;    // set the pixel color to the color passed in by the Rasterizer Stage
}

// the primary technique
technique10 Technique_0
{
    // the primary pass
    pass Pass_0
    {
        SetVertexShader(CompileShader(vs_4_0, VS()));
        SetGeometryShader(NULL);
        SetPixelShader(CompileShader(ps_4_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-05-27T22:13:41+00:00Added an answer on May 27, 2026 at 10:13 pm

    So the Colour HLSL variable has not been defined inside a ConstantBuffer, just a normal shader variable.
    Perhaps the variable should rather be defined in a Constant buffer, updateblae per frame? Similar to how the world and view matrices should be defined in. At least then the GPU knows you want to update the colour variable each time you render. (As you are updating the value before you draw).

    cbuffer cbChangesEveryFrame
    {
    
        //The MVP matrices.
        matrix World;
        matrix View;
        float4   Colour;
    
    }
    

    Another point I would consider is to get the pointer to the technique desc everytime before the draw call (or pass through loop),
    and not reuse it, seems to also make a difference.

    //Initiate the pass through loop for the shader effect.
    technique->GetDesc(&desc);
    for (UINT p=0; p<desc.Passes; p++)
    {
        //Apply this pass through.
        technique->GetPassByIndex(p)->Apply(0);
    
        //draw indexed, instanced.
        device->device->DrawIndexedInstanced(indicesCount, (UINT) instanceCount, 0, 0, 0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Setting onchange event for CheckBoxList using the following code doesn't work. chkListUserGroup.Attributes.Add(onchange, document.forms[0].isRecordModified.value='true';); How
Setting the scene: My asp.net web application carries a version number which is incremented
setting is the following: I have a homepage where I display a diagram that
Setting width/height in CSS only corresponds to the content area. Is there a way
Setting the DBIC_TRACE environment variable to true: BEGIN { $ENV{DBIC_TRACE} = 1 } generates
Setting the DBIC_TRACE environment variable to true: BEGIN { $ENV{DBIC_TRACE} = 1 } generates
Setting a page title I have the following MVC View Syntax <title> Category :
Setting variable values inside a function call - I don't see this a lot,
Setting up an integration server, I’m in doubt about the best approach regarding using
Setting up ASP.net MVC with Linq2SQL or Entity Framework's context to have scaffolding work

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.