views:

779

answers:

3

I have a simple application in which I need to let the user select a shader (.fx HLSL or assembly file, possibly with multiple passes, but all and only pixel shader) and preview it.

The application runs, the list of shaders comes up, and a button launches the "preview window." From this preview window (which has a DirectX viewport in it), the user selects an image and the shader is run on that image and displayed. Only one frame needs rendered (not real-time).

I have a vertex/pixel shader combination set up that takes a quad and renders it to the screen, textured with the chosen image. This works perfectly. I need to then run another effect, purely pixel shader, on the output from the first effect, and display the final image (post-processed) to the screen. This doesn't work at all.

I've tried for the past few days to get it working, but for no apparent reason, the identical code blocks used to render each effect only render the first. I can add the second shader file as a second pass in the first shader file and it runs perfectly (although completely defeats my goal of previewing user-created shaders). When I try to use a second effect (which loads and compiles just fine), it does nothing. I've taken the results of the first shader (with GetRenderTargetData) and placed them in a texture & surface (destTex and destSur), then set that texture as the input for the second pass (using dev->SetTexture and later effect->SetTexture("thisframe", destTex)).

All calls succeed, effects compile, textures load, quads are drawn, but the effect is not visible. I suspected at first the device (created with software vertex processing) was causing the issue, but that doesn't seem to be the case (I tried with hardware and mixed). Additionally, using both a HAL and REF device (not a problem, since the app isn't realtime anyways), that second shader isn't visible. Everything is written in C++ for Direct3D 9.

A: 

There must be some kind of vertex input and vertex processing (either fixed-function or shader) in order for the pixel shader to be run. Are you supplying the vertex shader, and if so are you sure it does what the pixel shader expects? What does your draw call look like?

It's probably worth looking at a PIX trace of your app to see what the device state is when trying to use the user effect.

Jesse Hall
A: 

First Create a texture, then render the first shader directly into that texture. Finally render the second shader with the texture as input to the Backbuffer.

gufftan
+1  A: 

Try clearing the depth-stencil buffer after each time you render the quad.

Daniel Dimovski