Sign in to follow this  
aqez

Shader problem!?[SOLVED]

Recommended Posts

Alright.. I haven't had TOO much experience with programming shaders, and in my game engine I'm finally to that point(and I say finally because I did a LOT of foundation planning). So, I've played with the shaders in the directx10 samples of course, and from what I see my shader isn't wrong.. but obviously I'm missing something( simple I'd guess because shaders themselves are fairly simple right? ), and hopefully someone here can point it out to me so that I don't have to download an fx tool(Reason being I'm on my laptop, desktops down for the holidays as I sold my processor to someone as a present for their son, and am getting another yay!(I use a lot of parentheses don't I?)) Anyway the shader is as follows:
matrix World;
matrix Projection;
matrix View;
Texture2D gTex;
float4 gColor; //Comes from application code
//-----------------------------
// Texture Sampling State
//-----------------------------
SampleSate samLinear
{
	Filter = MIN_MAG_MIP_LINEAR;
	AddressU = Wrap;
	AddressV = Wrap;
};


//-----------------------------
// Pixel Shader input structure
//-----------------------------
struct PS_INPUT
{
	float4 Pos : SV_POSITION;
	float2 Tex : TEXCOORD0;
};

//--------------
// Vertex Shader
//--------------
PS_INPUT VS( float4 Pos : POSITION, float2 Tex : TEXCOORD )
{
	PS_INPUT output;

	output.Pos = mul(Pos, Projection);
	output.Tex = Tex;
	return output;
}

float4 PS( PS_INPUT input ) : SV_TARGET
{
	float4 color = float4( 0.0f, 1.0f, 1.0f, 0.0f );
	return gTex.Sample( samLinear, input.Tex ) * input.color;
}

technique10 Render
{
	pass P0
	{
		SetVertexShader( CompileShader( vs_4_0, VS() ) );
		SetGeometryShader( NULL );
		SetPixelShader( CompileShader( ps_4_0, PS() ) );
	}	
}
So that's it.. a few explanations! I'm fairly new to shaders, so this one is meant to be a 'test' shader to check out the engine and make sure all the vertices/normals/texcoords are in their respective places in memory and that I've got them loaded the way I want them etc. So I just wanted it to be simple, a position and a texture coordinate. I'm wide open to criticism and pointers as well as hopefully a fix. Also, the reason I know it's my shader is I loaded a few of the directx samples' shaders and they all worked. Of course only until the access violation as they don't comply with the layout of my engine. But they DID load, unlike the one I've posted here. So! Help me out, criticize my code, flame, and make smart remarks to your hearts content! <3 Edit: A little additional info.. File is called ZipShader.fx:
	hr = D3DX10CreateEffectFromFile( L"ZipShader.fx", NULL, NULL, "fx_4_0", dwShaderFlags, 0, device, NULL,
                                         NULL, &effect, NULL, NULL );

	if( FAILED( hr ) )
	{
		console->writeConsole("Failed to load shader.\n");
		return hr;
	}
This fails each time I use my shader, but not when I use a directx sample shader. [Edited by - aqez on December 23, 2009 7:52:21 PM]

Share this post


Link to post
Share on other sites



ID3D10Blob* pErrorsBlob = 0;

hr = D3DX10CreateEffectFromFile( ..., &pErrorsBlob, ... );

if( pErrorsBlob )
{
char* pErrorText = reinterpret_cast<char*>( pErrorsBlob->GetBufferPointer() );


Share this post


Link to post
Share on other sites
Can't thank you enough for that snippet, turns out a typo! SampleSate instead of SamplerState. Appreciate the help a lot. Two typos in one word, amazing haha, goes to show how much I rely on that red squiggly line. Also the other error was I changed the Color variable of PS_INPUT structure to be global and didn't reflect that in one part of the code, everything compiles and works now! Thanks a ton again.

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