Terrain normalmap


#1

i feel stupid, but i really dont know why normalmap dont work for me for TerrainLighting.

i think it was working before i had “long break” from game developing.

  1. add new scene in IDE
  2. add there terrain with diffuse and normal texture
  3. add directional light with [-0.6909942, -0.21225935, -0.6909942] location
  4. remove and add normalmap give 0 difference visually.

as i see terrain got normalRecalc control, so should generate tangents itself right?

i understand it can be about intensity, but normalmap have big intensity and TerrainLighting for some reason dont have intensity param, just shining(changing it also no difference).

or maybe i just dont remember how to generate tangents for terrain.

anyway i hope you will remind me what i do wrong :slight_smile:

with normalmaps:
withNormalmaps

without normalmaps:


#2

Lighting needs tangents. Generate them. I don’t know about the ide but programmatically you can use the BiNormalTangentGenerator or whatever it’s called. Maybe you can right click the mesh node or something and generate them there in the ide. I have zero experience with the ide.


#3

i thought i should not generate via:

TangentBinormalGenerator.generate(terrain);

because then i got odd issue like below(lines each some distance, and anyway no effect visible - normalmap dont have lines like this):

tangentgenerate

anyway terrain got normalRecalc control so i belive it should calculate this itself.


#4

Really, I’d expect the terrain shader to be doing its own tangent generation from the normals… because it’s silly to precalculate them.

…but I’m not at all familiar with JME’s terrain shader.


#5

Correction: lighting needs normals.

Only normal maps and bump maps need tangents. And for terrain, tangents are really consistent and there is no reason that the shader couldn’t do it.


#6

Just tagging @Darkchaos in the likely chance that this is a sdk issue.


#7

What one can do is rightclick the mesh and select Generate Tangents.
But it’s hard to tell if that is an SDK Bug or if it works in code?


#8

both,

in sdk i dont see differences in normalmaps and option to generate tangents(anyway it have NormalRecalc control so why everyone tell about generating all time).

in non sdk i dont see differences in normalmaps, when generating tangents manually then i got issue like last screenshot.

Maybe its NormalRecalc controller issue?

is here Anyone who got working TerrainLighting with normalmaps?


#9

Are you using an ambient light in the scene? I’ve noticed ambient lights that are too bright will drastically dim the effects of normal maps for the standard phong shaders, especially the terrain shader. I always struggled to get the normal maps to show much, and it seemed like the sun light had to be almost parallel to the terrain for the normal maps to even show up at all in some spots.

Switching to use a PBR terrain shader made a huge difference though - once a light probe is added, the normal maps appear 5x more noticeably for the terrain.

Unless I was also doing something wrong (or maybe there’s a bug), I’d say that normal maps seemed ineffective when using the phong TerrainLighting shader from my experience with it.


#10

by PBR Terrain Lighting you mean:

right?

because in base JME there are no PBR terrain.

about the link above i seen its kind of unstable ;/

about TerrainLighting i tried set directional light very low, anyway 0 effect visible ;/ Also in sdk there was only DL, no ambient.

in game i also tried no ambient, also no changes visible.


#11

Yes I actually used that thread as a reference for making my PBR shader, but had to make some changes.

Looking back, I do remember that I had to caculate the tangents in the shader myself, so that means they must not be pre-generated, like Paul mentioned

Using the tangents provided by “inTangent” in the terrain shader just caused the Terrain to appear entirely black if there was a light probe, so thats what lead me to realize the tangent values were wrong (or I should say not pre-caclualted like I assumed)

Just a guess but maybe the phong TerrainLighting shader is still using empty tangent values, rather than calculating them in the shader?


#12

Thanks, i will try use PBR Terrain then. do you have some fixed version or is this just ok to copy paste it from there and apply fix that @Ali_RS provided?

also i dont see it on github or anywhere, so i belive its just like free to use license. someone said that no license provided = cant use, so now i think what about user codes provided in JME forum?

about TerrainLighting that sound like required issue ticket on github, but i will not create, because im not sure if there is issue or not trully.


#13

You can copy and paste the shader from that thread entirely, and then the only change you need to make is the very end of the fragment shader that does the PBR lighting calculations.

So you could just copy all of the code in that thread that handle reading the terrain’s textures and roughness/metalic values.
And then update the last half of the shader to match whichever branch of the enginre you use.

So If you are using master, you could make an updated PBR terrain shader by copying all of the code after line 177 of PBRLighting.frag https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag#L177

and just paste that code in the bottom of your terrain shader after all of the alpha map texture reading is done. you might just need to make a few changes so it compiles, and so that all your texture names match


#15

ok sorry, mistake earlier, ok so just copy PBR standard shader last lines into Terrain PBR

edit:
its have a lot differences between this two shaders


#16

Once you get to the bottom where the lighting is calculated, the shaders mostly match (aside from some changes to master to support light probe blending and morph animation) The master version of PBRLighting also does not currently work with the stable version of the engine as a result, in which case you’d want to base your PBR terrain shader on whichever version of the engine you use.


#17

without changes - only from topic code

Uncaught exception thrown in Thread[jME3 Main,5,main]
RendererException: compile error in: ShaderSource[name=MatDefs/PBRTerrain/terrainPBRShader.frag, defines, type=Fragment, language=GLSL150]
Fragment shader failed to compile with the following errors:
ERROR: 0:744: error(#202) No matching overloaded function found: PBR_ComputeDirectLight
ERROR: error(#273) 1 compilation errors. No code generated

after copy everything below(from your link to JME PBR shader):
float ndotv = max( dot( normal, viewDir ),0.0);
into shader.

Uncaught exception thrown in Thread[jME3 Main,5,main]
RendererException: compile error in: ShaderSource[name=MatDefs/PBRTerrain/terrainPBRShader.frag, defines, type=Fragment, language=GLSL150]
Fragment shader failed to compile with the following errors:
ERROR: 0:744: error(#202) No matching overloaded function found: PBR_ComputeDirectLight
ERROR: 0:800: error(#143) Undeclared identifier: alpha
ERROR: error(#273) 2 compilation errors. No code generated

will try look at it, but if you know what might be wrong, would be nice, maybe alpha is named differently

will copy from line 177 now, but a lot differences there

edit: when i copy after line 177, then i got:

Uncaught exception thrown in Thread[jME3 Main,5,main]
RendererException: compile error in: ShaderSource[name=MatDefs/PBRTerrain/terrainPBRShader.frag, defines, type=Fragment, language=GLSL150]
Fragment shader failed to compile with the following errors:
ERROR: 0:716: error(#198) Redefinition error: specular
ERROR: 0:718: error(#143) Undeclared identifier: albedo
ERROR: 0:718: error(#160) Cannot convert from: "float" to: "highp 4-component vector of vec4"
ERROR: 0:719: error(#198) Redefinition error: diffuseColor
ERROR: 0:769: error(#202) No matching overloaded function found: PBR_ComputeDirectLight
ERROR: 0:825: error(#143) Undeclared identifier: alpha
ERROR: error(#273) 6 compilation errors.  No code generated

so like said too much changes ;/ i belive it will not be that quite easy


#18

Is the shader possibly missing the imports at the top?

#import "Common/ShaderLib/GLSLCompat.glsllib"
#import "Common/ShaderLib/PBR.glsllib"
#import "Common/ShaderLib/Parallax.glsllib"
#import "Common/ShaderLib/Lighting.glsllib"

You may also need to add some variables or change the name of some - I recall I also had to make a lot of small tweaks and changes with renaming things to get the shader to compile


#19

about imports, i have them in fragment shader.

i will try make changes, but can’t you just share fixes from your file with me?

looks like this require 2 fixes:

  • missing PBR_ComputeDirectLight somehow
  • alpha param messed up somewhere

#20

yes i can definitely post my shader code if you’d like, I just am not sure if it will be any easier of a reference, since my shaders also have some modifications and extra functionality specific to my game, and they are slightly cluttered since I still edit them a lot

I would like to share my PBR shader and upload it to github in a way that it can be downloaded and easily used “out of the box” alongside a converter class that handles roughness/metallic values for each texture as you register them, and finally creates a new PBR terrain based on a phong terrain… but its been difficult to find an organized way to make it work with existent terrains and in the SDK, since you have to manually assign roughness and metallic values to each texture, and there’s no way to do that in the terrain editor


#21

i dont use SDK terrain editor, it was just example in this topic, because i wanted see if it work in SDK.

converter class that handles roughness/metallic values for each texture as you register them, and finally creates a new PBR terrain based on a phong terrain…

this sounds crazy :smiley: