Sign in to follow this  
MTclip

PIXEL SHADER.. why wont you work..

Recommended Posts

MTclip    242
HEy. Ok i am trying to just get a simple pixel shader to work.. first i have rendered to a texture then i am drawing that texture to the screen using a sprite... I know this works.... but.. when i try to pixel shade the texture nothing... ALL it should do is make the screen brighter.. but instead it does nothing to the image... I must not be getting something any ideas?? HERE IS MY SIMPLE FX FILE..
[SOURCE]
texture screenShot;
sampler2D sample = sampler_state
{
	Texture = (screenShot);
	mipfilter = LINEAR;
};
float4 MyShader( float2 Tex : TEXCOORD0 ) : COLOR0
{
    float4 Color;
    
    Color =  tex2D( screenShot, Tex.xy) * 15;
    return Color;
}

technique PostProcess
{
    pass Pass0
    {
        VertexShader = null;
        PixelShader = compile ps_2_0 MyShader();
    }
}
[/SOURCE]
HERE IS MY INIT FOR THE SHADER...
[SOURCE]

HRESULT hr;
		LPD3DXBUFFER pBufferErrors = NULL;
		hr = D3DXCreateEffectFromFile( g_pd3dDevice,"my.fx",NULL, NULL, 
								   0,NULL,&g_Effect,&pBufferErrors );
		if( FAILED(hr) )
		{
			LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
			MessageBox(NULL, (const char*)pCompilErrors, "Fx Compile Error",
				MB_OK|MB_ICONEXCLAMATION);
		}
		
		hr = g_Effect->ValidateTechnique("PostProcess");
		if( FAILED(hr) )
		{
			LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
			MessageBox(NULL, (const char*)pCompilErrors, "Fx Compile Error",
				MB_OK|MB_ICONEXCLAMATION);
		}

[/SOURCE]
HERE IS MY CALL TO THE SHADER
[SOURCE]
	g_pd3dDevice->BeginScene();
		
		g_Effect->SetTechnique( "PostProcess" );
		g_Effect->SetTexture( "screenShot", g_renderTexture );
		
		g_pd3dDevice->SetRenderTarget( 0, g_backbuffer);	
		g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER ,
                         D3DCOLOR_COLORVALUE(0.35f, 0.53f, 0.7, 1.0f), 1.0f, 0);

		g_screenSprite->Begin( D3DXSPRITE_ALPHABLEND );

		UINT uPasses;
		g_Effect->Begin( &uPasses, 0 );
    
		for( UINT uPass = 0; uPass < uPasses; ++uPass )
		{
			g_Effect->BeginPass( uPass );
			g_screenSprite->Draw(g_renderTexture,NULL,NULL,NULL,
								 D3DCOLOR_ARGB(255,255,255,255));
			g_Effect->EndPass();
		}
 
		g_Effect->End();
		
		g_screenSprite->End();
		g_pd3dDevice->EndScene();

[/SOURCE]

Share this post


Link to post
Share on other sites
S1CA    1418
Take a look at the documentation for ID3DXSprite::Begin, you'll notice that it sets a lot of render states internally. IIRC it will also use the fixed function pipeline internally (thus ignoring your pixel shader).

Share this post


Link to post
Share on other sites
technology    122
Quote:
Original post by MTclip
What function are you refering to?

the FX file ... of the call to create the fx file??


i mean the whole shader inside FX file.

Share this post


Link to post
Share on other sites
MTclip    242
im not sure if it is diffrent in directx 8... but the shader that i posted first had an error in it...

try this

texture screenShot;
sampler2D sample = sampler_state
{
Texture = (screenShot);
mipfilter = LINEAR;
};
float4 MyShader( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 Color;

Color = tex2D( sample, Tex.xy) * 15;
return Color;
}

technique PostProcess
{
pass Pass0
{
VertexShader = null;
PixelShader = compile ps_2_0 MyShader();
}
}




All this shader does is make the image really bright ovrerexposed if you will

Share this post


Link to post
Share on other sites
Guimo    463
Hi, this is the FX file I use in order to render my quads. I use Transformed Lit vertices when using this hader so I have no need of a vertex shader. In this case a pixel shader is not required.

This is the minimum shader of my engine and always loaded at startup. I use that basic load in order to register shared parameters. If you don'nt need shared params then just delete all the initial declarations (except the tex0:DIFFUSE which you will need in order to set the textures to be used in the shader).

Luck!
Guimo

------------------------------------------------------------------
//Basic TransformedLit shader
//Guillermo Rodriguez - Spritekin Entertainment 2004
//The idea is just to share some parameters that may be useful
// to any application to set only once like transformation matrices
shared float4x4 View : VIEW;
shared float4x4 ViewIT : VIEWINVERSETRANSPOSE;
shared float4x4 Projection : PROJECTION;
shared float4x4 ViewProjection : VIEWPROJECTION;
shared float Time : TIME;
texture Tex0 : DIFFUSE;

//This is a dummy shader. Just to allow D3D to load this effect
//Usually this shader will be ignored if the vertices FVF are set
// with the RHW flag (understood as TLVertices)
sampler Sampler = sampler_state
{
Texture = (Tex0);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};

technique K3DFXTransformedLit
{ pass P0
{ Lighting = FALSE;
VertexShader = NULL;
PixelShader = NULL;

Sampler[0] = (Sampler);

// texture stages
ColorOp[0] = MODULATE;
ColorArg1[0] = TEXTURE;
ColorArg2[0] = DIFFUSE;
ColorOp[1] = DISABLE;

AlphaOp[0] = MODULATE;
AlphaArg1[0] = TEXTURE;
AlphaArg2[0] = DIFFUSE;
AlphaOp[1] = DISABLE;

AlphaBlendEnable = TRUE;
SrcBlend = SRCALPHA;
DestBlend = INVSRCALPHA;

//Alpha filter=0
AlphaTestEnable = TRUE;
AlphaRef = 0x00000000;
AlphaFunc = GREATER;
}
}
----------------------------------------------------


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this