Skip to main content
GameDev.net gamedev.net
🔒 Locked

effect technique validation fail

Started by mvtapia Jun 30, 2006 at 3:15 AM 8 replies 2k views
Original Post
mvtapia
mvtapia
hello everyone, I'm a rookie on shaders and I'm trying to implement one I got from the post-processing sample. Ok I deleted the things I did not think were important but even with the things I deleted I get a fail on the Effect->ValidateTechnique(hTech) here is the fx file

//-----------------------------------------------------------------------------
// File: PP_ColorMonochrome.fx
//
// Desc: Effect file for image post-processing sample.  This effect contains
//       a single technique with a pixel shader that converts colored image to
//       black & white by performing post-processing on a texture.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------


texture g_txSrcColor;

sampler2D g_samSrcColor =
sampler_state
{
    Texture = <g_txSrcColor>;
    AddressU = Clamp;
    AddressV = Clamp;
    MinFilter = Point;
    MagFilter = Linear;
    MipFilter = Linear;
};

//-----------------------------------------------------------------------------
// Pixel Shader: PostProcessPS
// Desc: Performs post-processing effect that converts a colored image to
//       black and white.
//-----------------------------------------------------------------------------
float3 LuminanceConv = { 0.2125f, 0.7154f, 0.0721f };

float4 PostProcessPS ( float2 Tex : TEXCOORD0 ) : COLOR0
{
    return dot( (float3)tex2D( g_samSrcColor, Tex ), LuminanceConv );
}

//-----------------------------------------------------------------------------
// Technique: PostProcess
// Desc: Performs post-processing effect that converts a colored image to
//       black and white.
//-----------------------------------------------------------------------------
technique ColorMC
{
    pass p0
    {
        VertexShader = null;
        PixelShader = compile ps_2_0 PostProcessPS();
        //ZEnable = true;
    }
}

now I don't know why I get a fail on the validation. any clues? thanks
Marco Tapia
MePHyst0
MePHyst0
There are basically two things that seem incorrect to me:

1) return dot( (float3)tex2D( g_samSrcColor, Tex ), LuminanceConv );
With this line you're returning a single value instead of the expected float4.
So, it should be something like this:
float grayScale = dot( (float3)tex2D( g_samSrcColor, Tex ), LuminanceConv );
return float4(grayScale,grayScale,grayScale,1.0);

2) VertexShader = null;
I don't really know if this is causing the validation failure, but I would recommend to try it with a simple vertex shader. To be honest, I have never had good experience with NULL shaders :)
mvtapia
mvtapia
that didn't do it. still fails the call. really I have no idea whats wrong. if I don't check it and let it run it give me a texture with a whole bunch on numbers.. like the matrix... haha... looks really funky..
Marco Tapia
MePHyst0
MePHyst0
Then I would try commenting out the global declarations section and leave just a fragment shader that returns a single color and probably you should try also compiling against a lower level shader profile.
jollyjeffers
jollyjeffers
Quote:
Original post by MePHyst0
1) return dot( (float3)tex2D( g_samSrcColor, Tex ), LuminanceConv );
With this line you're returning a single value instead of the expected float4.
So, it should be something like this:
float grayScale = dot( (float3)tex2D( g_samSrcColor, Tex ), LuminanceConv );
return float4(grayScale,grayScale,grayScale,1.0);
I don't think that is technically wrong - behind the scenes it should do almost what you said:
Quote:
Casting and Conversion (in the SDK documentation)
From: Scalar
To: Vector
Replicate the scalar source value into every component of the destination vector after applying the type casting and conversion behavior described in Type Casting.


Have you tried using the debug runtimes - see if it provides you with a more meaningful explanation as to why the ValidateTechnique() call failed?

Look up the "Validation" page in the SDK - it lists a few of the reasons why the call might fail (much better than the actual reference page!)...

Are you sure your target hardware supports ps_2_0?

Are you getting any compile errors? Tried running fxc.exe on it?

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
jamesw
jamesw
yeah like jollyjeffers said, look at the compile errors. How else do you write shaders? Open it in FX Composer and you will instantly know what is wrong.
mvtapia
mvtapia
Hello everyone, I downloaded the fx composer and tested the fx file and no problem it does everything it's suppose to do. the texture looks grayscale... so the effect has no problem, maybe is the way I'm calling it. I'm trying to implement the effect to the "programming a fps with directx" book engine. so I don't know if you are familiar with it. when I render the scene I call the fx for every material there is to draw. so I really don't know what is the problem.
Marco Tapia
mvtapia
mvtapia
Ok, here is the code I use to render the effect. don't worry too much about the {} there are some things I did not include above.

					D3DXHANDLE hTech;										Effect->SetTexture ( "g_txSrcColor" , m_material->GetTexture());					hTech=Effect->GetTechniqueByName("ColorMC");					//HRESULT h;					//h = Effect->ValidateTechnique(hTech);					//if (FAILED(h))					//		return;					Effect->SetTechnique( hTech );										// Begin Effects passes.					UINT cPasses;					Effect->Begin(&cPasses, 0);					for (UINT iPass = 0; iPass < cPasses; iPass++)					{						Effect->BeginPass(iPass);						// set Material and Texture.						//m_device->SetMaterial( m_material->GetLighting() );						//Effect->SetTexture ( "g_txSrcColor" , m_material->GetTexture());					    Effect->CommitChanges();						// Set the indicies to render the correct faces.						m_device->SetIndices( m_indexBuffer );						// Render all the faces.						m_device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, m_totalVertices, 0, m_faces );						Effect->EndPass();						}					Effect->End();


this is what I use to load the effect.

	// Load effects.	DWORD dwShaderFlags = 0; // Effects flags.    dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT;    dwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT;    dwShaderFlags |= D3DXSHADER_NO_PRESHADER;	D3DXCreateEffectFromFile (  				g_engine->GetDevice(), 				GetFilename(), 		        NULL,	// CONST D3DXMACRO* pDefines,				NULL,	// LPD3DXINCLUDE pInclude,				dwShaderFlags,				NULL,				&m_Effect, 				NULL );


anything will be really helpful
Marco Tapia
Namethatnobodyelsetook
Namethatnobodyelsetook
From the help... "D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT - Force the compiler to compile against the next highest available software target for pixel shaders. This flag also turns optimizations off and debugging on."

Note, there are NO software targets for pixel shaders when using D3DDEVTYPE_HAL, which is what you likely are, and want, to be using.
mvtapia
mvtapia
Thanks... that was it... can believe it was that simple... well I got the black and white working...
Thank you all..
Marco Tapia

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.