upbge icon indicating copy to clipboard operation
upbge copied to clipboard

Environment Map with LOD Bias Acts as Flat Shaded

Open adriansnetlis opened this issue 7 years ago • 8 comments

When having LOD bias with environment maps in nodes, the normals seem to be broken. The result is similar to flat shading. Basically, you can see seams in reflection between any 2 triangles, unless they're reflecting the same pixel. This breaks a whole set of functionality for the LOD bias slider (e.g. reflection roughness).

Image: problem

File: http://pasteall.org/blend/index.php?id=48468

Edit. An option to force a certain mipmap level to be used would also work well.

adriansnetlis avatar Dec 03 '17 21:12 adriansnetlis

Just wanted to ask - is it just me who thinks that this is quite important bug? This is like the No1 thing that prevents me from creating cool materials and effects in nodes (No2 being difficulties when using lamp data for shading input). And this issue has been there since the cubemaps got added in UPBGE. Please, fix it! :pray:

adriansnetlis avatar Dec 09 '17 11:12 adriansnetlis

This is similar to https://github.com/UPBGE/blender/issues/531.

panzergame avatar Dec 09 '17 14:12 panzergame

The normals should be normalized in the vertex shader before passing them to the fragment shader through the varying. Also, just to make sure everything is right, normalize it before using it in the fragment shader as well.

DCubix avatar Dec 10 '17 02:12 DCubix

@panzergame Oh, I forgot I already told this.

I think that a solution could be being able to specify one of the mipmap textures to be used (instead of offsetting the LOD bias).

adriansnetlis avatar Dec 10 '17 17:12 adriansnetlis

Being able to access a node that uses textureLod(sampler, coords, lod) instead of texture(sampler, coords, lod_bias) would solve this. Maybe another node called Texture LOD would do the trick? Shouldn't be that hard to make either. I'll look into it and maybe make it on my own.

adriansnetlis avatar Dec 16 '17 09:12 adriansnetlis

A node is fine for using textureLod, you just have to treats cases for cube map and 2d map, else for material texture it is harder because you have to replace any call to texture2D in normal/parallax functions.

panzergame avatar Dec 16 '17 13:12 panzergame

I just tried implementing, but got stuck at textureCubeLod() throwing this error: error C7558: OpenGL does not allow profile specifiers on declarations Seems to be something to do with OpenGL/GLSL profile core versions.

adriansnetlis avatar Dec 16 '17 14:12 adriansnetlis

Just made a patch that adds a Lod Color output to texture nodes. This allows to use Lod Bias slider to access individual mipmap levels of texture. A .diff here: https://pastebin.com/ajSQ3NnA (sorry for being this messy, forgot that I would be better off by making my own branch and adding pull request)

adriansnetlis avatar Dec 23 '17 16:12 adriansnetlis