Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 19 Feb 2006
Offline Last Active Apr 11 2015 03:23 AM

Topics I've Started

Debug output options for Visual Studio using Release

06 April 2014 - 07:49 PM

I have a project I'm working on that has folders relative to the "Release" folder that my application requires. This means I am constantly compiling in Release mode even during debugging.


The issue is I want to be able to toggle debug output on and off.


What should I do to deal with this situation? Should I set the Debug and Release output folders the same directory and use Debug when I want Debug output? Or should I use the Release mode and setup a #define for toggling Debug output?

Using two shaders at the same time

18 December 2013 - 01:01 PM

I need to be able combine two different types of pixel shaders. One is for applying an effect and the other is for a transition.

Here is an example transition pixel shader
float Progress;

texture Input1;
sampler Input1Sampler = sampler_state
	Texture = <Input1>;
texture Input2;
sampler Input2Sampler = sampler_state
	Texture = <Input2>;

float4 Fade(float2 uv)
	float4 c1 = tex2D(Input1Sampler, uv);
	float4 c2 = tex2D(Input2Sampler, uv);

	return (lerp(c1, c2, Progress));

float4 main(float2 uv : TEXCOORD) : COLOR
	return (Fade(uv));

technique FadeTransition
	pass FadeTransition
		VertexShader = null;
		PixelShader = compile ps_2_0 main();
Here is how I apply it
m_transitionEffect.Technique = m_transitionEffect.GetTechnique(0);

m_transitionEffect.SetTexture("Input1", m_screenTexture[0].DXTexture);
m_transitionEffect.SetTexture("Input2", m_screenTexture[1].DXTexture);

m_transitionEffect.SetValue<float>("Progress", m_progress);



// Render stuff

Here is an example effect pixel shader
texture SourceTexture;
sampler SourceTextureSampler = sampler_state
	Texture = <SourceTexture>;

float4 InvertColorFunc(float2 tex : TEXCOORD) : COLOR
	float4 texcolor = tex2D(SourceTextureSampler, tex);
	float4 newcolor = 1.0f - texcolor;
	return (float4(newcolor.rgb, texcolor.a));

technique InvertColor
	pass InvertColor
		VertexShader = null;
		PixelShader = compile ps_2_0 InvertColorFunc();
Here is how I apply it.
m_effectEffect.Technique = m_effectEffect.GetTechnique(0);

m_effectEffect.SetTexture("SourceTexture", m_screenTexture[0].DXTexture);



// Render stuff

How can I combine these two shaders and keep them in separate files? I have tried nesting the two together but it does not seem to work.

Setting members in VB.NET without constructors

12 November 2013 - 01:58 PM

In C# I can do the following:

MyClass myObject = new MyClass() { Member1 = value1, Member2 = value2, Member3 = value3 };

Is there an equivalent in VB.NET?

Array.Sort performance issue

27 October 2013 - 03:51 PM

I am working on a C#/SlimDX rendering engine. I noticed a performance issue after having around 1000 rendered objects in a List<T> and sorting them every frame. I need to sort these objects so they render in the appropriate order. I'm actually getting a significant frame rate drop of about 5 FPS.
The problem is not so much the sorting per se but that I need to perform multiple levels of sorting based on members in the objects such as the layer, texture and so on. Finally the objects need to sort based on the original order they were added to the List so I have an index member for that.
Here is the sorting code (no idea why the indentation isn't working here)
public int CompareTo(RenderObject other)
if (this.Layer != other.Layer)
return this.Layer.CompareTo(other.Layer);
if (this.Translation.Z != other.Translation.Z)
return this.Translation.Z.CompareTo(other.Translation.Z);
if (this.TextureArray[0] != null && other.TextureArray[0] != null)
if (this.TextureArray[0].Id != other.TextureArray[0].Id)
return this.TextureArray[0].Id.CompareTo(other.TextureArray[0].Id);
if (this.TextureArray[1] != null && other.TextureArray[1] != null)
if (this.TextureArray[1].Id != other.TextureArray[1].Id)
return this.TextureArray[1].Id.CompareTo(other.TextureArray[1].Id);
if (this.TextureArray[2] != null && other.TextureArray[2] != null)
if (this.TextureArray[2].Id != other.TextureArray[2].Id)
return this.TextureArray[2].Id.CompareTo(other.TextureArray[2].Id);
if (this.TextureArray[3] != null && other.TextureArray[3] != null)
if (this.TextureArray[3].Id != other.TextureArray[3].Id)
return this.TextureArray[3].Id.CompareTo(other.TextureArray[3].Id);
if (this.BlendMode != other.BlendMode)
return (this.BlendMode != other.BlendMode ? 1 : 0);
if (this.ScissorRect != other.ScissorRect)
return (this.ScissorRect != other.ScissorRect ? 1 : 0);
return this.Index.CompareTo(other.Index);

As you can see I've implemented IComparable<T> and call Array.Sort every frame. Unfortunately it's causing this performance issue. Now if I change it to only sort based on index, for example, then there is no problem. So it's the fact I need multiple parameters to sort the object list that is slowing things down.
On a final note I have to be able to sort every frame because some render objects (like text) are dynamic and are added/removed every frame. I actually had a massive 15 FPS drop when I used a loop to remove the objects but have since improve by using List.AddRange to add text character objects and List.RemoveAll to remove them. So now I only have 5 FPS drop that is due to the sorting.
I do not have Linq available to me (using .NET 2.0) so I'd like to hear some ideas on how I can improve the performance of this necessary  sorting.

Predict the pitch of a texture before creation?

20 August 2013 - 03:28 AM

I want to create a texture of D3DFMT_A8R8G8B8 format. If I already know the width and height is there any way I can predict the pitch before calling CreateTexture?