Jump to content

  • Log In with Google      Sign In   
  • Create Account


Basic DirectX 9 shader tutorial


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
17 replies to this topic

#1 AntonioR   Members   -  Reputation: 183

Like
0Likes
Like

Posted 03 March 2011 - 08:57 AM

Hi,

does anyone know where I can find some tutorial about implementing DirectX pixel shaders ?

Or maybe some example code or project I could see?

I don't know nothing about it, just that it uses some .fx files.

I would like to use it in a 2D game (that uses LPD3DXSPRITE to draw textures).

Thanks!

Sponsor:

#2 AntonioR   Members   -  Reputation: 183

Like
0Likes
Like

Posted 29 March 2011 - 02:31 PM

Some hints or tips just to get me started ?

I basically just want to do something simple, like increasing or reducing brightness of the whole scene, like you can see in the link below.

facewound shader examples

#3 DrunkMonkey25   Members   -  Reputation: 108

Like
0Likes
Like

Posted 30 March 2011 - 08:21 PM

My usual response:

Get Programming with DX9: A Shader Approach, by Frank Luna. It's very well done, and takes you from the verys basics to some pretty interesting effects.

If you can't get the book, I don't have any web resources handy. I've never searched extensively, but I'm sure you could find something.



#4 Illuminated   Members   -  Reputation: 109

Like
0Likes
Like

Posted 31 March 2011 - 01:40 AM

Yeah i would point to frank d. luna too.
If you didnt find source code or whatsoever here is a link to his source code in shader approach book.
link .Still you will need the book to understand most of the things.


#5 Shintah   Members   -  Reputation: 109

Like
0Likes
Like

Posted 31 March 2011 - 02:37 AM

You can check out the samples and tutorials that come with the DirectX SDK.

MSDN also contain quite a lot of information, here for example.

#6 AntonioR   Members   -  Reputation: 183

Like
0Likes
Like

Posted 31 March 2011 - 07:57 AM

Thanks guys for your response.

I was actually looking for something way simpler, written in "common english" since english is not my native tongue.

I found it last night here: http://www.two-kings...graphics18.html

So I used their method, and those "facewound" shaders, and it worked.

I was even able to figure out how "render to texture" works so I can apply a shader on the whole backbuffer / texture.

I will post some images later.

#7 AntonioR   Members   -  Reputation: 183

Like
0Likes
Like

Posted 31 March 2011 - 06:01 PM

Today I figured out how to render to a texture, so I can now apply a shader on the whole scene. I also learned how to use ID3DXEffect Interface.
Also I managed to write my own two simple shaders: "simplify colors" and "flash light".

Credits go to Garry Newman : http://www.facewound...orials/shader1/
and Two-Kings: http://www.two-kings...als/dxgraphics/

Here are some pics:

NEGATIVE
Posted Image

EMBOSSED
Posted Image

BLACK AND WHITE
Posted Image

SIMPLIFY COLORS (mine)
Posted Image

FLASHLIGHT (mine)
Posted Image

#8 DrunkMonkey25   Members   -  Reputation: 108

Like
0Likes
Like

Posted 01 April 2011 - 07:54 PM

Nicely done!

You mentioned in your first post that you wanted to use the D3DXSprite interface with shaders... Is that the approach you used in your screenshots? If so, I'm curious about any hoops you needed to jump through to render your sprites with shaders. In the book I mentioned, the author introduces the interface but does not give any specifics about using the interface with shaders (...yet, I have not completed the book). I have not had the time to write tests myself, so I thought I'd take the easy way out... :unsure:

So, is it as simple setting the shader and rendering the sprites?



#9 AntonioR   Members   -  Reputation: 183

Like
1Likes
Like

Posted 03 April 2011 - 12:22 PM

@DrunkMonkey25:

Yes, I use D3DXSprite to draw everything.
It ended up being really straight forward. This is the sprite draw method that I updated to use shaders. Sprite has a string "shader" which is used to set shader technique, if ShaderOn==true.
This way I can apply a different shader on every sprite I draw.

All sprites are drawn on the texture using this method, then that texture is drawn on the backbuffer (using the sprite handler (D3DXSprite) with a shader applied or not ) , and then I call Present.

void Sprite::draw()
	{
		//sprite transformation stuff

        int fx = (this->curframe % this->animcolumns) * this->width;
		int fy = (this->curframe / this->animcolumns) * this->height;
		RECT srcRect = {fx,fy, fx+this->width, fy+this->height};

		this->transform();
        //
		
		if (this->ShaderOn)
		{
     				g_engine->p_effect->SetTechnique(this->shader.c_str());
                	UINT passes = 0;
     				g_engine->p_effect->Begin(&passes, 0);
         			
                    g_engine->p_sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);
                    
         			if (passes>0)
     				{
     	      			g_engine->p_effect->BeginPass(i);
                   		g_engine->getSpriteHandler()->Draw(this->image->GetTexture(),&srcRect,NULL,NULL,color);
             		}
     				
     				g_engine->p_sprite_handler->End();

     				g_engine->p_effect->EndPass();
     				g_engine->p_effect->End();
                    
    	}
   	else
   	{
   	g_engine->p_sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);
   	g_engine->getSpriteHandler()->Draw(this->image->GetTexture(),&srcRect,NULL,NULL,color);
   	g_engine->p_sprite_handler->End();
   	}
    	
    }


#10 AntonioR   Members   -  Reputation: 183

Like
1Likes
Like

Posted 06 April 2011 - 11:01 AM

I made a short video of some pixel shader examples and my vector mode (not a shader) which draws sprite's bounding box instead of the texture.



#11 DrunkMonkey25   Members   -  Reputation: 108

Like
0Likes
Like

Posted 08 April 2011 - 10:11 PM

Nice! I'd be really effing proud if I were you! You went from 0 to 60 FAST!



#12 AntonioR   Members   -  Reputation: 183

Like
0Likes
Like

Posted 10 April 2011 - 11:48 AM

Nice! I'd be really effing proud if I were you! You went from 0 to 60 FAST!


Thanks, if I haven't found those two sites with simple examples I would be stuck.

The beginning is always the hardest part.

#13 AntonioR   Members   -  Reputation: 183

Like
0Likes
Like

Posted 19 April 2011 - 02:08 PM

If you like what I am doing here, you can like me some more on Facebook :-*

My Facebook page

#14 Burnt_Fyr   Members   -  Reputation: 1198

Like
0Likes
Like

Posted 19 April 2011 - 03:57 PM

There is definately some great work going on here... Am I mistaken or do I recognize that level from somewhere??? :)

#15 rays   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 April 2011 - 12:20 AM

nice work done...can u share the code..i am a starter of direct x programming and this would be a very good tutorial for me..

#16 AntonioR   Members   -  Reputation: 183

Like
0Likes
Like

Posted 20 April 2011 - 06:54 AM

There is definately some great work going on here... Am I mistaken or do I recognize that level from somewhere??? :)


Yes, the level design is not very original, but I am making a new one. ;)

nice work done...can u share the code..i am a starter of direct x programming and this would be a very good tutorial for me..


Which code do you need, pixel shaders (.fx files) or the engine ?

#17 rays   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 April 2011 - 11:43 PM


There is definately some great work going on here... Am I mistaken or do I recognize that level from somewhere??? :)


Yes, the level design is not very original, but I am making a new one. ;)

nice work done...can u share the code..i am a starter of direct x programming and this would be a very good tutorial for me..


Which code do you need, pixel shaders (.fx files) or the engine ?



well i would really appreciate if you share the engine code..cause i want to learn from the starting..
if you want my personal communication:
rays_kk@yahoo.com

#18 AntonioR   Members   -  Reputation: 183

Like
0Likes
Like

Posted 21 April 2011 - 04:28 AM

well i would really appreciate if you share the engine code..cause i want to learn from the starting..
if you want my personal communication:
rays_kk@yahoo.com


Oh, this is not my engine. I am just playing around with J.S. Harbour's Advanced2D engine.
It is a simple engine that uses DirectX for graphics and input, and Fmod for sound.
More info here: Advanced 2D Game Development

You can get the source code and some examples (DevC++ and Visual Studio) on his forum: J.S. Harbour forum

You can also download my example game. The archive has two DevC++ projects (not compiled), one is the engine, the other is my game which I commented in English, so it is very easy to understand how to use the engine and some of its methods . Split Horizon

http://www.megaupload.com/?d=VA853IOH
or
http://hotfile.com/dl/98011154/b9ec1ce/SplitHorizon_eng.rar.html

The only thing I forgot to put in the archive are some FMOD libraries, but you can find them on the forum with the source code, or I can upload them.
Be free to PM me for more info.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS