XNA Game Development Forums
2012/05/21 21:22:57 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: 1 2 3 [4]
  Print  
Author Topic: Tutorial 8 :: Post Processing Framework  (Read 18081 times)
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #45 on: 2007/01/07 18:31:49 »

Hmm not used to SMF, my clan board allows them "" but I guess not here, i'll keep that in mind, and thanks.

[NOTE] For those who haven't noticed, when trying it out, you can use the S and D keys to swap between the 2 Shaders included, this shows off the SetEffect method.
[EDIT2] A little addon Wink, if you would rather do it this way, here is the code for a ChangeTechnique function:
Code:
public void ChangeTechnique(string newTechnique)
{
    myEffect.CurrentTechnique = myEffect.Techniques[newTechnique];
}
Put that into the PostProcessor. Also here is the new working .fx file for Invert and Normal post processing.
Code:
sampler screenSample;

float4 PostNormal(float2 TexCoord : TEXCOORD0) : COLOR0
{
float4 col = tex2D(screenSample, TexCoord);
col.a = 1.0f;
return col;
}

float4 PostInvert(float2 TexCoord : TEXCOORD0) : COLOR0
{
float4 col = (float4)1.0f - tex2D(screenSample, TexCoord);
col.a = 1.0f;
return col;
}

technique Normal
{
pass p0
{
PixelShader = compile ps_2_0 PostNormal();
}
}
technique Invert
{
pass p0
{
PixelShader = compile ps_2_0 PostInvert();
}
}
Use that and change the swapping code in the demo to use the new function with the correct technique names.
« Last Edit: 2007/01/07 19:24:13 by Chr0n1x » Logged

mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #46 on: 2007/01/07 19:24:21 »

Okay, so I got the combined tutorial up on the sources topic and updated tut 9 and 10 to have the new version with spritebatching. Now I just have to figure out what in the database needs to change to get them in the right order in the posts Smiley

fun, fun, fun
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #47 on: 2007/01/07 20:32:20 »

-.-
Annoying, seems the old method might still be needed, if you wanna do basic post processing stuff, this new method is the way to go, but I think if you wanna do more advanced stuff that require you to edit the pixel shader to do your stuff, you might need to go with the old way, either way you now know both ways and can do them both. Remember, source code for the old method is still up on the filefront links.
Logged

Dodger_
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #48 on: 2007/02/14 07:31:16 »

Just running through Tutorial 8 now and I cannot get the post processor to work.  When I try it with the invert shader provided, it just shows a white square over the left side of the window and black for the rest.  It appears to not be sampling the the render target that should contain the scene.  Any suggestions on how to determine what is wrong?  I have double checked the source code and it is in-line with the tutorial's.

Solved: Simplest typos always seem to cause the most havoc; I had reversed the Width and Height when setting up the render target.

Also, small mistake(I believe) in the tutorial's source code:

Code:
public class HMPostProcessor {

should be:

Code:
public class HMPostProcessor : IHMLoadable {

edit: I have downloaded the tutorial 8 source code and that does compile and run properly on my machine so it has to be something in my source code.  Still hunting.
« Last Edit: 2007/02/14 08:49:05 by Dodger_ » Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #49 on: 2007/02/14 21:39:18 »

I never intended to add the IHMLoadable to my code, but if that provides improvements then go ahead and use it. Wink
I just didnt see any benefits from adding on some parents at the time, no use adding extra code.
Logged

mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #50 on: 2007/02/14 22:17:27 »

I think he is talking about my version Smiley Since I probably ended up using that interface.
Logged
Dodger_
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #51 on: 2007/02/15 05:16:49 »

I think he is talking about my version Smiley Since I probably ended up using that interface.
Yeah, you implement LoadGraphicsContent() in the class but did not declare that you were implementing the interface, I assume it was left out by mistake.  If there is a reason it is not there, I would love to hear it. Smiley
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #52 on: 2007/02/15 15:06:34 »

Ah very well then, thats Mikes problem then Tongue, although unless the PP Framework is being used in other ways than intended, that interface implementation is not needed.
Logged

mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #53 on: 2007/02/15 19:20:43 »

That's just my OCD design side wanting to keep everything consitant for loading and all Smiley
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #54 on: 2007/02/19 07:38:33 »

I have put this up as a reference from this thread[http://www.thehazymind.com/smf/index.php/topic,101.msg6051.html#msg6051]

My current version of the PP

Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Randomchaos3DEngine.PostProcessing
{
    public class RCPostProcessor
    {
        private string shaderFileName;
        private string myAsset;         
        private SpriteBatch mySpriteBatch;
        private Effect myEffect;

        private Color myClearColor;
        public Color ClearColor
        {
            get { return myClearColor; }
            set { myClearColor = value; }
        }

        public Effect Effect
        {
            get { return myEffect; }
        }
        public Effect Shader
        {
            get { return myEffect; }
            set { myEffect = value; }
        }
        public string Asset
        {
            get { return shaderFileName; }
        }

        private RenderTarget2D myRenderTarget;
        private VertexBuffer vb;
        private IndexBuffer ib;
        private VertexDeclaration vDecl;
        private int numVertices;
        private int numIndices;
        private int numPrimitives;
        private int bytesPerVertex;

        private Texture2D myTvAndNoiseTexture;
        private float myTime;

        public void LoadGraphicsContent(GraphicsDevice myDevice, ContentManager myLoader)
        {
            myRenderTarget = new RenderTarget2D(myDevice, myDevice.Viewport.Width, myDevice.Viewport.Height, 1, myDevice.DisplayMode.Format);
            if (myAsset != null)
            {
                myEffect = myLoader.Load<Effect>(myAsset);
                mySpriteBatch = new SpriteBatch(myDevice);
            }
            else if(shaderFileName != null)
            {
                myEffect = myLoader.Load<Effect>(shaderFileName);
                MakeQuadMesh(myDevice);
            }

            try
            {
                myTvAndNoiseTexture = myLoader.Load<Texture2D>("Content/Textures/Gray");
            }
            catch { }
        }

        private void MakeQuadMesh(GraphicsDevice myDevice)
        {
            numVertices = 4;
            bytesPerVertex = VertexPositionTexture.SizeInBytes;
            VertexPositionTexture[] vertices = new VertexPositionTexture[numVertices];
            numPrimitives = 2;
            numIndices = 3 * numPrimitives;
            short[] indices = new short[numIndices];

            float dx = -1f / myDevice.Viewport.Width;
            float dy = 1f / myDevice.Viewport.Height;

            vertices[0] = new VertexPositionTexture(new Vector3(-1 + dx, -1 + dy, 0), new Vector2(0, 1));
            vertices[1] = new VertexPositionTexture(new Vector3(1 + dx, -1 + dy, 0), new Vector2(1, 1));
            vertices[2] = new VertexPositionTexture(new Vector3(1 + dx, 1 + dy, 0), new Vector2(1, 0));
            vertices[3] = new VertexPositionTexture(new Vector3(-1 + dx, 1 + dy, 0), new Vector2(0, 0));

            indices[0] = 1;
            indices[1] = 3;
            indices[2] = 2;

            indices[3] = 3;
            indices[4] = 1;
            indices[5] = 0;

            vDecl = new VertexDeclaration(myDevice, VertexPositionTexture.VertexElements);
            vb = new VertexBuffer(myDevice, bytesPerVertex * numVertices, ResourceUsage.None, ResourceManagementMode.Automatic);
            vb.SetData<VertexPositionTexture>(vertices);
            ib = new IndexBuffer(myDevice, numIndices * 2, ResourceUsage.None, ResourceManagementMode.Automatic, IndexElementSize.SixteenBits);
            ib.SetData<short>(indices);
        }

        public void SetPPShader(string assetName)
        {
            if(myAsset == null) // Make sure we dont endup loading them both. (for now)
                shaderFileName = assetName;
        }
        public void SetEffect(string newAsset)
        {
            myAsset = newAsset;
        }

        public void ReloadEffect(ContentManager myLoader)
        {
            if (shaderFileName != null)
                myEffect = myLoader.Load<Effect>(shaderFileName);
            else
                myEffect = null;
        }

        public void PreRender(GraphicsDevice myDevice)
        {           
            myDevice.SetRenderTarget(0, myRenderTarget);
        }

        public void PostRender(GraphicsDevice myDevice)
        {
            myDevice.ResolveRenderTarget(0);
            myDevice.SetRenderTarget(0, null);
            if (myAsset != null)
            {
                myEffect.Begin();

                if (myEffect.Parameters["BlurStrength"] != null)
                    myEffect.Parameters["BlurStrength"].SetValue(0.9f);

                mySpriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState);
                               
                for(int ps=0;ps<myEffect.CurrentTechnique.Passes.Count;ps++)
                {
                    myEffect.CurrentTechnique.Passes[ps].Begin();
                    mySpriteBatch.Draw(myRenderTarget.GetTexture(), Vector2.Zero, Color.White);
                    myEffect.CurrentTechnique.Passes[ps].End();
                }

                mySpriteBatch.End();
                myEffect.End();
            }
            else
            {
                myDevice.Clear(myClearColor);

                myEffect.Begin();

                // PostProc.fx
                if (myEffect.Parameters["ScreenTex"] != null)
                    myEffect.Parameters["ScreenTex"].SetValue(myRenderTarget.GetTexture());
                if (myEffect.Parameters["neg"] != null)
                    myEffect.Parameters["neg"].SetValue(false);

                // bloom.fx
                if (myEffect.Parameters["WindowSize"] != null)
                    myEffect.Parameters["WindowSize"].SetValue(new Vector2(myDevice.Viewport.Height, myDevice.Viewport.Width));
                if (myEffect.Parameters["ClearColor"] != null)
                    myEffect.Parameters["ClearColor"].SetValue(Color.CadetBlue.ToVector4());
                if (myEffect.Parameters["SceneMap"] != null)
                    myEffect.Parameters["SceneMap"].SetValue(myRenderTarget.GetTexture());
                if (myEffect.Parameters["DepthMap"] != null)
                    myEffect.Parameters["DepthMap"].SetValue(myRenderTarget.GetTexture());
                if (myEffect.Parameters["DownsampleMap"] != null)
                    myEffect.Parameters["DownsampleMap"].SetValue(myRenderTarget.GetTexture());
                if (myEffect.Parameters["HBlurMap"] != null)
                    myEffect.Parameters["HBlurMap"].SetValue(myRenderTarget.GetTexture());
                if (myEffect.Parameters["FinalBlurMap"] != null)
                    myEffect.Parameters["FinalBlurMap"].SetValue(myRenderTarget.GetTexture());

                for(int ps=0;ps<myEffect.CurrentTechnique.Passes.Count;ps++)
                {
                    myEffect.CurrentTechnique.Passes[ps].Begin();

                    myDevice.VertexDeclaration = vDecl;
                    myDevice.Vertices[0].SetSource(vb, 0, bytesPerVertex);

                    myDevice.Indices = ib;
                    myDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numPrimitives);

                    myEffect.CurrentTechnique.Passes[ps].End();
                }
                myEffect.End();
            }
        }
    }
}


I use SetPPShader to call the old PP shaders and SetEffect for the newer ones.
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #55 on: 2007/02/22 01:20:45 »

Code design for the new framework complete, im gonna send it to Mike so he can rename the variables to his style and then ill get the tutorial written up, so possibly this weekend. No guarantees though, i've got a maths exam on Monday. Sad
New system, cleaner code in the HMGame class, and can be derived for multiple render targets or shaders. I will write up a tutorial for that later on. Also this now supports multisampling, whereas the other one didn't.

Please note, when I put the new stuff up, this thread will be locked and a new one opened for discussion of that. Also I will be taking down the other tutorials.

[Reopened for problems if any. New tutorial probably cancelled, there are many ways to do this and depending on your needs can be very different. My intention now is to explain the core steps and give an understanding of the feature rather than providing a class to be used in any situation. For now the current tutorials will suffice.]
« Last Edit: 2007/05/12 04:25:09 by chr0n1x » Logged

Shamun
Newbie
*
Offline Offline

Posts: 12


View Profile
« Reply #56 on: 2007/06/15 02:27:25 »

Why when I try to combine the skull model with the BS shader and the tiger model with the TT shader I don't see the tiger?
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #57 on: 2007/06/15 02:58:03 »

I'm not quite sure what that has to do with Post Processing, could you elaborate what the post processing problem is?
Logged

Shamun
Newbie
*
Offline Offline

Posts: 12


View Profile
« Reply #58 on: 2007/06/15 03:24:45 »

I didn't use the post processing while I was trying to use the BS and the TT...
But for some reason they don't work together (BS & TT) altough they should be
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #59 on: 2007/06/15 03:41:52 »

This thread is for problems with the post processing framework, I think your problem would probably be best posted in the XNA engine discussion forum.
Logged

Pages: 1 2 3 [4]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Tutorial 14 Hazy Mind 3D Engine serus 3 3901 Last post 2008/12/19 10:32:01
by mikeschuld
Tutorial 1 :: Introduction to the XNA Framework Tutorial Discussion « 1 2 3 » mikeschuld 32 12695 Last post 2007/08/14 21:46:09
by mikeschuld
Tutorial 2 :: Scene Graph and Object Framework Tutorial Discussion « 1 2 » mikeschuld 18 10053 Last post 2008/07/31 22:50:22
by mikeschuld
Next Tutorial Hazy Mind XNA Engine mikeschuld 12 4871 Last post 2006/11/12 15:40:51
by mikeschuld
Having issues with tutorial 3 Hazy Mind XNA Engine siferion 4 2377 Last post 2006/11/26 14:04:03
by mikeschuld
Tutorial 3 Hazy Mind XNA Engine hansonc 4 2482 Last post 2007/03/27 09:23:23
by hansonc
Post Processing Hazy Mind XNA Engine Robin Sarac 3 1595 Last post 2007/04/21 19:23:20
by Arkcann
Tutorial 2 Hazy Mind XNA Engine Classicwarrior 5 2687 Last post 2008/05/17 23:01:31
by Classicwarrior
Post Tutorial 8 - advice needed! Hazy Mind XNA Engine solthar 5 2245 Last post 2008/09/03 20:47:57
by solthar
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.169 seconds with 19 queries.