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

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

## 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.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

// 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.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 on other sites
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 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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 24
• 42
• 75