Terrain normalmap

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.

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

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?

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?

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.

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.

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?

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.

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 jmonkeyengine/PBRLighting.frag at master · jMonkeyEngine/jmonkeyengine · GitHub

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

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

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.

1 Like

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

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

1 Like

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

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

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:

I am not at my computer to post up my code or upload my converter class, but tomorrow I could post my code, or if you’d like to try the converter class, I could post that to gtibhu and you can see if it works in your project, since you don’t need to worry about the fact that it doesn’t interface with the SDK yet.

1 Like

thanks, i will wait for tomorrow.

currently i will try find out why PBR_ComputeDirectLight is missing.

edit:

it kind of not load #import “Common/ShaderLib/PBR.glsllib”, because there is PBR_ComputeDirectLight. Even checked my lib version and this method is there…
it say about overload so i belive params then are wrong

ok i kind of got it why you do this crazy things. :slight_smile:

I had a moment after getting home to upload the files to github and got rid of the parts that depended on my project, so it should hopefully work alright, otherwise I can revise it again once I am awake tomorrow.

There’s a jar with a single class called “TerrainShaderConversion” that should be able to convert a phong terrain to my PBR shader, and theres also the shader files in the assets folder if you’d prefer to reference those

I should also note that i didn’t finish tri-planar mapping in the fragment shader.

1 Like

as i see your “converter” is just changing material/materialParams usage, nothing else.

i thought you change shader or something itself :slight_smile:

i will look at shader and see what differences it have to find what issue i have about PBR_ComputeDirectLight.

about shader material change i would design it via 2 files that extends some abstract method(that have remove material, apply material methods and texture managing method)