• 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
KillerkoUK

How to make semi-transparent simple shadows not stack?

4 posts in this topic

Hi, everybody.

I have a simple top down 2d game that have a bunch of characters and objects on screen with very simple shadows.
Shadows are basically inverted sprites tinted black and rendered at about 80 alpha.
It all looks ok until the shadows of multiple characters/objects start to overlap.. then it will create this effect:

l5mDcOH.jpg

How could I make the shadows not to stack on each other?
 

I'm using HGE (haaf's game engine) and one idea I got was to render all shadows to texture at solid black and then render this texture at half alpha between my level and characters.
This sounded initially like it could work but I hit the wall with HGE and render to texture that does not support alpha :/ or at least I had no idea how to render to texture with alpha working. I tried to play with blend modes, googled, but the best I could get is kind of white-ish shadow with BLEND_ALPHAADD which will get rid of all the black thus creates the desired "alpha" but leaves me with 'white' sprite that looks more like a reflection on water than shadow :/

any other ideas?
or any solution how to get that alpha work with render to texture in HGE?

I also googled and found a few posts on the original hge forum how to modify hge source to make alpha work but that failed too as I was unable to compile the hge (even without any changes..) as I got a bunch or errors..

 

0

Share this post


Link to post
Share on other sites

One option would be to render all of your shadows onto an off screen gray-scale texture using a normal blending mode. You then draw that texture to the screen using a multiply with alpha letting you control how dark the shadow is. Unfortunately, the game engine you are using might not have the features to allow you to do that. I am not familiar with HGE so I cannot tell you if it would support that or not.

1

Share this post


Link to post
Share on other sites

Stenciling would have been my first inclination as well, but it sounds like you don't have that option within the confines of what you're working with..

 

http://hge.relishgames.com/doc/index.html?hgeconst_blendmode.html

 

It sounds like you already had it figured out, but just needed to use something more like BLEND_COLORMUL or BLEND_ALPHABLEND (making sure the shadow's pixels are black / dark gray).

 

If you already had a shadow working with additive blending, then it should be as simple as just using a different blend mode.

Edited by radioteeth
1

Share this post


Link to post
Share on other sites

2_Robert Bob and radioteeth:

this is what I found about stencil buffer and hge: http://relishgames.com/forum/index.php?p=/discussion/3081/stencil-buffer-in-hge/p1

is there any other way how I could use it? any example how? I am quite new, still learning and it might be out of my skill...

 

2_HappyCoder: this sounds like something I have already tried to do.. I rendered my shadow sprite as opaque using 'render to texture'.. (lets say on with white background, since alpha is not working) then I slap this rendered texture on sprite and render it on screen with default blending and I got this:

 

pQzQbtH.jpg

 

now all I needed to do is to use like you said some kind of multiply blend mode that would get rid of the white colour and I could use alpha to get the desired transparency.

sadly, hge does not have any multiply blend mode (or I have no idea how to use them)..

I could only get rid of black from the pic above with using BLEND_ALPHAADD (or if I render my sprite at normal color on black background then the oposite effect):

 

04AOZ5i.jpg

 

I haven't been able to get the result I need with the hge blending modes available.

 

There is another idea that I got how to get rid of the white and thats colour-keying... of course hge does not support this, but I managed to find this code on their forum that should do it:

 void SetMaskColor(HGE *hge , HTEXTURE tex , int w , int h , int r , int g , int b)
{
int x , y;
    DWORD *color = hge->Texture_Lock(tex, false);
    DWORD maskcolor = ARGB(255, r , g , b);
    DWORD *pixel;
 
    for (x = 0; x < w; ++x)
    {
        for (y = 0; y < h ; ++y)
        {
            pixel = &color[y*w+x];
            if((*pixel) == maskcolor)
                (*pixel) = 0;
        }
    }
    hge->Texture_Unlock(tex);
}

good news is that this works! I have tried it and it works, BUT it only works with HTEXTURE which are textures.. and I need it to work with HTARGET which is render target.. my 'rendered to texture'

now I'm not very good at this but I try to do something like:

HTEXTURE newTexture;
...
newTexture = hge->Target_GetTexture(targetShadowMap); // I try to copy my HTARGET which contains my rendered texture into HTEXTURE

?

?

?

?

?

?

?

unfortunately when I pass this newTexture with the function above the whole thing will crash... on the line: if((*pixel) == maskcolor) with the message:

"Unhandled exception at 0x00d7c4f2 in Project2.exe: 0xC0000005: Access violation reading location 0x00000000."

If I use the function with any other HTEXTURE which I initialized as "hge->Texture_Load("texture.png");" then it works fine.
 

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