How to set Alpha value from pixel shader in SlimDX Direct3d9

Posted by Yashwinder on Game Development See other posts from Game Development or by Yashwinder
Published on 2014-08-25T10:22:40Z Indexed on 2014/08/25 10:34 UTC
Read the original article Hit count: 552

Filed under:
|
|

I am trying to set alpha value of color as color.a = 0.5f in my pixel shader but all the time it is giving an exception. I can set color.r, color.g, color.b but it is not allowing me to set color.a and throwing an exception D3DERR_INVALIDCALL: Invalid call (-2005530516). I have just created a direct3d9 device and assigned my pixel shader to it.

My pixel shader code is as below

sampler2D ourImage : register(s0);
float4 main(float2 locationInSource : TEXCOORD) : COLOR
{
   float4 color = tex2D( ourImage , locationInSource.xy);
   color.a = 0.2;
   return color;
}

I am creating my pixel shader as

byte[] byteCode = GiveFxFile(transitionEffect.PixelShaderFileName);
var shaderBytecode = ShaderBytecode.Compile(byteCode, "main", "ps_2_0", ShaderFlags.None);
var pixelShader = new PixelShader(device, ShaderBytecode);
_device.PixelShader=pixelShader; 

I have initialized my device as

var _presentParams = new PresentParameters
    {
            Windowed = _isWindowedMode,
            BackBufferWidth = (int)SystemParameters.PrimaryScreenWidth,
            BackBufferHeight = (int)SystemParameters.PrimaryScreenHeight,
            // Enable Z-Buffer
            // This is not really needed in this sample but real applications generaly use it
            EnableAutoDepthStencil = true,
            AutoDepthStencilFormat = Format.D16,
            // How to swap backbuffer in front and how many  per screen refresh
            BackBufferCount = 1,
            SwapEffect = SwapEffect.Copy,
            BackBufferFormat = _direct3D.Adapters[0].CurrentDisplayMode.Format,
            PresentationInterval = PresentInterval.Immediate,
            DeviceWindowHandle = _windowHandle
    };
 _device = new Device(_direct3D, 0, DeviceType.Hardware, _windowHandle, deviceFlags | CreateFlags.Multithreaded, _presentParams);

© Game Development or respective owner

Related posts about hlsl

Related posts about directx9