Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

Slig Commando

Member Since 01 Sep 2010
Offline Last Active Jun 01 2014 07:01 PM

Posts I've Made

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;


In Topic: Blend textures in HLSL

21 September 2013 - 03:18 PM

Thank you lwm. That is exactly what I needed.

In Topic: pick 3D cursor position sampling depth buffer

11 September 2013 - 09:44 PM

Ok guys. Thank you for all your help. I have realized what is wrong and have fixed the problem.