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

Blending RGBA8

5 posts in this topic

Hello there. I'm currently working on my light prepass render pipeline, that is, writing normal and depth buffer (1), then creating light accumulation buffer (2) and finally render geometry again (3) using the information from the light accumulation buffer.

Now I'm working on adding decals to the system. Since decals are placed on top of solid geometry I disable depth writing and then render the decals using alpha blending. Here is where the problem starts:

During (3) I can smoothly alpha blend my decals on top of the solid geometry using ogl's blend function (ONE_MINUS_SRC_ALPHA, SRC_ALPHA). Decals blend in very well, BUT it uses the normals of the underlying surface. While this may be desired in some cases like graffiti on walls, it should sometimes use its own normals for lighting calculation. A simple example would be foot step marks on the ground.

What I'd like to do is to use alpha blending during (1), i.e. alpha blend solid geometry normals with my decal normals. The normal buffer layout is
ARGB8 with normal xyz in RGB and object's specular roughness in A. That means I need to blend all 4 channels. Since the alpha blend function uses the alpha channel for blending I can't blend normals and roughness at the same time. Actually I need some additional fragment value on which I can base the alpha blending.

Here's the code
[CODE]
#extension GL_ARB_draw_buffers : enable
varying vec3 normal;
varying vec4 position;
uniform sampler2D texAlpha;
void main()\n \
{\n \
// normal\n \
gl_FragData[0].rgb = normal * 0.5 + 0.5;
//roughness
gl_FragData[0].a = gl_FrontMaterial.shininess/128.;
// the blend factor that I actually need for blending
float blendFactor = texture2D(texAlpha, gl_TexCoord[0].st);
gl_FragDepth = position.z/position.w;
}
[/CODE]

So basicall I'd like to use the blending function with the blend factor I defined in the code. Like ONE_MINUS_BLENDFACTOR_ALPHA. I know this doesn't exist but you get the idea. Is there any way to make this possible or workaround the problem?

Thanks for your help
0

Share this post


Link to post
Share on other sites
The simplest solution is to use alpha-test ([i]or [font=courier new,courier,monospace]discard[/font][/i]) decals instead of alpha-blend decals, but that's changing the problem [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]

There's a solution in this presentation, which I think requires your decals to have a constant spec-power over their surface, which it looks like you're already doing.
[url="http://www.slideshare.net/blindrenderer/screen-space-decals-in-warhammer-40000-space-marine-14699854"]http://www.slideshar...marine-14699854[/url] Edited by Hodgman
1

Share this post


Link to post
Share on other sites
Hm, they use alpha testing for the normals only. This might actually work in most cases.
Constant specular is only in the code provided. There're other shaders that support specular power mapping. I wonder how they did it here (that's what I'm looking for):
[url="http://blog.wolfire.com/2009/06/decals-editor-part-three/"]http://blog.wolfire.com/2009/06/decals-editor-part-three/[/url]
0

Share this post


Link to post
Share on other sites
[quote name='mk1x86' timestamp='1351679052' post='4995776']
Hm, they use alpha testing for the normals only.
[/quote]They say that they were originally using alpha testing, but then switched to blending with the blend mode of:
[code]result.rgb = src.rgb * src.a + dst.rgb * (1-src.a)
result.a = src.a * factor + dst.a * (1-src.a)[/code]
where [font=courier new,courier,monospace]factor[/font] is set to the material's spec power. Obviously this doesn't work if you want the spec-power to vary across the decal though.
N.B. this relies on [url="http://www.opengl.org/registry/specs/EXT/blend_func_separate.txt"]EXT_blend_func_separate[/url].
[quote name='mk1x86' timestamp='1351679052' post='4995776']I wonder how they did it here (that's what I'm looking for): [url="http://blog.wolfire.com/2009/06/decals-editor-part-three/"]http://blog.wolfire....tor-part-three/[/url][/quote]This one doesn't mention deferred lighting, so it doesn't deal with your spec-power blending issue. In his level editor, he's pre-generating a world-space normal map per decal instance ([i]which is a mixture of the underlying geometric normals, and the decals tangent-space normals[/i]), and saving those texture alongside the level. Edited by Hodgman
1

Share this post


Link to post
Share on other sites
Sorry, I typed it up wrong. Edited my post.

The code would be something like:
[code]BlendColor( 0, 0, 0, specPow );//N.B. 0-1 range
BlendFuncSeparate( SRC_ALPHA, ONE_MINUS_SRC_ALPHA, CONSTANT_ALPHA, ONE_MINUS_SRC_ALPHA );
BlendEquationSeparate( FUNC_ADD, FUNC_ADD );[/code] Edited by Hodgman
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