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

Metallic in UE 4

7 posts in this topic

I'm curious how the metallic parameter as in the Disney and UE 4 material model could be used.

Following these course notes I implemented the UE 4 style GGX specular model and use metallic like this:

vec3 specular_color = lerp(vec3(1.f, 1.f, 1.f), diffuse_color, metallic);
float f0 = lerp(0.04f, 1.f, metallic);

vec3 specular = specular_color * specular_f(v_dot_h, f0) * specular_d(n_dot_h, a2) * specular_g(n_dot_l, n_dot_v, a2);

vec3 diffuse = (1.f - metallic) * diffuse_color;

return n_dot_l * (diffuse + specular);

From the notes it didn't become quite clear to me what I should do with metallic. It feels strange that non-metallic materials have a specular color of 1, but due to the small f0 it doesn't seem to be a big problem.

 

Any ideas how this could be improved upon?

0

Share this post


Link to post
Share on other sites

Non-metallic materials are achromatic most of a time and thus don't cause the reflections to be colored in any way. In their implementation the more the material is metallic, the more its reflections are colored by the diffuse color. Also the more metallic the material is, the stronger it reflects light in a specular way.

Edited by CryZe
2

Share this post


Link to post
Share on other sites
Spec colour and f0 are the same thing. IMO they shouldn't be two different parameters. The Fresnel function will make an RGB f0 term change to white at glancing angles, but if you use an RGB spec colour and a 1D f0 term, you don't get this behaviour.

I implemented it like this:
float3 albedo = ...
float specMask = ...
float metallic = ...
float3 f0 = lerp( specMask.xxx, specMask * albedo, metallic.xxx );
float3 diffuse = albedo * (1-metallic);
Later on I removed the metallic parameter because the artists didn't like having it as basically a second spec-mask parameter, and I replaced it with this:
float metallic = saturate(specMask*2-1);
float nonMetalSpec = saturate(specMask*2)*0.2;
float3 f0 = lerp( nonMetalSpec.xxx, albedo, metallic.xxx );
float3 diffuse = albedo * (1-metallic);
^Basically any spec-mask value below 50% (<186 in sRGB) is a non-metal, with 50%/186 being slightly shinier than diamonds. Above 50% is metallic, with 100% (255 in sRGB) being pure metal. Pure metals use the albedo colour as the spec mask instead, and set the diffuse colour to black. Non-pure metals (187 - 254) use a darkened diffuse term, and a not-fully-coloured specular term. Edited by Hodgman
1

Share this post


Link to post
Share on other sites

Spec colour and f0 are the same thing. IMO they shouldn't be two different parameters. The Fresnel function will make an RGB f0 term change to white at glancing angles, but if you use an RGB spec colour and a 1D f0 term, you don't get this behaviour.

I implemented it like this:

float3 albedo = ...
float specMask = ...
float metallic = ...
float3 f0 = lerp( specMask.xxx, specMask * albedo, metallic.xxx );
float3 diffuse = albedo * (1-metallic);
Later on I removed the metallic parameter because the artists didn't like having it as basically a second spec-mask parameter, and I replaced it with this:
float metallic = saturate(specMask*2-1);
float nonMetalSpec = saturate(specMask*2)*0.2;
float3 f0 = lerp( nonMetalSpec.xxx, albedo, metallic.xxx );
float3 diffuse = albedo * (1-metallic);
^Basically any spec-mask value below 50% (<186 in sRGB) is a non-metal, with 50%/186 being slightly shinier than diamonds. Above 50% is metallic, with 100% (255 in sRGB) being pure metal. Pure metals use the albedo colour as the spec mask instead, and set the diffuse colour to black. Non-pure metals (187 - 254) use a darkened diffuse term, and a not-fully-coloured specular term.

 

I used to have a float3 f0 and now I want to fit it back in, following your argumentation.

I notice that you have another parameter called spec mask. Isn't it more confusing to differentiate between roughness and spec mask?

0

Share this post


Link to post
Share on other sites

Spec-mask / f0 are based on the index-of-refraction. They determine the percentage of light that will reflect off the surface boundary. This is based on the type of the material, and should be a pretty flat/boring texture without much detail (unless there are many different types of material in the texture -- bricks, mortar, plastic, dirt, metal all would have different spec-mask values).
 
Roughness / spec-power is like a microscopic normal map. If you zoomed in with a microscope, would you have a flat normal map or a bumpy normal map.
Low roughness / high power / smooth micro-normal == small, crisp specular highlights.
High roughness / low power / bumpy micro-normal == large, dull specular highlights.
 
You can have a plastic material with a high spec-mask / f0 value, which means it's quite reflective -- you can then have a polished version (low roughness) and a dull version that's been attacked with rough sandpaper (high roughness). Those are two physically different parameters.
 
I've seen some engines lately have completely discarded the spec-mask value, because for most common (non-metal) materials, its value is around 4%.
The code you posted does this -- non-metals are 4% reflective and metals can be anything, including 100% (if you use a white diffuse colour).
In that case, your parameters would be colour, roughness/spec-power and metallic, which is also nice and simple.
If you used a vec3 f0, your code could look like:

vec3 f0 = lerp(vec3(0.04f), diffuse_color, metallic);

But yes, the more parameters you have, the more confusing it is wink.png

I have lots of reference charts and documentation to remind the artists what the parameters do, and how they should be used (e.g. if something is made up of one clean material, it should probably have one single spec-mask value, not lots of noise/detail in the spec-mask texture).

Edited by Hodgman
0

Share this post


Link to post
Share on other sites

Thanks for the explanation! 

 

After my previous post I remembered the UE 4 course notes to also mention a specular parameter which was later replaced by cavity. I'm having a hard time understand what cavity is used for as it seems similar to roughness. 

 

Picking up your example, lets say we have a highly reflective/metallic material that's been polished. In my case that might be metallic 1 and roughness 0. Now I want to have some small details with less highlights. I could say the roughness is higher here, or the cavity is higher. What is the difference?

0

Share this post


Link to post
Share on other sites

After my previous post I remembered the UE 4 course notes to also mention a specular parameter which was later replaced by cavity. I'm having a hard time understand what cavity is used for as it seems similar to roughness.

my guess is that it's a final multiplier, like the spec color in your original code -- white = no change, black = all spec lighting is removed.

In a physically based shader, even if you set f0/spec-mask to 0%, if you view the material at a glancing angle, 1-100% of the light will still be reflected due to Fresnel.
When you have little cavities, lake gaps between plates of armor, this looks weird. In reality, the shadow system should take care of this, but on a low-poly model, that cavity may not even exist (so it can't be shadowed). So, it's like doing a very fina AO bake on your model, or letting you artist hand paint areas where they want to remove the specular reflections.

 

Picking up your example, lets say we have a highly reflective/metallic material that's been polished. In my case that might be metallic 1 and roughness 0. Now I want to have some small details with less highlights. I could say the roughness is higher here, or the cavity is higher. What is the difference?

If the roughness is 0, you'll only see a reflection if H•N is exactly 1 (or in other words if R•L is exactly 1). Increasing the roughness relaxes this, so H•N can be smaller and smaller (less aligned) but a highlight is still produced. Yes, as roughness increases, the intensity of the highlight also decreases, because it's being spread over a large area (assuming were conserving energy).
Tweaking the cavity on the other hand just reduces the intensity directly, without affecting the size/shape of the highlight.
0

Share this post


Link to post
Share on other sites


In a physically based shader, even if you set f0/spec-mask to 0%, if you view the material at a glancing angle, 1-100% of the light will still be reflected due to Fresnel.
When you have little cavities, lake gaps between plates of armor, this looks weird. In reality, the shadow system should take care of this, but on a low-poly model, that cavity may not even exist (so it can't be shadowed). So, it's like doing a very fina AO bake on your model, or letting you artist hand paint areas where they want to remove the specular reflections.

OK, I never thought about the fresnel still being present on very rough surfaces. I think I can see a use case for the cavity parameter now. Thanks for the explanation!

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