Jump to content
  • Advertisement
Sign in to follow this  
Green Gandalf

how to render to texture using FX Composer

This topic is 4228 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've been trying to write an HLSL FX file in FX Composer to illustrate the use of an intermediate render target. However I am having difficulty getting something very simple to work (when I've got that right I can move on to something more interesting). In my simple example I am trying to read a texture and process it using two passes: 1. the first pass merely removes the green component from the colour and sends the output to an intermediate render target; 2. the second pass merely adds full purple to the result of the first pass and so the result should be full purple for all pixels. I realise there is no need for two passes to do this in this instance, I'm merely trying to test the mechanics of working with an intermediate target, so I can write efficient two pass blur and glow shaders for example. I've tried adjusting various variables but all I ever achieve is either a garbled image, a purple image with white patches or the red, blue and black image from the first pass. The latest version of my FX file which compiles in FX Composer is the following: ---------------------------------------------- // Green Gandalf's render target practice // // Created 13 November 2006, modified 15 November 2006. float Script : STANDARDSGLOBAL < string UIWidget = "none"; string ScriptClass = "object"; string ScriptOrder = "standard"; string ScriptOutput = "color"; string Script = "Technique=GGTest;"; > = 0.8; float4x4 wvp : WorldViewProjection < string UIWidget = "none"; >; float4 noGreen = {1.0, 0.0, 1.0, 1.0}; float4 hiPurple = {1.0, 0.0, 1.0, 1.0}; float4 ClearColor = {0.0, 0.0, 0.0, 0.0}; float ClearDepth = 1.0; texture renderTexture : RenderColorTarget < float2 Dimensions = { 256, 256 }; int MipLevels = 1; string Format = "A8R8G8B8" ; string UIWidget = "None"; >; sampler renderSample = sampler_state { Texture = (renderTexture); AddressU = Clamp; AddressV = Clamp; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = POINT; }; texture baseTexture < string ResourceName = "test image.png"; >; sampler baseSample = sampler_state { Texture = <baseTexture>; ADDRESSU = Clamp; ADDRESSV = Clamp; MIPFILTER = LINEAR; MINFILTER = LINEAR; MAGFILTER = LINEAR; }; struct VSInput { float4 Pos: POSITION; float2 UV: TEXCOORD0; }; struct VSOutput { float4 Pos: POSITION; float2 UV: TEXCOORD0; }; VSOutput VShader( VSInput In, VSOutput Out ) { Out.Pos = mul(In.Pos, wvp); Out.UV = In.UV; return Out; } struct PSInput { float2 UV: TEXCOORD0; }; struct PSOutput { float4 Col: COLOR; }; PSOutput PShader1( PSInput In, PSOutput Out ) { // Remove green component Out.Col = tex2D(baseSample, In.UV) * noGreen; return Out; } PSOutput PShader2( PSInput In, PSOutput Out ) { // Add full purple Out.Col = tex2D(renderSample, In.UV) + hiPurple; return Out; } technique GGTest < string ScriptClass = "object"; string ScriptOrder = "standard"; string ScriptOutput = "color"; string Script = "RenderColorTarget0=renderSample;" "ClearSetColor=ClearColor;" "ClearSetDepth=ClearDepth;" "Pass=P1;" "Pass=P2;"; > { pass P1 < string Script = "RenderColorTarget0=renderSample;" "Draw=Geometry;"; > { // reads the base texture, removes the green component // and outputs the result to the intermediate // render target defined by <renderSample> // no vertex shader needed PixelShader = compile ps_1_1 PShader1(); } pass P2 < string Script = "RenderColorTarget0=;" "Draw=Geometry;"; > { // reads the intermediate render target texture created by // the first pass, modifies it by adding full purple // and outputs it - result should be all purple, but isn't PixelShader = compile ps_1_1 PShader2(); } } ------------------------------------------------------------------------- I'm obviously misunderstanding something very basic - but can't find any explanations of how to use the various script commands - or I may be having a GFX card problem (I'm using a GeForce FX 5200 on one machine and an ATI Mobility Radeon Xpress 200 on the other - giving similar results). Any help would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
I have been having a lot of hard time with Render Targets aswell. I am new to shaders, but I would look at your pass scripts, and having them draw to geometry. I would try maybe a buffer or scene.

take a look at this http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c_Summer_04/directx/graphics/reference/EffectFileReference/EffectFileFormat/StandardAnnotations/tandardAnnotationScriptingSyntax.asp

which is the annotations and what they do.

Not much help, but maybe a start.

Share this post


Link to post
Share on other sites
Thanks for responding. I'll have a look at the reference you give - that sort of info is hard to track down.

"I have been having a lot of hard time with Render Targets aswell. I am new to shaders, but I would look at your pass scripts, and having them draw to geometry. I would try maybe a buffer or scene."

Yes, I tried various things along those lines, but couldn't get anything to work - perhaps your link will help.

"take a look at this http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c_Summer_04/directx/graphics/reference/EffectFileReference/EffectFileFormat/StandardAnnotations/tandardAnnotationScriptingSyntax.asp

which is the annotations and what they do."

Will do.

"Not much help, but maybe a start."

I hope so. Thanks - I'll let you know how I get on.

P.S. How do you mark code snippets and quotes on this board?

Share this post


Link to post
Share on other sites
http://www.gamedev.net/community/forums/faq.asp#tags
That's how you make the tags for code snippets. I just use the C++ one for shaders.

Let me know if you find out anything I have been working one for a while and no such luck. I also tried to add a depth target to clear it out and no such luck with that so far.

Share this post


Link to post
Share on other sites
Cheers - don't know why I didn't look at the FAQ's first...

I'll certainly post a reply if I come up with an answer.

Your original link didn't tell me much more than the Helps in FX Composer - neither tell you exactly what the various options do. Haven't systematically checked yet though - been otherwise occupied for a few days. Back to normal by end of week I hope.

Thanks for helping and I'll post progress.

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!