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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:00:01+00:00 2026-05-28T19:00:01+00:00

I have a 2D scene, 2 textures set as render targets, and a vertex

  • 0

I have a 2D scene, 2 textures set as render targets, and a vertex buffer.

first texture is filtered out by contrast/brightness pixel shader, the second acts as a menu, which I would not like to be processed by the same shader, but want it to be alphablended with the first one.

Everything runs fine, until I go to extreme values for brightness/contrast which looks like the fade out effect when changing the the second one and it stops to redraw at all on very extreme ones, though the data is always fed to the first one.

Disabling AlphaBlendnable corrects it, but I loose alpha blending… Any way to clean the buffers prior to applying pixel shaders? Any help appreciated.

pixel shader code:

float offsetBrightness = 0.0f; \
float offsetContrast   = 0.0f; \
float4 PSBrightnessContrast(float2 inCoord : TEXCOORD0) : COLOR0\
{\
    float4 color = tex2D( screen, inCoord.xy); \
    color = color + offsetBrightness; \
    color = color * (1.0 + offsetContrast); \
    return saturate( color ); \
}\

Rendering code

// Begin the scene
    hr = IDirect3DDevice9_BeginScene(d3ddev);
  if (FAILED(hr)) 
    throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );

// Render the vertex buffer contents
hr = IDirect3DDevice9_SetStreamSource(d3ddev, 0, d3dvtc, 0, sizeof(CUSTOMVERTEX));
if (FAILED(hr)) {
    IDirect3DDevice9_EndScene(d3ddev);
    throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
}

// we use FVF instead of vertex shader
hr = IDirect3DDevice9_SetFVF(d3ddev, D3DFVF_CUSTOMVERTEX);
if (FAILED(hr)) {
    IDirect3DDevice9_EndScene(d3ddev);
    throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
}

//apply shaders

UINT shaderPasses;
if(d3dxShader)
{
    hr = d3dxShader->Begin( &shaderPasses, 0 );
    if (FAILED(hr))
        throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
}
else
    shaderPasses = 1;

for( UINT uPass = 0; uPass < shaderPasses; ++uPass )
{
    if(d3dxShader)
    {
        hr = d3dxShader->BeginPass(uPass);
        if (FAILED(hr))
            throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
    }

    hr = IDirect3DDevice9_SetTexture(d3ddev, 0, (LPDIRECT3DBASETEXTURE9)d3dtex);
    if (FAILED(hr)) {
        IDirect3DDevice9_EndScene(d3ddev);
        throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
    }

    // draw rectangle
    hr = IDirect3DDevice9_DrawPrimitive(d3ddev, D3DPT_TRIANGLEFAN, 0, 2);
    if (FAILED(hr)) {
        IDirect3DDevice9_EndScene(d3ddev);
        throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
    }

    if(d3dxShader)
    {
        hr = d3dxShader->EndPass();
        if (FAILED(hr))
            throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
    }
}

if(d3dxShader)
{
    hr = d3dxShader->End();
    if (FAILED(hr))
        throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
}

// Render the vertex buffer contents
hr = IDirect3DDevice9_SetStreamSource(d3ddev, 0, d3dvtc, 0, sizeof(CUSTOMVERTEX));
if (FAILED(hr)) {
    IDirect3DDevice9_EndScene(d3ddev);
    throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
}

// we use FVF instead of vertex shader
hr = IDirect3DDevice9_SetFVF(d3ddev, D3DFVF_CUSTOMVERTEX);
if (FAILED(hr)) {
    IDirect3DDevice9_EndScene(d3ddev);
    throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
}

// Setup our texture. Using textures introduces the texture stage states,
// which govern how textures get blended together (in the case of multiple
// textures) and lighting information. In this case, we are modulating
// (blending) our texture with the diffuse color of the vertices.
hr = IDirect3DDevice9_SetTexture(d3ddev, 0, (LPDIRECT3DBASETEXTURE9)d3dtex2);
if (FAILED(hr)) {
    IDirect3DDevice9_EndScene(d3ddev);
    throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
}

// draw rectangle
hr = IDirect3DDevice9_DrawPrimitive(d3ddev, D3DPT_TRIANGLEFAN, 0, 2);
if (FAILED(hr)) {
    IDirect3DDevice9_EndScene(d3ddev);
    throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
}

// End the scene
hr = IDirect3DDevice9_EndScene(d3ddev);
if (FAILED(hr)) 
    throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );    
  • 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-28T19:00:02+00:00Added an answer on May 28, 2026 at 7:00 pm

    This has worked for me, seems the alpha channel must be accounted in this case

    float offsetBrightness = 0.0f; \
    float offsetContrast   = 0.0f; \
    float4 PSBrightnessContrast(float2 inCoord : TEXCOORD0) : COLOR0\
    {\
       float4 pixelColor = tex2D( screen, inCoord.xy); \
       pixelColor.rgb /= pixelColor.a; \
       \
      pixelColor.rgb = ((pixelColor.rgb + 1.0f) * max(offsetContrast, 0)) - 1.0f; \
      pixelColor.rgb += offsetBrightness; \
      pixelColor.rgb *= pixelColor.a; \
    \
     return pixelColor;\
    }\
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large scene graph in Java 3D consisting out of a Group
I have a scene that is rendered to texture via FBO and I am
Okay, so I am trying to render a scene to a small 32x32 texture
I have been having trouble finding straightforward code to render a scene to a
I can't figure out what is up with this. I have a Scene class
I currently have two shaders, a processing shader (both vertex and pixel) - which
I have a texture where it is a 4x4 grid in a 256x256 pixel
If I have the vertex normals of a normal scene showing up as colours
I have a scene written in Java 3d, where the user's viewing position is
I have a scene in my WPF project with about 2000 different user controls:

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.