• 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
Gavin Williams

Losing my alpha channel somewhere !

11 posts in this topic

I'm trying to render a quad (with character sprite from a spritesheet) over the top of my terrain. But I seem to be losing my alpha data, I'm saving my 32bit bitmap out of photoshop, and I've checked that the alpha channel is still there using Pixelformer (which shows alpha clearly)

[img]http://i44.tinypic.com/2cf60k4.jpg[/img]

Here's the shader code that should demonstrate the alpha channel :

[CODE]
float4 finalColor = gSpriteSheet.Sample(PointSampler, input.texcoord);
// ------------------------------------------------------------------------
// final composition
// ------------------------------------------------------------------------
return float4(finalColor.a,0,0,1);
[/CODE]

But all I get is red !

What could I be doing wrong ?

Here's my rendertarget construction :

[CODE]
// create DirectX11 device
CreateDevice11(form, out swapChain, out device11);
// create depth buffer
CreateDepthBuffer(form.ClientSize.Width, form.ClientSize.Height);
// create a view of our render target, which is the backbuffer of the swap chain we just created
RenderTargetView renderTarget;
using (Resource resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
renderTarget = new RenderTargetView(device11, resource);
// setting a viewport is required if you want to actually see anything
var context = device11.ImmediateContext;
//var viewport = new Viewport(0.0f, 0.0f, form.ClientSize.Width, form.ClientSize.Height);
context.OutputMerger.SetTargets(renderTarget);
[/CODE]

and here's my device/swapchain construction :

[CODE]
private static Result CreateDevice11(RenderForm form, out SwapChain swapChain, out Device device11)
{
var description = new SwapChainDescription()
{
BufferCount = 2,
Usage = Usage.RenderTargetOutput,
OutputHandle = form.Handle,
IsWindowed = true,
ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
SampleDescription = new SampleDescription(1, 0),
Flags = SwapChainFlags.AllowModeSwitch,
SwapEffect = SwapEffect.Discard
};
return SlimDX.Direct3D11.Device.CreateWithSwapChain(adapter1, DeviceCreationFlags.Debug, description, out device11, out swapChain);
}
[/CODE]
0

Share this post


Link to post
Share on other sites
[code]return float4(finalColor.a, 0, 0, 1);[/code]

this will return red. you should do it like this:

[code]return float4(Red, Green, Blue, Alpha);[/code]

if your just trying to return the color of the texel in the sprite sheet with the alpha value, you can just do this:

[code]return finalColor;[/code]

if you just want to completely not draw the transparent parts, you can clip, or stop pixels with a certain alpha value from even getting processed like this:

[code]float4 finalColor = gSpriteSheet.Sample(PointSampler, input.texcoord);
clip(finalColor.a - .25);
return finalColor;[/code]

so anything with an alpha value of .25 or less will not be rendered.
1

Share this post


Link to post
Share on other sites
return float4(finalColor.a, 0, 0, 1);
this code is just to demonstrate that all alpha values are coming through as 1.0, rather than the mix of 0 & 1 (which the texure contains). In other words, when rendering float4(finalColor.a,0,0,1); I would expect the areas of the texture with alpha=1.0 to be rendered red and the areas with alpha = 0 to be rendered black. But this is not happening, by the time the texture gets to the shader, the whole alpha plane is 1.0.

So when i use return finalColor; I don't get the alpha values that are present in the texture at design time.
0

Share this post


Link to post
Share on other sites
ooh, i get what you were trying to do, sorry for not seeing that, haha

have you tried using a different format? like jpeg? I've come across other people having problems with directx, bmp, and alpha channels before. maybe the alpha channel in the bmp is not being recognized, my only suggestion at the moment

also, i don't think you would want to use a format like bmp anyway since it's a larger file than better compressed formats like jpeg or png
0

Share this post


Link to post
Share on other sites
Well it looks to me like photoshop can't save png with alpha, there is a warning sign next to alpha channels in the save box. And when i look at the image in Pixelformer, the background is black. I'm so bored with all these alpha channel issues, I don't understand why these issues still exist.
0

Share this post


Link to post
Share on other sites
I just can't believe that Adobe think like this .... to save transparency in png format I had to remove the transparency channel and only save it as an rgb. That is so so counter-intuitive, that i would say it is completely disfunctional reasoning in software design. So very frustrating that some things are like this in software. And why haven't MS fixed the issue with bitmaps not loading alpha ? Do I not understand alpha and it's usage or do these giant companies who make this stuff not understand it ?

Anyway, I have transparency in my quads now, and thanks for introducing me to the clip function iedoc, that's a handly little thing aint it.
0

Share this post


Link to post
Share on other sites
yeah that clip function really is nice.

I'm glad to see you got it working. That really is strange your having problems with photoshop exporting the alpha channel. I always use jpg and alpha seems to be fine. Another format you might be interested in is the tiff format, which seems to be a common format for a lot of games. I'm not real experienced though, so i couldn't tell you which one is best ;)
0

Share this post


Link to post
Share on other sites
Bitmaps not having alpha is not an issue, it's part of the bitmap specification. If MS were to change that, imagine all the legacy programs that would need to be re-tested. It's not going to happen.
0

Share this post


Link to post
Share on other sites
Hi,

you should use DDS format (there is an export plugin from NVidia for Photoshop).
It allows you to control exactly the format of the loaded image. Exactly in the sense that dds format contains the data in the format which is used by the hardware and there is no need to do any (unless the format isn't supported of course) conversion at the load time.

Cheers!
1

Share this post


Link to post
Share on other sites
Thank you kauna, It took me no time to test alpha blending with a texture in dds format. I never knew about that exporter. So very helpful.
0

Share this post


Link to post
Share on other sites
Sounds like you've solved your problem already by switching to the dds format, but thought I'd mention I had exactly the same problem with png's output from Photoshop losing their Alpha Channel. It looks as though Photoshop converts the png to use pre-multiplied alpha when loading the file. The thing is, the png I was editing was originally exported from Illustrator, another Adobe product, and guess what... It writes the alpha channel in the png properly. Bizarre huh? Not sure why those two products are inconsistent.

I discovered a plugin for Photoshop called SuperPNG which fixes the problem. To load the png, you select "Open As" and then pick the super png format, and the alpha channel is properly imported as a separate channel.
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