V!nc3r

Reflection probe bounding box

Recommended Posts

Hi all!

Is it possible to define a bounding box size on a reflection probe ?

Here a screen record in Unity3D, to show what I'm talking about:

https://imgur.com/NoMzMil

(another quick record with a simplier scene)

By tweaking the probe cage as the same size of the room walls, I get kind of realtime effect just by using a probe (box projection need to be checked):

wOSpUwI.png

 

I don't know technical logic behind this functionnality, maybe this bounding box option looks like an abstract cube mesh where is applied the cubemap as a texture, and materials using this probe reflect this cube inverted ? No idea :)

 

 

 

 

Share this post


Link to post
Share on other sites

Nope, my explanations was unclear I think. I will try to make a cornell box scene example in the playground to show the desired effect.

And maybe in my example on Unity I havn't spotted the correct parameters. Rather than the bounding box, I think the two important parameters on Unity are the probe origin and the box projection checked (at 0:29 - it's in fact probably only this box projection which I interested in).

Share this post


Link to post
Share on other sites

Ok (so non-infinite reflection probe is the correct name, I'm gonna remember that ;) ). Maybe this can be add to the BJS whishlist ?

I suppose this functionnality bring the fact to rewrite another reflection probe system, like generate dynamic cubemap with a probe > map this cubemap onto an invisible cube (where x,y,z scale can be set) > use this cube to project reflection depending on the camera angle. Looks like complicated.

So, I will try to cheat with realtime reflection using a mirrorPlane for now.

Share this post


Link to post
Share on other sites

I got it implemented once, but only in the legacy PBR code.
So this is parallax correction, to a box defined by vCubemapSize and  vCubemapCenter. (faster than any size box but it worked)

The code was like this (in reflectionFunction.fx):

#ifdef PARALLAXCORRECTION
vec3 parallaxCorrectNormal( vec3 pos, vec3 v, vec3 cubeSize, vec3 cubePos ) {

    vec3 nDir = normalize(v);
    vec3 rbmax = (   .5 * ( cubeSize - cubePos ) - pos ) / nDir;
    vec3 rbmin = ( - .5 * ( cubeSize - cubePos ) - pos ) / nDir;
    
    vec3 rbminmax;
    rbminmax.x = ( nDir.x > 0. )?rbmax.x:rbmin.x;
    rbminmax.y = ( nDir.y > 0. )?rbmax.y:rbmin.y;
    rbminmax.z = ( nDir.z > 0. )?rbmax.z:rbmin.z;

    float correction = min(min(rbminmax.x, rbminmax.y), rbminmax.z);
    vec3 boxIntersection = pos + nDir * correction;
    
    return boxIntersection - cubePos;
}
#endif


and later:

#ifdef REFLECTIONMAP_CUBIC
	vec3 viewDir = worldPos.xyz - vEyePosition.xyz;
	vec3 coords = reflect(viewDir, worldNormal);
#ifdef PARALLAXCORRECTION
	coords = parallaxCorrectNormal(worldPos.xyz, coords, vCubemapSize, vCubemapCenter );
#endif



 

Share this post


Link to post
Share on other sites
12 hours ago, V!nc3r said:

Ok (so non-infinite reflection probe is the correct name, I'm gonna remember that ;) ). Maybe this can be add to the BJS whishlist ?

I suppose this functionnality bring the fact to rewrite another reflection probe system, like generate dynamic cubemap with a probe > map this cubemap onto an invisible cube (where x,y,z scale can be set) > use this cube to project reflection depending on the camera angle. Looks like complicated.

So, I will try to cheat with realtime reflection using a mirrorPlane for now.

I might be able to pull this off.  If nobody does it by next week remind me.

Share this post


Link to post
Share on other sites

Here a test with the cornell box scene : https://www.babylonjs-playground.com/#59ZXVF#25

Why, if I try to attenutate the reflection, by setting metallic or reflectionTexture.level to 0.1, my material become darker?

I see that I must set both scene.ambientColor and material.ambientColor to white to avoid this : https://www.babylonjs-playground.com/#59ZXVF#17 (lines 5 and 104). Is this "physically" correct?

[edit] or maybe I have to replace the environmentBRDFTexture on the ground material, with the cubeTexture of my probe? But how can I do that, since the BRDF texture looks like a weird texture, how can I regenerate dynamically one, using a probe?

Edited by V!nc3r
quick fix of PG

Share this post


Link to post
Share on other sites

The BRDFTexture should not be change as it is a tool for use to compute some optics value. You can however try to set it to null to use a different algorithm 

 

Reducing the metalness will indeed reduce the amount of received light

 

To attenuate the reflection, can you try to play with reflectivityColor perhaps? https://www.babylonjs-playground.com/#24BYDQ

pinging @Sebavan for other ideas

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.