• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
AntonioR

Basic DirectX 9 shader tutorial

17 posts in this topic

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!
0

Share this post


Link to post
Share on other sites
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.

[url="http://www.facewound.com/tutorials/shader1/"]facewound shader examples[/url]
0

Share this post


Link to post
Share on other sites
My usual response:

Get [u]Programming with DX9: A Shader Approach[/u], 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.

0

Share this post


Link to post
Share on other sites
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.
[url="http://d3dcoder.net/d3d9c.htm"]link[/url] .Still you will need the book to understand most of the things.
0

Share this post


Link to post
Share on other sites
You can check out the samples and tutorials that come with the DirectX SDK.

MSDN also contain quite a lot of information, [url="http://msdn.microsoft.com/en-us/library/ms810449.aspx"]here[/url] for example.
0

Share this post


Link to post
Share on other sites
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: [url="http://www.two-kings.de/tutorials/dxgraphics/dxgraphics18.html"]http://www.two-kings...graphics18.html[/url]

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.
0

Share this post


Link to post
Share on other sites
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 : [url="http://www.facewound.com/tutorials/shader1/"]http://www.facewound...orials/shader1/[/url]
and Two-Kings: [url="http://www.two-kings.de/tutorials/dxgraphics/"]http://www.two-kings...als/dxgraphics/[/url]

Here are some pics:

NEGATIVE
[img]http://img192.imageshack.us/img192/2598/projectstudenttoni20110.jpg[/img]

EMBOSSED
[img]http://img816.imageshack.us/img816/2598/projectstudenttoni20110.jpg[/img]

BLACK AND WHITE
[img]http://img545.imageshack.us/img545/2598/projectstudenttoni20110.jpg[/img]

SIMPLIFY COLORS (mine)
[img]http://img204.imageshack.us/img204/2598/projectstudenttoni20110.jpg[/img]

FLASHLIGHT (mine)
[img]http://img708.imageshack.us/img708/2598/projectstudenttoni20110.jpg[/img]
0

Share this post


Link to post
Share on other sites
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?

0

Share this post


Link to post
Share on other sites
@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.

[code]
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();
}

}
[/code]
1

Share this post


Link to post
Share on other sites
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.

[media]http://www.youtube.com/watch?v=BL8T7uw7ERE[/media]
1

Share this post


Link to post
Share on other sites
[quote name='DrunkMonkey25' timestamp='1302322313' post='4796206']
Nice! I'd be really effing proud if I were you! You went from 0 to 60 FAST!
[/quote]

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

The beginning is always the hardest part.
0

Share this post


Link to post
Share on other sites
If you like what I am doing here, you can like me some more on Facebook :-*

[url=http://www.facebook.com/pages/AntonioR-Software/193787573997917]My Facebook page[/url]
0

Share this post


Link to post
Share on other sites
There is definately some great work going on here... Am I mistaken or do I recognize that level from somewhere??? :)
0

Share this post


Link to post
Share on other sites
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..
0

Share this post


Link to post
Share on other sites
[quote name='Burnt_Fyr' timestamp='1303250263' post='4800529']
There is definately some great work going on here... Am I mistaken or do I recognize that level from somewhere??? :)
[/quote]

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

[quote name='rays' timestamp='1303280416' post='4800666']
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..
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='AntonioR' timestamp='1303304074' post='4800741']
[quote name='Burnt_Fyr' timestamp='1303250263' post='4800529']
There is definately some great work going on here... Am I mistaken or do I recognize that level from somewhere??? :)
[/quote]

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

[quote name='rays' timestamp='1303280416' post='4800666']
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..
[/quote]

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


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
0

Share this post


Link to post
Share on other sites
[quote name='rays' timestamp='1303364611' post='4801110']
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
[/quote]

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: [url="http://www.gamedev.net/page/books/index.html/_/game-development-31/advanced-2d-game-development-r715"]Advanced 2D Game Development[/url]

You can get the source code and some examples (DevC++ and Visual Studio) on his forum: [url="http://theharbourfamily.com/jonathan/forum/index.php"]J.S. Harbour forum[/url]

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 . [url="http://www.youtube.com/watch?v=p4jOGMa6tKY"]Split Horizon[/url]

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

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.
0

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  
Followers 0