• 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
Laurie Brown

Alpha Blending with SharpDX/DirectX11/WP8 using feature level 9_3

4 posts in this topic

I'm using SharpDX on the Windows Phone 8 and therefore although it uses DirectX11 it is feature level 9_3. This means certain things won't work on the device but will work on the emulator. I have a shader working on the emulator that uses alpha blending but I can't get it working on the phone at all. Basically I am drawing to a render target without clearing it and then drawing that to another one and multiplying the alpha by 0.95 to slowly fade it out over time. On the emulator this creates a nice fading trail behind a moving object. On the phone however the trail is just always the same colour and doesn't fade.

I am assuming this has something to do with feature level 9_3 but I can't figure out what it is I am doing that is wrong.

Here's the pixel shader:


[source lang="cpp"]Texture2D<float4> shaderTexture : register(t0);

sampler TextureSampler =
sampler_state
{
Texture = <shaderTexture>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Mirror;
AddressV = Mirror;
};

struct PSInput
{
float4 ScreenPosition : SV_POSITION;
float2 UV : TEXCOORD;
};

float4 main( PSInput input ) : SV_TARGET
{
float4 textureColor = shaderTexture.Sample(TextureSampler, input.UV);

textureColor.a *= 0.95f;
return textureColor;
}[/source]

Thanks for any suggestions. Edited by Lozzaaa
0

Share this post


Link to post
Share on other sites
Not strictly related, but I'm surprised by your shader, as the declared sampler TextureSampler won't be used in WP8. This was part of old Effect framework but this is not working under WP8. Compilation is probably running fine on your shader, but the TextureSampler must be setup programmaticaly from the code and not from the shader (and if you didn't set it, it is set to null by default, not sure about the default behavior of a texture sampler when it is not bound).
0

Share this post


Link to post
Share on other sites
Hmm maybe that's the problem then. I am really having trouble switching to DX11 and WP8. It seems like finding the right info out there is incredibly hard. All the tutorials are for DX9. Thanks once again for the help Xoofx, you're really saving me here.

I'll edit with an update after I've rewritten it to pass the samplerstate in from code.

Edit:
Creating a SamplerState causes a SharpDXException for some reason. The device is already set and creating the BlendState works fine:

[source lang="csharp"]var samplerStateDesc = new SamplerStateDescription();
samplerStateDesc.Filter = Filter.MinMagMipLinear;
samplerStateDesc.AddressU = TextureAddressMode.Mirror;
samplerStateDesc.AddressV = TextureAddressMode.Mirror;
samplerStateDesc.ComparisonFunction = Comparison.Never;
samplerStateDesc.MinimumLod = 0;
samplerStateDesc.MaximumLod = int.MaxValue;
_samplerState = new SamplerState(_device, ref samplerStateDesc);[/source] Edited by Lozzaaa
0

Share this post


Link to post
Share on other sites
SamplerStateDescription needs to have the exact same [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476207%28v=vs.85%29.aspx"]default values as stated in the msdn[/url] documentation, otherwise It will failed to create (this is relevant for all states).
As there are no custom default values for struct in C# (yeah, that sucks), you need to use SamplerStateDescription.Default() like this:
[CODE]
var samplerStateDesc = SamplerStateDescription.Default();
samplerStateDesc.AddressU = TextureAddressMode.Mirror;
samplerStateDesc.AddressV = TextureAddressMode.Mirror;
_samplerState = new SamplerState(_device, ref samplerStateDesc);
[/CODE]

Btw, you should try to use SharpDX Toolkit as it should simplify a *lot* managing D3D11.
0

Share this post


Link to post
Share on other sites
Ah thanks, yes that is annoying about not having default values for structs.

This didn't change the alpha blending on the device unfortunately, it is still either off or on. If you multiply in the shader by anything below 0.5f it is off and anything above it is on, it isn't blending at all. I also changed the blendStateDesc to use BlendStateDescription.Default() but that didn't change anything.

Yes I realise I should have started fresh with the Toolkit but I had already started the code in XNA and then C++ so this project has been moved about a lot. All just for 2D rendering, it's pretty frustrating. Next time I will definitely use Toolkit, it looks a lot more like XNA, which is nice.
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