Jump to content

  • Log In with Google      Sign In   
  • Create Account

Slig Commando

Member Since 01 Sep 2010
Offline Last Active Mar 29 2016 04:09 PM

Posts I've Made

In Topic: Alpha splatting and unexpected behavior

21 October 2015 - 06:13 PM

Thank you so much for both of your input, that was indeed the problem.

In Topic: Alpha blend mystery

28 August 2015 - 09:59 AM

Well after running the program through pix and looking at the mip chain, both of you are correct. Thank you for the help.

In Topic: Flat Projection matrix

20 October 2013 - 03:58 PM

Thank you

In Topic: Locking and writing to certain channels of surface data

22 September 2013 - 08:16 PM

Ah, roger that. Thats what I get for copying my lock from a different function I wrote(meant to read, not write...) Thank you for the help. That seemed to do the trick.

In Topic: Locking and writing to certain channels of surface data

22 September 2013 - 10:03 AM

Thank you for the response. This seems to change the correct value, but the change is not reflecting in my rendering. Is their anything that would prevent my change from taking effect?


The purpose of this is I am building an editor for my engine. I want to have multiple layers for terrain painting. So you have the base layer, and then you can have layers on top of that. Each extra layer can be "painted" by lowering the alpha channel of which ever layer you like. So what I m trying to do is manually edit the alpha channel only at certain indices of the surface data(due to mouse dragging). I have manually set up a test case where I just lower the alpha to 50 percent ala 255 / 2 but it has zero effect. If I set the alpha channel to 0.5f in my shader before the alpha blending occurs, it works as expected. Will locking the surface of the texture and setting the alpha channel there not effect my alpha channel I receive in my shader? that seems to be the case right now.


Using your example this is what my test function looks like. It is simply supposed to adjust every texels alpha channel to 0.5f in my shader.


Shader(tested and verified to work)

//Alpha blend
float4 blendResult;

blendResult.a = layerTwo.a + (1.0f - layerTwo.a) * layerOne.a;
blendResult.rgb = (1.0f / blendResult.a) * (layerTwo.a * layerTwo.rgb + (1.0f - layerTwo.a) * layerOne.a * layerOne.rgb);    
color = blendResult;


Alpha function

IDirect3DSurface9* surf;
            _layers[1].texture->GetSurfaceLevel(0, &surf);

            //Get surface description
            D3DSURFACE_DESC desc;

            //Lock surface data
            D3DLOCKED_RECT surfaceData;
            surf->LockRect(&surfaceData, 0, D3DLOCK_READONLY);    

            //Make pointer to directly edit surface data
            BYTE* bytePointer = (BYTE*)surfaceData.pBits;

            for (int y = 0; y < desc.Height; y++)
                for (int x = 0; x < desc.Width; x++)
                    //Alpha channel
                    ((byte *) &bytePointer[x])[3] = 255 / 2;

                // 32bpp == 4 bytes and pitch may not be == width * 4
                bytePointer += surfaceData.Pitch >> 2;