Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 24 Jan 2013
Offline Last Active Today, 06:49 AM

Posts I've Made

In Topic: Creating a custom sprite class

03 November 2015 - 02:55 PM

Thankyou very much for the help, this has allowed me to create a working quad class :)

In Topic: Finding the current average of an indefinitely increasing sequence

03 November 2015 - 02:54 PM

Great - the moving average method is what I was after. As predicted, now that I know about it, it makes perfect sense!

In Topic: Creating a custom sprite class

02 November 2015 - 10:57 AM

Ah OK, so I need to shift the coordinates of each vertex (which I have now corrected to properly fit the NDC format) by -0.5/WIDTH in the x direction and -0.5/HEIGHT in the y direction?

In Topic: Creating a custom sprite class

02 November 2015 - 09:41 AM

Hey again,
Thanks for the responses, I have created my quad class, along with a vertex shader to go with it. Here's my class:
struct ScreenQuadVertex
D3DXVECTOR2 texCoords;
class ScreenQuad
IDirect3DVertexDeclaration9* vertexDecleration;
bool CreateResources()
ScreenQuadVertex vertices[] =
{D3DXVECTOR4(-1, 1, 0, 1), D3DXVECTOR2(0, 1)}, //Bottom Left
{D3DXVECTOR4(1, 1, 0, 1), D3DXVECTOR2(1, 1)}, //Bottom Right
{D3DXVECTOR4(-1, -1, 0, 1), D3DXVECTOR2(0, 0)}, //Top Left
{D3DXVECTOR4(1, -1, 0, 1), D3DXVECTOR2(1, 0)}, //Top Right
D3DVERTEXELEMENT9 elements[] =
vertexDecleration = 0;
if (FAILED(d3ddev->CreateVertexDeclaration(elements, &vertexDecleration))){return false;}
if (FAILED(d3ddev->CreateVertexBuffer(4*sizeof(ScreenQuadVertex), 0, 0, D3DPOOL_MANAGED, &vertexBuffer, 0))){return false;}
void* pVoid;
if (FAILED(vertexBuffer->Lock(0, 0, (void**)&pVoid, 0))){return false;}
memcpy(pVoid, vertices, sizeof(vertices));
if (FAILED(vertexBuffer->Unlock())){return false;}
return true;
bool Render()
if (FAILED(d3ddev->SetVertexDeclaration(vertexDecleration))){return false;}
if (FAILED(d3ddev->SetStreamSource(0, vertexBuffer, 0, sizeof(ScreenQuadVertex)))){return false;}
if (FAILED(d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2))){return false;}
return true;
void DeleteResources()
...and here's a simple effect file which is supposed to take a texture (which is the same dimensions as the program client area) and display it on screen:
Texture ScreenTexture;
sampler ScreenTextureSampler = sampler_state
texture = <ScreenTexture>;
magfilter = POINT;
minfilter = POINT;
mipfilter = POINT;
AddressU = Mirror;
AddressV = Mirror;
struct PixelColourOut
float4 Colour : COLOR0;
struct ScreenQuadVertexToPixel
     float4 Position      : POSITION;
     float2 TexCoords     : TEXCOORD0;
ScreenQuadVertexToPixel ScreenQuadVertexShader(float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0)
     ScreenQuadVertexToPixel Output = (ScreenQuadVertexToPixel)0;
     Output.Position = inPos;
     Output.TexCoords = inTexCoords;
return Output;
PixelColourOut ScreenPixelShader(ScreenQuadVertexToPixel PSIn)
PixelColourOut Output = (PixelColourOut)0;
Output.Colour = tex2D(ScreenTextureSampler, PSIn.TexCoords);
     return Output;
technique ShowTexture
pass Pass0
     VertexShader = compile vs_3_0 ScreenQuadVertexShader();
         PixelShader = compile ps_3_0 ScreenPixelShader();
It seems to work overall, i.e. when I send in this texture:
Attached File  testtex.jpg   225.46KB   2 downloads
I get this result when I run the program:
Attached File  testtexrender.png   390.38KB   2 downloads
There are two obvious issues - first, the image is flipped about the horizontal, implying that there is something wrong with the texture coordinates I defined, and second, the texture is very blocky when displayed by my program. This shouldn't happen because even though the shader sampler uses no filtering, the client area and texture are the same dimensions, meaning that there should be a 1:1 correspondence between the pixels. Note that I used the AdjustWindowRect() function to make sure the client area of my window is the same as the texture dimensions (640x480 in this case).
Can anyone see why these things are happening from my code? I thought that HLSL used (0, 0) for the top left of the texture and (1, 1) for the bottom right, as I have coded into the four vertices of the ScreenQuad. Is this not the case?
Thanks for the help smile.png

In Topic: Generating random rays within a cone

18 May 2015 - 09:14 AM

IsItSharp: Yes, that's it :)


l0calh05t/Alvaro: The way I'm doing it is that I have changed my uniform sphere distribution for diffuse reflection (which I sort of stole from SmallPT in the "if(obj.refl == DIFF)" section) and I modified it so that it only chooses results between the angles I want. It's not rejection sampling, so I think it's working properly :)