Sign in to follow this  

Problem with shaders, they don't seem to work

This topic is 3853 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 have tried to implement the shader and somehow they seemed don't work at all, they just don't apply. My rendertarget renders to texture and everything is ok, but the shader doesn't have effect on it. The texture itself renders fine. Ok here is some code, any ideas why? You know I was thinking maybe there is problem with Sprite (ID3DXSPRITE) .
blabla::init...()
{

	p_lpd3d9->GetRenderTarget(0,&Original);

	D3DXCreateSprite(p_lpd3d9,&Sprite);

	LPD3DXBUFFER errors = NULL;

	if(FAILED(D3DXCreateEffectFromFile(p_lpd3d9, "Simple.fx", NULL, NULL, 0,NULL, &effectShader, &errors)))
	{
		LPVOID compileErrors = errors->GetBufferPointer();
		   
        MessageBox(NULL, (const char*)compileErrors, "Shader Compile Error...",
                    MB_OK | MB_ICONEXCLAMATION);
	}

	p_lpd3d9->CreateTexture(800,600,0,D3DUSAGE_RENDERTARGET,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&Texture,NULL);
	Texture->GetSurfaceLevel(0,&Normal);

	p_lpd3d9->GetRenderTarget(0,&Original);

	CreateVbFull();

	return true;
}

void EngineCore::Render()
{
	p_lpd3d9->SetRenderTarget(0,Normal);
	p_lpd3d9->Clear(NULL,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,Global.GetDepthColor(), 1.0f, 0);
	p_lpd3d9->BeginScene();
	{	
		DXInput->UpdateDevices();
		Camera->Set();

		Effect->TakeScreenShot(DXInput,DIK_F8);
		Effect->Wireframe(DXInput,DIK_W);

		Light->Render();
		Tile->RenderRelease();
		
		Collision->Render();

		Particle->Render();

		MapEditor->Draw();
		
		//GameMenu->Render();

		if(GetAsyncKeyState(VK_ESCAPE)){ PostQuitMessage(0); }
	}
	p_lpd3d9->EndScene();

	p_lpd3d9->SetRenderTarget(0,Original);
	p_lpd3d9->Clear(NULL,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_RGBA(255,255,255,255), 1.0f, 0);
	p_lpd3d9->BeginScene();
	{
		
		D3DXMATRIX World;
		D3DXMatrixIdentity(&World);

		effectShader->SetTechnique("Simple");
		effectShader->SetMatrix( "WorldViewProj", &(World * Camera->View * Camera->Ortho2D) );
		effectShader->SetTexture("SimpleTexture", Texture);

		UINT Pass, Passes;
		effectShader->Begin(&Passes, 0);
		for (Pass = 0; Pass < Passes; Pass++)
		{
			effectShader->BeginPass(Pass);

			Sprite->Begin(0);
			Sprite->Draw(Texture,0,0,&D3DXVECTOR3(0,0,0),D3DCOLOR_RGBA(255,255,255,255));
			Sprite->End();

			effectShader->EndPass();
		}
		effectShader->End();

	}

	p_lpd3d9->EndScene();
	p_lpd3d9->Present(NULL,NULL,NULL,NULL);
}

[Edited by - Milleniumas on May 27, 2007 3:22:47 AM]

Share this post


Link to post
Share on other sites
Instead of:
effectShader->SetTechnique("Simple");
effectShader->SetMatrix( "WorldViewProj", &(World * Camera->View*Camera->Ortho2D) );
effectShader->SetTexture("SimpleTexture", Texture);

Try:
effectShader->SetTechnique(Simple);
effectShader->SetMatrix( WorldViewProj, &(World * Camera->View*Camera->Ortho2D) );
effectShader->SetTexture(SimpleTexture, Texture);

[Edited by - HarrisonPloeg on May 26, 2007 5:50:22 AM]

Share this post


Link to post
Share on other sites
We can't read your mind - you have given us almost NOTHING to work with here. Help us to help you. Dumping your code on us is really not that useful unless we know how it's failing - are functions returning errors? are you just getting the wrong results? what debugging have you tried? Any debug warnings/errors being issued? etc..etc..

Read the Updated FAQ (stuck to the top of this forum) for guidelines on how to write a good question/post in order to get the best possible replies. Whilst you're there, go read up on thread titles - yours is not appropriate and I would have changed it if only I knew what your thread was actually about [lol]


Jack

Share this post


Link to post
Share on other sites
You can use D3DXSPRITE_DONOTMODIFY_RENDERSTATE as a flag to ID3DXSprite::Begin. Otherwise the function sets the states as described in the docs page.

Share this post


Link to post
Share on other sites
Quote:
Original post by Milleniumas
I have found my problem.Shaders seemed not to work with ID3DXSprite at all and I believe it is not my programming fault so I change it to draw primitive :)


In fact it is your programming fault :) D3DXSPRITE works fine with shaders, I do it all the time..

Share this post


Link to post
Share on other sites

This topic is 3853 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.

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