Already new standard material, based on NodeMaterial?

Ahh… ok, sorry I misunderstood about that. Yeah, those are excellent questions you raise. Let’s listen to comments from the pros (like you). :slight_smile:

Are you going to test some speculars and shadows on the above PG series? Teach/show us what you learn, ok? Perhaps we need to wire-up some light nodes to the box material? Got the docs memorized? :wink:

YOU might be the #1 or #2 expert on this new system, at this time. If you go experimenting… please teach us what you learn. thx!

I went into the editor and clicked “Export shaders”. The shader code that was generated by the NodeMaterial shows that lighting is not included but has to be modeled using more nodes. When I saw that, I thought “duh, of course!”. (So, forget my stupid question from above).

So, what I need is a simple example how to connect a NodeMaterial to a ShadowGenerator. I think, the rest will be quite easy. :slight_smile:

1 Like

Hey:) it will be automatically done:) as long as you add a light node, the node will take care of the shadows as well and if your light has a shadowgenerator then magic will happen;)

In a nutshell, wiring a light node is all that you need:)

Hey :slight_smile: this comes in handy! I am just in the middle of tinkering with it. The light node wants a world position input – where do I get it from? is it the world position of the light itself?

It is the world position of the mesh position. You should already have it for the vertex output (mesh position transformed by world matrix)

Oops, suddenly my node editor window is gone. When I click “Edit”, it does not re-appear.

Try reload:) if you can repro I’m interested by your save file

Wow, in the editor I have created this node graph. Worked well!

The box looks green with specular lighting, as expected.

HOWEVER: When I generate the code and put it back into the original playground, I see a black box instead of a green box.
See here: https://playground.babylonjs.com/#4I3SIR#9

How come?

What I need now is a node for which I can write the shader code by myself. Example: Height-dependent colors for a terrain, done in the fragment shader.

Is there a (kind of) “generic” node?

Found something: In the code further down, the specular color is set to black. When I set it to white, the box becomes green.

light.specular = BABYLON.Color3.White();

Yep no need for more. Your specular was just black :slight_smile:

Regarding custom shader code node. This is not the goal of the node material. You can write it using other nodes.

For custom shader code you need to get back to the ShaderMaterial (where you can use includes to get some code done for you though)

I went back and extended the SimpleMaterial sample to meet my needs. Works quite well so far, except that the ShadowGenerator sometimes does not generate a shadow. I asked another question today in this forum because it’s another topic.

Thanks so far for your help!

1 Like

@mattes3 Did you succeed in implementing a material for height dependant texturing with propper lightning/shadowing? I could use such a thing for my current project as well. I’ve played around with the worldmonger groundMaterial, but it lacks lightning/shadowing AFAICS.

Hi @holger,
yes, I succeeded in doing so. The shadows are cast on the terrain because I included the standard shader includes in my terrain shaders that I derived from the Worldmonger example. It worked pretty much out of the box because I used the SimpleMaterial class as a blueprint.

how are the standard shader includes included? I’m currently using the unmodified ground.fragment.fx and ground.vertex.fx shaders from worldmonger. Sorry, but I don’t fully understand I’m relatively new to this.
Any help appreciated!

I was totally new to that as well. I took these three files as templates and mixed the Worldmonger shader into a copy of them:

In simple.*.fx, you see include statements like this:

#include<shadowsVertex>[0..maxSimultaneousLights]

Statements like that include the standard shader snippets that reside in this directory:

You can find the included files pretty easily when you click “Find file” on Github and type some of the characters of the filename. Github will search the file for you.

Let me know if this helps.

Hi @mattes3,
thanks for the quick reply! As you suggested I’ve made a copy of the 3 simple* files and put them under the name groundMaterial into my project. Beside the renaming it needed no further modification to use them as a new material with a single texture for my terrain.
Now I need to make the neccessary modifications and patch the woldmonger code in. Please could you confirm if these steps are correct

  1. modifying my new groundMaterial so it can handle the needed textures (ground, rock, sand, grass, snow, blend) and set the appropriate uniforms into the shaders
  2. place the worldmonger fragment/vertex code at the right place (wherever that is :slight_smile: ) into the shaders of the new groundMaterial to handle the height dependant texturing

Thanks again for any help!

Hi Holger,
Sounds good to me. I did it tgat way and it worked!

Hi @mattes3 it worked out so far, thanks for all the help!

Good job @holger. Have fun!
Matthias