• Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at \$59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

# Slig Commando

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

### Solve path around a given point and radius

12 January 2014 - 12:48 PM

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

### Flat Projection matrix

20 October 2013 - 01:29 PM

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

### Apply effect to texture using pixel shader

23 September 2013 - 09:22 PM

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__);

}

if(device->CreateVertexBuffer(6 * sizeof(LWVERTEX),

0,

0,

D3DPOOL_DEFAULT,

0) != D3D_OK)

ErrorMessenger::ReportMessage("Failed to create vertex buffer!", __FILE__, __LINE__);

void* bufferData;

```

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)

{

}
```

### Locking and writing to certain channels of surface data

21 September 2013 - 03:54 PM

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.

### Blend textures in HLSL

21 September 2013 - 12:20 PM

Hello, it has been a long time since I have worked in hlsl and when I did I was never a prodigy by any means. My scenario is this. I have three textures. I would like to alpha blend them starting with texture one as the base, then blend two and then finally blend three using the alpha channel(A8R8G8B8 format). Im pretty sure multiple passes are unnecessary and I really dont have much of a clue how to get this achieved. I feel it should be pretty simple. Basically what would my pixel shader look like?

Thank you for any help!

PARTNERS