Jump to content
  • Advertisement
Sign in to follow this  

Weird Distortion When Running Shader

This topic is 1133 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright I'm not able to run PS_3_0 shaders with DX9. However, there is weird distortion in the image after running a basic shader. Colors are fine but shapes are all weird. This is after running a test shader that shouldn't alter the image. The before picture includes converting the data to the shader and back, so that part is working fine.







Here's the code that runs the shader.



Any idea what could be causing this distortion and how to solve it? I'm using D3DFMT_A16B16G16R16F data for frames.



As a side note, there is this code that was was in my script and I'm not seeing any difference when I comment it out. Is any of it useful?

m_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
m_pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
m_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
m_pDevice->SetRenderState(D3DRS_DITHERENABLE, TRUE);

m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

m_pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_SPECULAR);

m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

This code also can be commented out without any difference. Any of it is useful?

D3DXMATRIX matOrtho;

D3DXMatrixOrthoOffCenterLH(&matOrtho, 0, (float)m_videoWidth, (float)m_videoHeight, 0, 0.0f, 1.0f);
HR(m_pDevice->SetTransform(D3DTS_PROJECTION, &matOrtho));

D3DXMATRIX matIdentity;
HR(m_pDevice->SetTransform(D3DTS_WORLD, &matIdentity));
HR(m_pDevice->SetTransform(D3DTS_VIEW, &matIdentity));

Share this post

Link to post
Share on other sites

The SetTransform() is only for fixed-function pipeline, those matrices does nothing when using shaders as you're responsible for supplying your vertex shader with proper matrices etc.


Can you post the test shader maybe, both vertex and pixel?

Share this post

Link to post
Share on other sites

Test shader

sampler s0 : register(s0);
float4 p0 :  register(c0);
float2 p1 :  register(c1);

// -- Main code --
float4 main(float2 tex : TEXCOORD0) : COLOR {
    float4 c0 = tex2D(s0, tex);

    return c0;

There is no vertex shader as I'm using fixed function pipeline.

Edited by MysteryX

Share this post

Link to post
Share on other sites

Great! This solved the problem

for (int i = 0; i < 4; i++) {
    vertexArray[i].x -= .5f;
    vertexArray[i].y -= .5f;
Edited by MysteryX

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!