I’ve been going around in circles for a few days now…
Jut thought i’d ask here to see if i’m missing anything obvious.
I’m trying to colour a mesh according to height (Y axis) and a few other parameters to get varying terrain across my maps.
I can do this with RawTexture.CreateRGBTexture(...)
or similar:
but it’s not a great fit; The resolution of the texture i need to generate is many times larger than the mesh if i want to avoid the pixelated boundaries visible where the snowline meets the grass in that image.
I tried playing with custom shaders:
but i loose shadows and diffuse coloring; Note the colouring of the mountain top does not take light into account so you just end up with a flat colour.
It does solve the pixelation issue though.
Both the issues are fixable with work…
but reading there doesn’t appear to be anything “out of the box” that will work here and fixing shadows seems like a lot of work that maybe i can avoid.
It’s interesting to note the reason shadows are usually an issue here is that shaders might be altering the vertex positions, so changing the shadow, whereas i am only altering the pixel color.
Next i tried playing with CustomProceduralTexture(...)
.
It seems like a good fit; It’s a nice mix of textures and custom shaders allowing me to just write a fragment shader but let Babylon do the shadows, defuse lighting, etc.
Unfortunately i don’t have access to the Y axis data; CustomProceduralTexture(...)
uses the src/Shaders/procedural.vertex.fx
vertex shader that only passes the X and Z axis to the fragment shader. (varying vec2 vPosition;
)
I poked around in CustomProceduralTexture(...)
source code and don’t see any obvious ways to change the default vertex shader.
Options i’m currently considering:
-
Use custom shaders. Fix shadows and diffuse lighting. It can be done but seems un-necesary.
-
Use
CustomProceduralTexture
and pass in /all/ my vertex data as auniform
parameter or texture and extrapolate to find Y axis for any given X,Z. This would work but seems like a lot of work for the GPU for nothing. -
Make a local copy of
CustomProceduralTexture(...)
andProceduralTexture(...)
which allows me to specify my own vertex shader at run time. There is already aCustomProceduralTexture.setFragment(...)
method. addingsetVertex(...)
would be fairly straight forward. (Any interest in me submitting a PR for something like this or is it too niche?)
Anyway,
i’ve had fun so far.
It’s the first time i’ve played with shaders. You can do some interesting things with them…