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!


Member Since 25 Aug 2009
Offline Last Active Today, 12:37 PM

Topics I've Started

c++ Heap corruption w/ std::vector

20 January 2015 - 10:07 AM

Thanks for taking the time to read this. I'm using a mesh object that contains std::vectors for vertex and index data.

class Mesh2
// snipped for brevity
    std::vector<unsigned short>        indices;


void Mesh2::AddFace(unsigned short _i1,unsigned short _i2, unsigned short _i3) {


The above functions reside in a static lib that contains all rendering code, linked to the main executable. Below are functions in the .Exe.

// In main()

Mesh2 cube;

and the function GenerateCube

GenerateCube(Mesh2* mesh, bool bGenNorms, bool bGenTangents)

 // at some point

//.. and so on

The issue is as soon as mesh.indices has to resize past 10(it's default size) I get a heap corruption. I'm not sure what must be done to rectify this. If anyone has a good link or can spare 5 minutes for a thorough explanation it would be much appreciated. Everything I've pulled up on google so far has to do with crossing DLL boundaries which I'm not doing, but might be happening behind the scenes in the std::vector. I'm heading back to google for now.

Shadowmapping woes

07 January 2015 - 09:03 PM

Greetings all, happy new year. I've been working on shadow mapping and have ran into an issue that I can't seem to figure out. My scene is simple, a single light, a few cubes in a cornell box sort of setup. The shadows are working, but the cubes are coming out black. If this is/was a bias issue I would assume that it would effect the entire scene and not just the cubes so I'm not sure where to begin without access to the vertex debugging features in pix.


EDIT:Attached File  test.png   169.85KB   0 downloads

// Shadow map generation

struct VS_INPUT
    float3 Position : POSITION0;
    float3 Normal : NORMAL0;
    float2 Texcoord : TEXCOORD0;

struct VS_OUTPUT
    float4 PositionCS : POSITION0;
    float2 TexCoord : TEXCOORD0;
    float2 Depth: TEXCOORD1;


    VS_OUTPUT output = (VS_OUTPUT)0;

    float4x4 WVmatrix = mul(Wmatrix,Vmatrix);
    float4x4 WVPmatrix = mul(WVmatrix,Pmatrix);
    // Transform Position to Clip Space
    output.PositionCS= mul(float4(input.Position,1), WVPmatrix);
    // Output TexCoords
    output.TexCoord = input.Texcoord;
    output.Depth = output.PositionCS.zw;
    return output;

struct PS_INPUT
    float4 PositionCS : POSITION0;
    float2 Depth : TEXCOORD1;
struct PS_OUTPUT
    float4 Color : COLOR0;
float4 PSMain(PS_INPUT input) : COLOR0
    PS_OUTPUT output;

    float4 diffuse = tex2D(tex0, input.TexCoord.xy);
    clip (diffuse.a - 0.15f);
    return input.Depth.x / input.Depth.y; // z / w; depth in [0, 1] range. // NDC SPACE

// shadow Calculation

float CalcShadowFactor(float4 projTexC)
// Complete projection by doing division by w.
	projTexC.xy /= projTexC.w;
	// Points outside the light volume are in shadow.
	if( projTexC.x < -1.0f || projTexC.x > 1.0f || 
	    projTexC.y < -1.0f || projTexC.y > 1.0f ||
	    projTexC.z < 0.0f )
	    return 0.0f;
	// Transform from NDC space to texture space.
	projTexC.x = +0.5f*projTexC.x + 0.5f;
	projTexC.y = -0.5f*projTexC.y + 0.5f;
		// Depth in NDC space.
	float depth = projTexC.z / projTexC.w;

	// 2x2 percentage closest filter.
	// Sample shadow map to get nearest depth to light.
	float s0 = tex2D(tex1, projTexC.xy).r;
	float s1 = tex2D(tex1, projTexC.xy + float2(ShadowMap_dx, 0)).r;
	float s2 = tex2D(tex1, projTexC.xy + float2(0, ShadowMap_dx)).r;
	float s3 = tex2D(tex1, projTexC.xy + float2(ShadowMap_dx,ShadowMap_dx)).r;
	// Is the pixel depth <= shadow map value?
	float result0 = depth <= s0 + ShadowEpsilon;
	float result1 = depth <= s1 + ShadowEpsilon;
	float result2 = depth <= s2 + ShadowEpsilon;
	float result3 = depth <= s3 + ShadowEpsilon;
	// Transform to texel space.
	float2 texelPos = ShadowMapSize*projTexC.xy;
	// Determine the interpolation amounts.
	float2 t = frac( texelPos );

	// Interpolate results.
	return lerp( lerp(result0, result1, t.x), 
	             lerp(result2, result3, t.x), t.y);

Blting DX9 textures to GDI, editing, and blting back

06 July 2014 - 07:31 PM

I'm looking for info on directly editing height and splat map data. My initial thought was that GDI with it's premade brushes would be an asset. So I set about learning what i needed from GDI to get the DXTexture into an HDC for use in a window.I've used BltBit which copies the entire Pixels RGB data from the dx surface into the HDC of my window.


I would prefer to copy a single SRC channel ( R,G,B,or A for the splat layers(1-4)), leaving the rest of the DST bitmap black. After a brush has affected the bitmap, I intend to copy the single channel back to the initial DXTexture, which is used as a splat map in my terrain viewer(hopefully editor)


Another thought was skipping GDI directly, and and implementing brushes in DX(unless they exist in an area i'm not familiar with) using pixel shaders, and modifying textures directly that way.


I'd appreciate a nudge in the right direction, if anyone has a spare moment.

Alan Turing

10 June 2014 - 07:57 AM



Anyone else catch this in their news feeds today?

Siggraph 2014 Vancouver

30 May 2014 - 06:11 PM

Anyone attending? I just noticed this was in Vancouver, and though it's about 600 mi away, or 1000km for we metric folk, the thought crossed my mind about going, as I will have a steady income this summer and will not need to slave away at a 9-5 position for a few months. I've never attended an event like this and would like to know if it is worth the trip.