Jump to content
  • Advertisement
Sign in to follow this  
Ethangar

[.net] Help me with Managed DirectX and Pixel Shaders using HLSL!

This topic is 4676 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm going nuts here trying to get pixel shaders working correctly. I sailed across the entire internet looking for some help with this stuff, and even found some nice video tutorials, but I am still having trouble. Here is the situation, I have a game I am working on and am trying to add some fancy pixel shaders to make it look super cool. The problem is, I am having a hell of a time getting them to work correctly. For instance, I have a shader file containing 3 shader techniques that would do different things to a model involving color. This one came straight out of my book, but I changed it to work with my own mesh. Here is the file: http://www.ethangar.com/shaders/shade.fx Now the problem arises when I try to use two of the shaders. The technique "TransformTextureNoBlue" works great. BUT, "TransformTexture" and "TransformInverseTexture" will just make my entire mesh disappear. WTF is going on. Is my mesh fucked up? Am I forgetting some device parameters? This computer has a GeForce 6800 Ultra, so I know my card is perfectly capable of all the shaders. I am also running in Pure mode. Anyone have any hints as to what might be up? Also, I tried to bump map a box once and I ended up with some crazy semi-transparent abortion of a box. Here is my messy code for the initialization of my device:
this.AssociatedSprites = new ArrayList();
this.AssociatedBackgrounds = new ArrayList();
this.AssociatedInput = new ArrayList();
this.AssociatedMeshes = new ArrayList();

Direct3D.PresentParameters presentParams = new Direct3D.PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = Direct3D.SwapEffect.Discard;
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = Direct3D.DepthFormat.D16;

bool canDoShaders = false;
DirectX.Direct3D.Caps hardware = DirectX.Direct3D.Manager.GetDeviceCaps(0, DirectX.Direct3D.DeviceType.Hardware);
if ((hardware.VertexShaderVersion >= new Version(1, 1)) &&
	(hardware.PixelShaderVersion >= new Version(1, 1)))
{
	// Default to software processing
	DirectX.Direct3D.CreateFlags flags = DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing;

	// Use hardware if it's available
	if (hardware.DeviceCaps.SupportsHardwareTransformAndLight)
		flags = DirectX.Direct3D.CreateFlags.HardwareVertexProcessing;

	// Use pure if it's available
	if (hardware.DeviceCaps.SupportsPureDevice)
		flags |= DirectX.Direct3D.CreateFlags.PureDevice;

	// Yes, Create our device
	device = new DirectX.Direct3D.Device(0, DirectX.Direct3D.DeviceType.Hardware, this, flags, presentParams);
}
else
{
	// No shader support
	canDoShaders = false;

	// Create a reference device
	device = new DirectX.Direct3D.Device(0, DirectX.Direct3D.DeviceType.Reference, this, 
		DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, presentParams);
}


//device = new Microsoft.DirectX.Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, Direct3D.CreateFlags.HardwareVertexProcessing, presentParams);

device.RenderState.AlphaBlendOperation = Direct3D.BlendOperation.Add;
device.RenderState.AlphaTestEnable = true;
device.RenderState.ReferenceAlpha = 0x08;
device.RenderState.AlphaFunction = Direct3D.Compare.GreaterEqual;

device.SetTextureStageState(0, Direct3D.TextureStageStates.AlphaOperation, true);
Also, another shader I really really want to get working was one I found in Render Monkey that has a nice ooze effect. You can find the stuff here: http://www.ethangar.com/shaders/ooze.rar If anyone can help me get that working, I would really appreciate it. Basically, I want to replace that sphere mesh that the ooze is being rendered on with a simple box mesh or a flat surface (an ocean of ooze as it were). If anyone could help me modify it for that and get it working in a managed directX project.

Share this post


Link to post
Share on other sites
Advertisement
I assume you are using "Managed DirectX Kickstart" (that code looks familiar [:D]). Anyways, id oubt the initialization of the device is the problem. Perhaps you could post your 3 techniques.

Just so I understand, you are saying that the "transformTexture" and "TransformInverseTexture" techiques will cause the mesh to disapear? If so, will it come back when you switch back to the first technique? Are you getting any DX errors or warnings? Are you sure the techniques are identical to the code in the book/CD? Are you sure the techniques are compiled to PS 1.1 (and nothing higher)?

Share this post


Link to post
Share on other sites
I noticed that this technique (that you said is working correctly)

technique TransformTextureNoBlue
{
pass P0
{
// shaders
//VertexShader = compile vs_1_1 Transform();
PixelShader = compile ps_1_1 TextureColorNoBlue();
}
}



has its vertex shader commented out. The other techniques do use your vertex shader, so maybe that's where the problem is.
While working in rendermonkey I noticed that if in the app the effect worked correctly and the mesh disappeared while in a DirectX window (when everything seemed to work correctly) is that because in DirectX, depending on how the effect is coded you may need to use the Transpose of the matrix you are using.
So if you are using without problems a WorldViewProj matrix in Rendermonkey and it doesn't work in DX try using the transpose of that matrix.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!