Skip to content

Conversation

@takahirox
Copy link
Collaborator

@takahirox takahirox commented Mar 5, 2018

This PR is still WIP but you can test if this change fixes #13107
I calculate max mip level by log2( max( image.width, image.height ) ) for gl.generateMipmap.

I'll add comments later about what I'm worried about in this impl.


#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )

// TODO, replace 8 with the real maxMIPLevel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, this file appears to contain two copies of this TODO comment, but only one got removed. Was that intentional?

Copy link
Collaborator Author

@takahirox takahirox Mar 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I've just missed another one. I'll update.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks!


_gl.generateMipmap( target );

var image = Array.isArray( texture.image ) ? texture.image[ 0 ] : texture.image;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I expect images for cubic map have the same size?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not guaranteed, but lets assume that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I wanna add comment about our assumption here later.

@takahirox
Copy link
Collaborator Author

takahirox commented Mar 6, 2018

Changes and notes.

  • Using uniforms for maxMipLevel in glsl rather than using #define because texture can be updated.
  • Calculating max mip level by log2( max( image.width, image.height ) ) for gl.generateMipmap.
  • Holding maxMipLevel in textureProperties.

I add some questions inline.


var image = Array.isArray( texture.image ) ? texture.image[ 0 ] : texture.image;
var textureProperties = properties.get( texture );
textureProperties.__maxMipLevel = Math.max( Math.log2( Math.max( image.width, image.height ) ), textureProperties.__maxMipLevel );
Copy link
Collaborator Author

@takahirox takahirox Mar 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will gl.generateMipmap() clear the existing mipmap configuration?
For example, imagine you have 64x64 texture image and set mip level up to 10 with gl.texImage2D and then call gl.generateMipmap. gl.generateMipmap sets mip levels 1-6. So 7-10 levels will be removed?

I suppose it doesn't, so using max to choose the bigger one here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kenrussell do you know the answer for this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see section 3.8.10.5 "Manual Mipmap Generation" of the OpenGL ES 3.0.5 spec.

It says that levels levelbase+1 through q are derived from the contents of levelbase. Other mip levels are untouched.

I'm not sure what the intent of this code is, but probably you need to zero out all levels of the texture that were previously set, and set the max mip level to the one that will be set by GenerateMipmap.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kenrussell thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I had just misunderstood a bit.
In the example I mentioned, 7-10 levels makes no sense (seems like we can set 1x1 image tho)
I can remove max.

@mrdoob
Copy link
Owner

mrdoob commented Mar 7, 2018

Merging for now.

@mrdoob mrdoob merged commit 51fe8f7 into mrdoob:dev Mar 7, 2018
@mrdoob
Copy link
Owner

mrdoob commented Mar 7, 2018

It'd be nice to compare how different is this from PMREMGenerator.

But, for people not using it, rough reflections look much better indeed!

screen shot 2018-03-06 at 7 34 29 pm

@mrdoob mrdoob added this to the r91 milestone Mar 7, 2018
@takahirox takahirox mentioned this pull request Mar 7, 2018
@mrdoob
Copy link
Owner

mrdoob commented Mar 8, 2018

In ChromeOS seems like it gets blurred too quickly?

screenshot 2018-03-07 at 22 54 39

@mrdoob
Copy link
Owner

mrdoob commented Mar 8, 2018

On windows...

I see the same behavior with Microsoft Edge:

edge

Chrome seems fine:

chrome

And so seems Firefox:

firefox

@takahirox
Copy link
Collaborator Author

Confirmed it with Windows + Edge here, too.

Hm, I guess it could be from the WebGL (extensions) capability?

@mrdoob
Copy link
Owner

mrdoob commented Mar 8, 2018

Which extension would it be?

@takahirox
Copy link
Collaborator Author

I supposed float texture but Edge has. Hm, I might be wrong?

Chrome
image

Edge
image

@mrdoob
Copy link
Owner

mrdoob commented Mar 8, 2018

I was not aware this code relied in floating point textures...?

@mrdoob
Copy link
Owner

mrdoob commented Mar 8, 2018

I guess maxMipLevel that gets computed is different in Edge/Chrome OS?

@takahirox
Copy link
Collaborator Author

I was not aware this code relied in floating point textures...?

Ah, sorry. I just said floating texture without thinking deeply because I haven't looked into the related shader code yet.

@takahirox
Copy link
Collaborator Author

I guess maxMipLevel that gets computed is different in Edge/Chrome OS?

You meant, you guess the behavior of gl.generateMipmap() could be different?

@takahirox
Copy link
Collaborator Author

This issue seems appearing even in r90. I'm really not sure if it's related to mipmap yet.

@mrdoob
Copy link
Owner

mrdoob commented Mar 8, 2018

This issue seems appearing even in r90. I'm really not sure if it's related to mipmap yet.

That is a good point.

@mrdoob
Copy link
Owner

mrdoob commented Mar 9, 2018

Wild guess... Maybe this is related to window.devicePixelRatio?

@mrdoob
Copy link
Owner

mrdoob commented Mar 9, 2018

@takahirox is window.devicePixelRatio the same value in Edge and Chrome in your setup?

@WestLangley
Copy link
Collaborator

Another related point:

Our material.roughness is intended to be "perceptual" roughness. I would not be surprised if metallic and non-metallic materials responded differently to that property value. In any event, this is going to be somewhat subjective.

How the shader selects the mipmap level based on the roughness property is based on code copied from another source. That code can -- and may have to -- be changed.

@takahirox
Copy link
Collaborator Author

is window.devicePixelRatio the same value in Edge and Chrome in your setup?

Same.

@Mugen87 Mugen87 changed the title [WIP] Replace 8 with real maxMipLevel in lights_fragment_maps.glsl Replace 8 with real maxMipLevel in lights_fragment_maps.glsl Mar 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MeshStandardMaterial: Reflections visible for moderate roughness values

5 participants