Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

377 Neutral

About LevyDee

  • Rank
  1. Real programmers use FORTRAN, and If you can't do it in FORTRAN, do it in assembly.  If you can't do it in assembly, it isn't worth doing
  2. As stated in the topic, I have a use case where this would be nice, but is it actually possible? If you declare an interface in libraryOne and define an identical interface signature in libraryTwo, can  the two libraries use each other through an application without the two libraries having knowledge of each other?
  3. Theoretically: if you were to open an image file via an I/O object and write its bytes out in plain text and then create an IDirect3DTexture9 object(using a compatible format), then lock the surface to receive a D3DLOCKED_RECT object, could you then simply write the original source image bytes directly to the pBits pointer and result in a functioning IDirect3DTexture9 object(representing the original image)?   The question: AKA is the pBits member of D3DLOCKED_RECT a direct and exact representation of raw image pixel data(from .jpg, .png, ect...), or is their a liaison process that occurs, altering the data, when the d3d device creates the texture from a file?   Thank you
  4. Thank you so much for both of your input, that was indeed the problem.
  5. My issue is explained in the attached images. I am attempting to texture splat by adjusting alpha values on seperate layers. The problem is when the alpha map runs through the shader multiple times, it affects previous alpha adjustments adversly. The shader is very simple and is as follows: void psPPAlphaPaint(float2 iUV : TEXCOORD0, out float4 color : COLOR0) {     color = tex2D(AlphaMap, iUV);         float2 distance = float2(0.0f, 0.0f);     distance.x = uCoordinate - iUV.x;     distance.y = vCoordinate - iUV.y;         float dist = sqrt(pow(uCoordinate - iUV.x, 2) + pow(vCoordinate - iUV.y, 2));     if(dist < 0.05)     {         color.a = 1.0;     } } Older alpha adjustments begin to blur and adust their position in the texture.   Any thoughts or clarifying questions?   Thank you   Edit: I am running the shader using a full screen quad to make adjustments to the alpha map as a render target
  6. LevyDee

    Alpha blend mystery

    Well after running the program through pix and looking at the mip chain, both of you are correct. Thank you for the help.
  7. Hello,   So I am having a little trouble alpha blending two ground textures in order to "paint" alpha values in my homegrown engine level editor. I am using hlsl and direct3d9. The problem is that the alpha values seem to be taking BUT are only visible when the camera is very close to the texture in game. I have included two pictures that show the issue.   This is my pertinent hlsl code //LWSurface layers int layers; texture layerOne; texture layerTwo; sampler LayerOneTexture = sampler_state {     Texture = <layerOne>;     MipFilter = LINEAR;     MinFilter = LINEAR;     MagFilter = LINEAR; }; sampler LayerTwoTexture = sampler_state {     Texture = <layerTwo>;     MipFilter = LINEAR;     MinFilter = LINEAR;     MagFilter = LINEAR; }; void psLWSurface(float4 iNorm : TEXCOORD0,                  float2 iUV : TEXCOORD1,                  float2 iDepth : TEXCOORD2,                  out float4 mapColor : COLOR0,                  out float4 mapNorm : COLOR1,                  out float4 mapDepth : COLOR2,                  out float4 mapIdentity: COLOR3) {         float4 layerOne = tex2D(LayerOneTexture, iUV);     if(layers == 1)     {         mapColor = layerOne;     }     else if(layers == 2)     {                 //Sample second layer         float4 layerTwo = tex2D(LayerTwoTexture, iUV);         //Alpha blend the two layers         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);             mapColor = blendResult;     }     //Normal map     //Transform to range [0, 1] due to X8R8G8B8 texture format. Only holds unsigned data. = 0.5f * (normalize(iNorm) + 1.0f);     mapNorm.w = 1.0f;     //Depth map = (iDepth.x / iDepth.y);     mapDepth.w = 1.0f;     mapIdentity.xyzw = dsObjectIdentity; } technique LWSurface {     pass p0     {         VertexShader = compile vs_3_0 vsFill();         PixelShader = compile ps_3_0 psLWSurface();     } } And in the engine I have hardcoded a test value for the alpha of the second texture just until I can get this probem solved D3DLOCKED_RECT textureData;             _layers[layer].layer->LockRect(0, &textureData, 0, 0);             unsigned* bytePointer = (unsigned*)textureData.pBits;             for (int y = 0; y < desc.Height; y++)             {                 for (int x = 0; x < desc.Width; x++)                 {                     //Alpha channel                     ((byte*)&bytePointer[x])[3] = 50;                 }                 // 32bpp == 4 bytes and pitch may not be == width * 4                 bytePointer += textureData.Pitch >> 2;             }             _layers[layer].layer->UnlockRect(0); The textures are Dynamic and 32byte A8R8G8B8.   Thank you for taking the time.      
  8. The attached image helps to describe my problem.   Given a direction vector(V1), location to avoid along with the radius, and a destination point, how could I calculate the blue travel path?   I know that given the angle in radians of a circle you can find the vector location at that angle on the circle, but I am not sure how I would implement this equation to solve this.   Thank you
  9. I am looking to make the scene flat for editing maps in my engine. I am assuming it would have something to do with my projection matrix. I am looking for the effect that most editors use including Blender, Unreal sdk, hammer editor ect... Any tips?   Thanks
  10. First I want to apologize, I have been pretty active with questions the past few days so I hope nobody is getting annoyed with me!   The concept is as follows   Two identical textures loaded from the same resource. Texture 1 used in the pixel shader, Texture 2 the device render target. Pixel shader manipulates texture 1 to render results to texture 2 via full screen quad. After draw calls, copy texture 2's surface back into texture 1's surface.   That is what I am attempting to accomplish, but alas am failing. I have been working on this all day and it is getting pretty frustrating. Can anyone give any advice or knit pick my code?   Thank you   Create textures and full screen quad            //Create texture for display             if(D3DXCreateTextureFromFileEx(                                 device,                                 texturePath.c_str(),                                 D3DX_DEFAULT,                                 D3DX_DEFAULT,                                 D3DX_DEFAULT,                                 D3DUSAGE_RENDERTARGET,                                 D3DFMT_A8R8G8B8,                                 D3DPOOL_DEFAULT,                                 D3DX_DEFAULT,                                 D3DX_DEFAULT,                                 0,                                 0,                                 0,                                 &texture1) != D3D_OK)             {                 ErrorMessenger::ReportMessage("Failed to create texture!", __FILE__, __LINE__);             }             //Create texture for applying shader effect             if(D3DXCreateTextureFromFileEx(                                 device,                                 texturePath.c_str(),                                 D3DX_DEFAULT,                                 D3DX_DEFAULT,                                 D3DX_DEFAULT,                                 D3DUSAGE_RENDERTARGET,                                 D3DFMT_A8R8G8B8,                                 D3DPOOL_DEFAULT,                                 D3DX_DEFAULT,                                 D3DX_DEFAULT,                                 0,                                 0,                                 0,                                 &texture2) != D3D_OK)             {                 ErrorMessenger::ReportMessage("Failed to create texture!", __FILE__, __LINE__);             }             //Create full screen quad             if(device->CreateVertexBuffer(6 * sizeof(LWVERTEX),                                       0,                                       0,                                       D3DPOOL_DEFAULT,                                       &fullScreenQuad,                                       0) != D3D_OK)                 ErrorMessenger::ReportMessage("Failed to create vertex buffer!", __FILE__, __LINE__);             LWVERTEX* fsQuad = new LWVERTEX[6];             fsQuad[0].position = D3DXVECTOR3(-1.0f, 1.0f, 0.0f);             fsQuad[1].position = D3DXVECTOR3(-1.0f, -1.0f, 0.0f);             fsQuad[2].position = D3DXVECTOR3(1.0f, -1.0f, 0.0f);             fsQuad[3].position = D3DXVECTOR3(-1.0f, 1.0f, 0.0f);             fsQuad[4].position = D3DXVECTOR3(1.0f, 1.0f, 0.0f);             fsQuad[5].position = D3DXVECTOR3(1.0f, -1.0f, 0.0f);                          void* bufferData;             fullScreenQuad->Lock(0, 0, &bufferData, 0);             memcpy(bufferData, fsQuad, sizeof(LWVERTEX) * 6);             fullScreenQuad->Unlock(); Here is the draw function             //Set effect variables             if(effect->SetTexture("scene", texture1) != D3D_OK)                 ErrorMessenger::ReportMessage("Failed to set texture", __FILE__, __LINE__);             //Back up old render target             IDirect3DSurface9* oldRT;             if(device->GetRenderTarget(0, &oldRT) != D3D_OK)                 ErrorMessenger::ReportMessage("Failed to GetRenderTarget", __FILE__, __LINE__);             //Set texture2 as new render target             IDirect3DSurface9* newRT;             texture2->GetSurfaceLevel(0, &newRT);             if(device->SetRenderTarget(0, newRT) != D3D_OK)                 ErrorMessenger::ReportMessage("Failed to SetRenderTarget", __FILE__, __LINE__);              //Draw             device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);             device->BeginScene();                 UINT numPass;                 effect->Begin(&numPass, 0);                     effect->BeginPass(0);                     if(device->SetStreamSource(0, fullScreenQuad, 0, sizeof(LWVERTEX)) != D3D_OK)                         ErrorMessenger::ReportMessage("Failed to set stream source!", __FILE__, __LINE__);                     if(device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2) != D3D_OK)                                                     ErrorMessenger::ReportMessage("Failed to draw primitave!", __FILE__, __LINE__);                     effect->EndPass();                 effect->End();             device->EndScene();             device->SetRenderTarget(0, oldRT);             //Copy results from texture2 back into texture 1             IDirect3DSurface9* destSurf;             texture1->GetSurfaceLevel(0, &destSurf);             if(D3DXLoadSurfaceFromSurface(destSurf, nullptr, nullptr, newRT, nullptr, nullptr, 0, 0) != D3D_OK)             {                 ErrorMessenger::ReportMessage("Failed to LoadSurfaceFromSurface", __FILE__, __LINE__);             }
  11. 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.
  12. 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;             surf->GetDesc(&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;             }             //Unlock             surf->UnlockRect();
  13. I am looking for a way to manually adjust the alpha channel of an A8R8G8B8 formatted texture. I create the texture as managed in order to lock the surface and get the pBits describing the surface data. So how would you loop through the entire surface and only change the alpha channel of each pixel?   I know you can do something like this   BYTE* bytePointer = (BYTE*)surfaceData.pBits;   for(int i = 0; i < surfaceData.pitch * textureHeight; i++) {     bytePointer[i] = //some value } This will loop through every bit, but how do I figure which channel of the pixel I am on so I can update only the alpha channel of an A8R8G8B8 texture?   Thank you.
  14. LevyDee

    Blend textures in HLSL

    Thank you lwm. That is exactly what I needed.
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!