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

gloss mapping?

7 posts in this topic

Hey I just implemented gloss mapping or at least I think I did. Am I right in thinking that gloss mapping is when you change the specular exponent based on a texture? Also did I implement it right? here is my code (simplified of course):

[CODE]
specular = pow(max(dot(halfvec, finalnormal), 0.0), (texture2D(gloss_texture, transformedTexcoord).r*99.0) + 1.0);
[/CODE]

Mostly I was wondering about the range, I want to be pretty conformant to what other engines use as to maximize the portability of my content. right now I noticed that when multiplying it by 99 I start running into the limitations of 8-bit grayscale. Does anyone have an example of how they implemented this effect?
0

Share this post


Link to post
Share on other sites
Sometimes "gloss" terminology is a bit vague - some engines use it to mean the specular power, while others use it to mean the specular mask. In any case, it's good to fetch both the power and mask values from a texture to give your artists decent control over the materials.
In my engine, I call the specular-power texture the "roughness" texture.

You seem to be using the traditional Blinn-Phong specular function, and the code looks ok. In terms of style, I'd suggest a few more line breaks:
[code]float NdotH = saturate(dot(halfvec, finalnormal)); //prefer saturate over max where able
float specPower = texture2D(gloss_texture, transformedTexcoord).r*99.0 + 1.0;
specular = pow(NdotH, specPower);[/code]

As for the "[font=courier new,courier,monospace]x*99+1[/font]" part, there is no right answer for this encoding/decoding function. Any positive value is valid for the specular power -- some materials might need "5" and others might need "50000"... This makes choosing a function that encodes this range into 8-bits particularly difficult.
If the materials in your game only need the values of 1-100, then your encoding is fine.

If you want to move more precision to the lower end, you can do something like:
[code]float specPower = texture2D....
specPower = (specPower*specPower) * range + 1;[/code]Or to move precision to higher values, something like:[code]float specPower = 1.0 - texture2D....
specPower = (1.0-(specPower*specPower)) * range + 1;[/code]
Some engines use the log function for a logarithmic distribution, but basically you've just got to choose a mapping that works for you.

Other engines might not even be using Blinn-Phong, so even if you use the same mapping, you'll get different appearances of "gloss" anyway. Edited by Hodgman
2

Share this post


Link to post
Share on other sites
Sorry to intrude but I'm curious as to why you'd prefer saturate over max ?
I was having some problems using saturate for a dot product before, were it was clamping values to 1 which should not have been.
Isn't a max much safer and precise in that respect ? Edited by lipsryme
0

Share this post


Link to post
Share on other sites
It is common in game engines now to store the spec power in log space, even with 8 bit precicion.

i.e see how UE4 does it here (slide 30)

http://advances.realtimerendering.com/s2012/Epic/The%20Technology%20Behind%20the%20Elemental%20Demo%2016x9.pptx

Frostbite2 also does it this way too (albeit with maybe a slightly different range)


Also as mentioned above a saturate will be better. Its usually free whereas max is not.
2

Share this post


Link to post
Share on other sites
[quote name='AliasBinman' timestamp='1354558493' post='5006703']
Also as mentioned above a saturate will be better. Its usually free whereas max is not.
[/quote]

I'm using glsl, as far as I know saturate doesn't exist there, glsl has clamp() but I'm not sure if that is still "free"
0

Share this post


Link to post
Share on other sites
[quote name='ic0de' timestamp='1354560058' post='5006713']
[quote name='AliasBinman' timestamp='1354558493' post='5006703']
Also as mentioned above a saturate will be better. Its usually free whereas max is not.
[/quote]

I'm using glsl, as far as I know saturate doesn't exist there, glsl has clamp() but I'm not sure if that is still "free"
[/quote]

In that case do clamp(x,0,1) and the compiler should replace with a saturate.
0

Share this post


Link to post
Share on other sites
[quote name='lipsryme' timestamp='1354548568' post='5006633']
Sorry to intrude but I'm curious as to why you'd prefer saturate over max ?
I was having some problems using saturate for a dot product before, were it was clamping values to 1 which should not have been.
Isn't a max much safer and precise in that respect ?
[/quote]Yes if the input is possibly > 1, then saturate isn't a valid replacement. A dot product of two normal vectors can't be > 1 though, so it's possible in this case.
Saturate/clamp(x,0,1) is preferable because it's often implemented as an instruction modifier, rather than its own instruction.
E.g. Instead of "mul ...; max ...;", the GPU ASM may just be "mul_clamped ...;"
2

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