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

Valve's Glowing Text Shader

5 posts in this topic

I wrote a decal generater with the Alpha Tested Magnification method defined here [url="http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf"]http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf[/url] and I tried to implement the outer glow shader but I had a few questions

1) What is the appropriate valus for something like "GLOW_UV_OFFSET", "OUTER_GLOW_MIN_DVALUE" and "OUTER_GLOW_MIN_DVALUE"? I have tried used (-0.004, -0.004), 0.3 and 0.5.

2) What is the value for "mskUsed"?

I tried to implement this with the code below but it just looked terrible and not even noticeable. (I do have the rendering working without trying this effect).

float4 PS( PS_INPUT input) : SV_Target
{
float4 baseColor = float4(0.0f, 0.0f, 1.0f, 1.0f);
baseColor.a = txDiffuse.Sample(samLinear, input.Tex.xy).a;

float2 glowOffset = float2(-0.004f, -0.004f);
float4 glowColor = float4(0.0f, 0.0f, 0.0f, 1.0f);

float4 glowTexel = txDiffuse.Sample(samLinear, input.Tex.xy + glowOffset);
float4 glowc = glowColor * smoothstep(0.3f, 0.5f, glowTexel.a);
baseColor = lerp(glowc, baseColor, baseColor.a);

return baseColor;
}
0

Share this post


Link to post
Share on other sites
Has anyone been able to implement any of the text shaders that Valve described in that article? (Not just the glow shader)
0

Share this post


Link to post
Share on other sites
[font="Courier New"]GLOW_UV_OFFSET[/font] determines the number of pixels that the glow effect will be offset from the text by (for using glow as a drop shadow). This is in normalized texture coordinates --- so if your texture is 512x512, then 1 pixel = [font="Courier New"]float2(1/512.0, 1/512.0)[/font].

[font="Courier New"]OUTER_GLOW_MIN_DVALUE[/font] / [font="Courier New"]OUTER_GLOW_MIN_DVALUE[/font] determine how far outside the shape the glow begins appearing, and when it reaches full opacity. The numbers to use here depend on how you generated your distance field....
0.5 means "right on the edge". 1.0 means "x units inside the shape". 0.0 means "x units outside the shape". Depending on how you generated the distance field, "x" is going to be a different number of pixels.

I would guess that [font="Courier New"]baseColor.a[/font] is the right value to use in place of [font="Courier New"]mskUsed[/font], but before you do that part, you're missing either[code]baseColor.a *= smoothstep( SOFT_EDGE_MIN, SOFT_EDGE_MAX, baseColor.a );[/code]or[code]baseColor.a = step(0.5, baseColor.a);[/code]
1

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1295242855' post='4759950']
[font="Courier New"]GLOW_UV_OFFSET[/font] determines the number of pixels that the glow effect will be offset from the text by (for using glow as a drop shadow). This is in normalized texture coordinates --- so if your texture is 512x512, then 1 pixel = [font="Courier New"]float2(1/512.0, 1/512.0)[/font].

[font="Courier New"]OUTER_GLOW_MIN_DVALUE[/font] / [font="Courier New"]OUTER_GLOW_MIN_DVALUE[/font] determine how far outside the shape the glow begins appearing, and when it reaches full opacity. The numbers to use here depend on how you generated your distance field....
0.5 means "right on the edge". 1.0 means "x units inside the shape". 0.0 means "x units outside the shape". Depending on how you generated the distance field, "x" is going to be a different number of pixels.

I would guess that [font="Courier New"]baseColor.a[/font] is the right value to use in place of [font="Courier New"]mskUsed[/font], but before you do that part, you're missing either[code]baseColor.a *= smoothstep( SOFT_EDGE_MIN, SOFT_EDGE_MAX, baseColor.a );[/code]or[code]baseColor.a = step(0.5, baseColor.a);[/code]
[/quote]

Thank you for the help, I have been experiementing with this for a little bit now and have a few questions.

Currently my text is getting a poor inner shadow look, rather then an outer shadow. If the code I posted above is correct (which is nearly identical to the Valve example), it seems like it is do to the MIN/MAX glow value. I calculate my text fields using the type of algorithm that OrangeTangy posted in his blog, do you have an algorithm you can suggest. This uses 0.5 as the mask type value, I am not sure at all though what the MIN/MAX values should like though, I have tried numerous pairs but "nothing fit".

Where did you happen to find out some of this information, such as the normalized texture coordinates? I don't recall reading any of that.

Also, since it seems you may have implemented this before, what is your commendation for the smoothstep values when no effects are applied? I am currently doing "smoothstep(0.48, 0.52, alpha)"
0

Share this post


Link to post
Share on other sites
When you calculate your distance field, each pixel ends up with a distance value to the edge of the shape. You then perform some kind of operation that converts these distances into bytes, where 0=far outside, 255=far inside and 127/128=on the edge.
Depending on how this conversion is performed, the meaning or your MIN/MAX parameters will be different!

For example, let's say that after converting distances to bytes, a difference of 1 means a distance of "1 pixel".
That would mean that 126 is 1px from the edge, 125 is 2px from the edge, etc, etc, and 0 is 127px from the edge.

Remember, once we're in shader-land, our 0-255 bytes are automagically converted to floats, meaning now:
0.0=far outside, 1.0=far inside, 0.5=on the edge.

This also means that "one pixel" in distance is now a difference of 1/255, instead of a difference of 1.

So, if you want a soft edge that is 6 pixels wide, you would use:
[code]float onePixelDistance = 1.0/255.0;//value determined by distance field generation tool
float SOFT_EDGE_MIN = 0.5 - onePixelDistance * 3.0;
float SOFT_EDGE_MAX = 0.5 + onePixelDistance * 3.0;[/code]

Looking at your "smoothstep(0.48, 0.52, alpha)" example, that's a distance of "0.02" either side of the centre, or in our byte representation, it's "5.1" either side of the centre.
Now, "0.02" and "5.1" have no meaningful units at this point without knowing how your tool converts distances into the byte representation.
If we assume it's doing it the same as my example above (1 unit = 1 pixel distance in the original map), then you edge blur should be 10.2 pixels wide relative to the original texture.

[font="Courier New"][hr]
txDiffuse.Sample()[/font] takes normalised texture coordinates as inputs. Seeing you add GLOW_UV_OFFSET to the parameter passed into this function, then it follows that GLOW_UV_OFFSET should also be specified in normalised texture coordinates. This isn't specified in the Valve paper, it's just background shader programming knowledge.
0

Share this post


Link to post
Share on other sites
Thanks for the help, it looks like that about clears it up for me. By any chance do you happen to remember where you figured out your method for generating distance maps? Mine was just put together from random places that I read.
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