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

In-engine environment map probes questions

36 posts in this topic

You're correct about the fresnel color. Still didn't change anything for the better... I've gone over it again, to make sure the view vector is correct. Tested it with a phong (RdotV) output, which worked. The reflection when moving around the sphere's also looks like it would be correct. It is a distant env map though. It's actually the skybox itself, filtered using cubemap gen. But does that even make any difference ? edit: here's the screenshot when looking down at the ground:

http://d.pr/i/lnEX

Edited by lipsryme
0

Share this post


Link to post
Share on other sites
Now I'm pretty sure there's some error in the fresnel calculation...
When looking down at the ground the N.L of most pixels should be almost 1, so the Fresnel would be the specular color of the material. Since the material has a low specular color the sky reflection shouldn't that much visible.

Check the result of the fresnel equation when looking at the ground for some pixels in PIX (or NVIDIA NSight), it should be close to the fresnel color.

Also post the full pixel shader if you can... I'm running out of ideas wacko.png

EDIT: You changed the screenshot looking at the ground right? It looks correct now. Edited by TiagoCosta
0

Share this post


Link to post
Share on other sites

Yeah sorry, I switched the N and V before for testing when calculating the reflection vector.
Still the ground looks like this (it's just this small part in the middle that doesn't get the reflection):
http://d.pr/i/QXfU

 

Here are the parts that are important for the env reflection:

 

	// Calculate Position from linear view space depth
	float3 ViewRay = input.ViewRay.xyz;
	float depth = DepthTarget.Sample(PointSampler, UV).r;
	float linearDepth = ProjectionB / (depth - ProjectionA);
	float3 ViewDir = ViewRay * linearDepth; // View space position
	float3 V = normalize(ViewDir) * -1.0f;
	float3 V_WS = mul(V, (float3x3)InverseView);
	V_WS = normalize(V_WS);

// Retrieve Specular Power [2-2048]
	float SpecPow = exp2(10.0f * AlbedoTarget.SampleLevel(PointSampler, UV, 0).a + 1.0f);

	// Sample reflection from environment probe
	float3 R = reflect(N_WS, V_WS);

	// Pick MipLevel depending on glossiness
	float mipLevel = -1.66096404744368 * log(SpecPow) + 5.5; // log(SpecPow / 2048.0f) / log(0.25f);
	float3 reflectionColor = ToLinear(EnvironmentProbe.SampleLevel(LinearSampler, R, mipLevel).rgb).rgb;


	// Compute Fresnel Term (F) using Schlick's approximation
	float NdotV = dot(N_WS, V_WS);
	float3 FresnelReflectance = ToLinear(float3(0.3f, 0.3f, 0.3f));
	float3 F_schlick = FresnelReflectance + ((1.0f - FresnelReflectance) * pow(1.0f - NdotV, 5.0f));
	reflectionColor *= F_schlick;

		// Accumulate results of BRDF and Ambient lighting for regular objects
		lighting.rgb = MicrofacetBRDF(N, LightDir, V, DiffuseAlbedo, SpecPow,
								      ambientOcclusion, Attenuation, shadowFactor).rgb;

		lighting.rgb += reflectionColor;

 

 

0

Share this post


Link to post
Share on other sites

It's starting to look better, I'm wondering why there's no reflection in the ground far away in front of the camera because the fresnel should increase with the distance in that situation... Can you post the shader? If you don't mind... (or send me a link to it via PM if you don't feel like sharing it to everyone)

0

Share this post


Link to post
Share on other sites
It looks correct. So I'm not sure what the problem might be...

Let's try one more thing:
Remove the normal mapping, so the normal of the ground is (0.0f, 1.0f, 0.0f) on all pixels, and just output the reflection color. So there're no changes in normals, diffuse colors and lighting.

The ground should be black near the camera and the reflection of the environment map should increase with distance around the camera.

P.S: I noticed that you're multiplying the reflection color with the shadow factor, which isn't correct because a pixel might be in shadow from the light but it still receives light from the environment. You might want to multiply it with the ambient occlusion factor though Edited by TiagoCosta
1

Share this post


Link to post
Share on other sites
Multiplying the reflection color with the ambient light (and ambient occlusion) does make it look good, but I guess now its intensity would depend entirely on the ambient light intensity in the scene.
I'm wondering wouldn't it make sense to use the glossiness or specular power of the material as an intensity value for this reflection color ? Basically a material that is highly glossy (let's say = 1.0f) would have strong reflection intensity and a material that is very rough (= 0.2f) would then have very low reflection intensity. Does that make sense, or would it be "physically incorrect" somehow ?
Also would I add the reflection to everything ? Or exclude it on materials like skin ? (not sure I can't remember having seen environmental reflections on human skin before in real life).
And what you said earlier about the cryengine screenshot of those sphere's that is a metallic reflection ? How is it different ? Do I just output specular and ignore diffuse completely ? You're saying the color of the spheres in that screenshot comes from the specular color ?


Here's a screen of how it looks multiplied by the ambient and ambient occlusion:
http://d.pr/i/SuZh

The reflections are very faint now. Which makes perfect sense on the ground but maybe not on the highly glossy sphere on the right. Edited by lipsryme
0

Share this post


Link to post
Share on other sites

Basically a material that is highly glossy (let's say = 1.0f) would have strong reflection intensity and a material that is very rough (= 0.2f) would then have very low reflection intensity. Does that make sense, or would it be "physically incorrect" somehow ?

A rough material reflects just as much light as a smooth one. The only difference is, that on the rough material the reflections are more scattered into all directions and not as bundled into a single direction. That gives the illusion of a highly smooth material being more reflective, but that's not true, it's just more or less "binary" as to how it reflects light (completely into one direction, nothing into another direction).

The only parameters needed to describe reflection are parameters to describe the materials microfacets orientations and positions (usually a single parameter called "Roughness" or "Glossiness") and the index of refraction of the material. The IOR is completely responsible for as to how much light is reflected from a microfacet which can be calculated using fresnel's equations. The easier and more common way to store this IOR is to calculate how much light would be reflected at microfacet normal incidence (aka specular intensity) and use this later on with Schlick's approximation of fresnel's equations which approximates them without the need for actual IOR values.

Each microfacet is a perfect mirror so light coming from one direction will be reflected to exactly one other direction. So how each microfacet is oriented doesn't affect how much light is reflected, only where it's being reflected to.

So overall it doesn't matter how rough your material is, the only thing that is actually responsible for how much is reflected, is the index of refraction.

You could actually derive a diffuse model from this microfacet model as well:
Simply multiply lambert with the integral over all the microfacet orientations of the percentage of microfacets being oriented into this direction multiplied with the percentage of microfacets actually visible from the light source multiplied with the complement of how much light is reflected from these microfacets (because the non-reflected rest of the light is getting scattered into the material and thus might get scattered out again into random directions as diffuse lighting if it's not absorbed).

Also I'm not quite sure what those numbers are (0.2 being rough and 1.0 being glossy). In Phong and Blinn-Phong you have exponents ranging from 1 to infinity where higher numbers represent a smoother surface and in NDFs like Beckmann or GGX you have factors ranging from 0 to 1 where higher numbers represent a rougher surface. You are either using a pretty weird NDF / BRDF or you misunderstand something.

Also would I add the reflection to everything ? Or exclude it on materials like skin ?

Everything has an index of refraction and thus everything must be reflective unless it has the same index of refraction as air (or whatever material the camera is in). Skin for example is pretty much as reflective as water is (the index of refraction doesn't differ that much), but is pretty rough in comparison to water.

metallic reflection ? How is it different ? Do I just output specular and ignore diffuse completely ? You're saying the color of the spheres in that screenshot comes from the specular color ?


Metals have index of refractions in the complex plane. If you calculate how much light is reflected using fresnel's equations, you get pretty high percentages. These are usually around 95% instead of at about 4% for dielectric materials. Also most metals unlike dielectric materials have highly varying index of refractions in the visible light spectrum. So green light might get reflected less than red light for example. Copper and gold are good examples of materials with varying index of refractions in the visible light spectrum. Also metals are highly absorbtive. The already low amount of light that is not reflected and gets scattered into the material gets absorbed so fast, that pretty much no light gets scattered out again as diffuse lighting. Keep in mind, that there is no difference between subsurface scattering and diffuse lighting. Edited by CryZe
1

Share this post


Link to post
Share on other sites

Multiplying the reflection color with the ambient light (and ambient occlusion) does make it look good, but I guess now its intensity would depend entirely on the ambient light intensity in the scene.


I would simply multiply with the ambient occlusion factor (not the ambient light). The reflections might be to strong because the environment map luminance is much higher than the directional light intensity, and when you multiply the reflection color with the ambient light you scale it back and it starts to look better. Keep in mind that a physically based renderer usually requires some calibrating work to be done.

Also would I add the reflection to everything ? Or exclude it on materials like skin ? (not sure I can't remember having seen environmental reflections on human skin before in real life).


No need for that. Even though every material reflects light, there's no need to waste computation time calculating reflections for rough materials because the reflection won't be noticeable. For movies, there's time to add reflections on every material because you don't need to run at 30/60 fps, games, on the other hand, need to cut on details like that.
Skin is actually a good candidate for environment reflections, especially in bald people at grazing angles, but since its a rough material the reflections are so much "blurred" that it looks like a uniform color.

And what you said earlier about the cryengine screenshot of those sphere's that is a metallic reflection ? How is it different ? Do I just output specular and ignore diffuse completely ? You're saying the color of the spheres in that screenshot comes from the specular color ?


Yes, diffuse color can be ignored in metallic surfaces.
Example: Gold specular color (1.0f, 0.71f, 0.29f)
Even if HalfVector dot Light or View dot Normal = 1 the result of fresnel will be (1.0f, 0.71f, 0.29f).

Here's a screen of how it looks multiplied by the ambient and ambient occlusion:
http://d.pr/i/SuZh

The reflections are very faint now. Which makes perfect sense on the ground but maybe not on the highly glossy sphere on the right.


What specular color are you using in the sphere? You might need to increase it. Especially if the sphere is supposed to be metallic.


Also I'm not quite sure what those numbers are (0.2 being rough and 1.0 being glossy). In Phong and Blinn-Phong you have exponents ranging from 1 to infinity where higher numbers represent a smoother surface and in NDFs like Beckmann or GGX you have factors ranging from 0 to 1 where higher numbers represent a rougher surface. You are either using a pretty weird NDF / BRDF or you misunderstand something.


Its common to store a glossiness value in the range [0,1] in textures and then convert it to specular power using a function like this:
float specPower    = pow(2.0f, 13*glossiness);
Edited by TiagoCosta
1

Share this post


Link to post
Share on other sites

So would it be correct to multiply this by the ambient occlusion ? (as I recall ambient occlusion should only ever be added to something?) else you'd get the dark aura look of e.g. Far cry 3 rolleyes.gif

 

And how about shadows ? Do I multiply or add them to the environment map color ? Or not at all ?

 

But even with a fresnel reflectance color of 0.028f (for skin) I'm seeing reflections even when not at glancing angle on the skin. Do you think the color of the env map is too bright ? I basically just took my skybox and prefiltered it with amd's cubemap gen. And I'm also already reading the env map as linear.

0

Share this post


Link to post
Share on other sites

No need for that. Even though every material reflects light, there's no need to waste computation time calculating reflections for rough materials because the reflection won't be noticeable.

So rough gold would be completely black? I don't know, roughness doesn't change anything about the reflectivity of the material, just the "blurriness" of the reflection. So on metals or at grazing angles you'll lose an incredible amount of lighting if you simply turn it off for rough materials. If anything I'd approximate rough reflection using an approximation via a diffuse term.

Its common to store a glossiness value in the range [0,1] in textures and then convert it to specular power using a function like this:
float specPower = pow(2.0f, 13*glossiness);

Oh, my bad. I thought he was talking about the specular power used in the BRDF. :D

So would it be correct to multiply this by the ambient occlusion ?

Ambient occlusion is low-quality shadowing information. Use it on anything non-directional, where you don't have better visibility information. So don't apply it to reflections or any point / spot / directional lights. Just to irradiance or other kinds of ambient terms, like diffuse sky illumination. Basically every source of light which comes from more than just a single direction (this includes area lights) could be multiplied with ambient occlusion. The more it spans the hemisphere over the surface, the more it's suited for ambient occlusion. Environment maps might span the whole hemisphere over the surface, but when used for reflections, only a single direction is used, so you shouldn't apply ambient occlusion to it. If the environment map is used for diffuse image based lighting, samples over the whole hemisphere are used and thus ambient occlusion should be applied. For rough reflections you might want to blend in ambient occlusion to some degree though.

And how about shadows ? Do I multiply or add them to the environment map color ? Or not at all ?

I'm not quite sure which shadows you're talking about. But basically you are "tracing" a reflection ray and the environment map helps you find the intersection. So there's no need for any kind of shadow map.

But even with a fresnel reflectance color of 0.028f (for skin) I'm seeing reflections even when not at glancing angle on the skin. Do you think the color of the env map is too bright ?

Either it's actually too strong or the reflection is not rough enough. Hard to tell without seeing the result. Edited by CryZe
1

Share this post


Link to post
Share on other sites

Do you think the color of the env map is too bright ? I basically just took my skybox and prefiltered it with amd's cubemap gen. And I'm also already reading the env map as linear.

 
Maybe... You have to make sure that intensity of the env map matches the light sources in the scene...
 

So rough gold would be completely black? I don't know, roughness doesn't change anything about the reflectivity of the material, just the "blurriness" of the reflection. So on metals or at grazing angles you'll lose an incredible amount of lighting if you simply turn it off for rough materials. If anything I'd approximate rough reflection using an approximation via a diffuse term.

 

You're right, for metals the reflections shouldn't be disabled. I was talking about materials with both low specular colors and glossiness where the reflections aren't much noticeable, like the trunk of a tree, etc.

 

Ambient occlusion is low-quality shadowing information. Use it on anything non-directional, where you don't have better visibility information. So don't apply it to reflections or any point / spot / directional lights. Just to irradiance or other kinds of ambient terms, like diffuse sky illumination. Basically every source of light which comes from more than just a single direction (this includes area lights) could be multiplied with ambient occlusion. The more it spans the hemisphere over the surface, the more it's suited for ambient occlusion. Environment maps might span the whole hemisphere over the surface, but when used for reflections, only a single direction is used, so you shouldn't apply ambient occlusion to it. If the environment map is used for diffuse image based lighting, samples over the whole hemisphere are used and thus ambient occlusion should be applied. For rough reflections you might want to blend in ambient occlusion to some degree though.

 

Since the OP is using the same environment map for all objects multiplying the reflections with the ambient occlusion factor might help reduce artifacts like reflections of the environment on the bottom of the spheres near the ground where they should be occluded. This is just a suggestion though, since occlusion in environment mapping is a rather complex problem.

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