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!


george7378

Member Since 24 Jan 2013
Offline Last Active Apr 03 2015 04:19 AM

Topics I've Started

oblem with OpenMP for loop

02 February 2015 - 09:48 AM

(fail on the title, sorry)

 

Hi everyone!

 

As a little side project I decided to implement a simple 3D drawing engine of my own using GDI+ to draw lines between a bunch of points which have been projected onto the screen. Here's my main drawing loop which iterates through all the polygons (stored as triangles in 'meshTestObject.indexbuffer') and draws a line between each vertex in the polygon (note that 'main_pixel_buffer' contains the projected locations of all the mesh vertices):

for (int i = 0; i < meshTestObject.indexbuffer.size(); i++)
{
graphics.DrawLine(&whitePen, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].x)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].x)].y, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].y)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].y)].y);
graphics.DrawLine(&whitePen, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].y)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].y)].y, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].z)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].z)].y);
graphics.DrawLine(&whitePen, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].z)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].z)].y, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].x)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].x)].y);
}

The above code works fine and produces this:

 

Attached File  teapot1.png   59.08KB   1 downloads

 

I thought I would try and speed up the process using OpenMP (which I have used before in a path tracer). So, I stuck a parallel for pragma over the loop like this:

#pragma omp parallel for schedule(dynamic, 1)
for (int i = 0; i < meshTestObject.indexbuffer.size(); i++)
{
graphics.DrawLine(&whitePen, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].x)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].x)].y, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].y)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].y)].y);
graphics.DrawLine(&whitePen, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].y)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].y)].y, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].z)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].z)].y);
graphics.DrawLine(&whitePen, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].z)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].z)].y, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].x)].x, main_pixel_buffer[unsigned(meshTestObject.indexbuffer[i].x)].y);
}

...and now I get a random smattering of lines which changes every time I refresh:

 

Attached File  teapot2.png   15.32KB   1 downloads

 

I can't figure out why this is happening. I thought that this would basically assign a single polygon from 'meshTestObject.indexbuffer' to be drawn by each thread, and since the order in which the wireframe triangles are drawn doesn't matter, the result should be the same right? Can anyone spot a reason why I can't use OMP with the particular for loop?

 

Thanks a lot smile.png


Scaling sprites with distance?

12 December 2014 - 06:29 AM

Hi!

 

I'm wondering if there's an easy way to change the scaling of an ID3DXSprite according to its depth? I'm using a sprite for the exhaust of a spacecraft in my game (using D3DXVec3Project to determine its position on screen):

 

Attached File  spritescale1.jpg   97.82KB   2 downloads

 

...however as I change the camera distance, the sprite stays the same size:

 

Attached File  spritescale2.jpg   89.69KB   2 downloads

 

Perhaps there's a flag I can set? Or failing that, does anyone know how the scaling factor would relate to distance?

 

Thanks :)


Annoying shadow map artifacts

07 December 2014 - 02:15 PM

Hi, just a quick question.

 

I've got a small issue with a shader I'm using for basic shadow mapping. When I render the scene, I get thin black lines around the edge of my projected shadow area:

 

Attached File  shadow problem.jpg   111.02KB   1 downloads

 

I have a feeling that it's floating point inaccuracy in this part of the shader:

if ((saturate(projTexCoord.x) == projTexCoord.x) && (saturate(projTexCoord.y) == projTexCoord.y))

    {

        if ((PSIn.Pos2DLight.z - f_ShadowBias) > tex2D(ShadowMapSampler, projTexCoord).r)

        {

            diffuseLightingFactor = 0;

         }

    }

Is this likely to be the problem or do you think it may be something else?

 

Thanks.

 


Post-processing effect questions

03 December 2014 - 02:11 PM

Hi everyone,

 

I've been using a sprite to do post-processing effects for a while now, but I'm having a few issues with it recently. Here is my code for drawing to the screen using post-processing:

bool draw_Processed_Texture(D3DXHANDLE technique, DrawableTex2D screen_texture)
{
if (FAILED(screenSprite->Begin(D3DXSPRITE_DO_NOT_ADDREF_TEXTURE | D3DXSPRITE_SORT_TEXTURE))){return false;}
 
globalEffect->SetValue("i_TextureWidth", &WIDTH, sizeof(unsigned));
globalEffect->SetValue("i_TextureHeight", &HEIGHT, sizeof(unsigned));
 
globalEffect->SetTexture("t_ScreenTexture", screen_texture.drawTexture);
 
globalEffect->SetTechnique(technique);
UINT numPasses = 0;
if (FAILED(globalEffect->Begin(&numPasses, 0))){return false;}
for (UINT i = 0; i < numPasses; i++)
{
if (FAILED(globalEffect->BeginPass(i))){return false;}
screenSprite->Draw(screen_texture.drawTexture, NULL, NULL, NULL, D3DCOLOR_ARGB(255, 255, 255, 255));
if (FAILED(screenSprite->End())){return false;}
if (FAILED(globalEffect->EndPass())){return false;}
}
if (FAILED(globalEffect->End())){return false;}
 
return true;
}
 
Is this the right way to go about doing it? Do I have my calls in the correct order? Also, in the screenSprite->Draw() function I have specified the texture (screen_texture.drawTexture) again. Since I've already sent it to the shader to be sampled, do I need to put it in the sprite draw call too?
 
Thanks!

Putting a calculation in the vertex shader vs. pixel shader

27 November 2014 - 04:03 PM

Hi,

 

I'm having a bit of trouble getting my head around how interpolation works in HLSL when sending values from the vertex shader to the pixel shader. I've attached a shader I'm working with at the moment for rendering a water plane:

 

Attached File  water_shader_snippet.txt   2.24KB   42 downloads

 

So I understand that HLSL will interpolate everything I've put in the vertex shader across the face of the current triangle when it is sent to the pixel shader, so I was wondering, could I move some of my other calculations across into the vertex shader? For example, my 'attenuation' calculation uses LightDirTS as a variable - would it still get interpolated properly if I move it over into the vertex shader and passed it in? Same with 'projTexCoord'.

 

Likewise I understand that things like 'reflectionVector' and 'specularLightingFactor' can't be in the VS because they are calculated using texture values (which are sampled per-pixel).

 

Can anyone help me understand exactly what should and shouldn't be in the vertex shader?

 

Thanks :)


PARTNERS