Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEXTURE SPLATTING? #9

Closed
Thundros opened this issue Mar 13, 2020 · 32 comments
Closed

TEXTURE SPLATTING? #9

Thundros opened this issue Mar 13, 2020 · 32 comments

Comments

@Thundros
Copy link

Hi @gkjohnson! First off, I'd like to say BEAUTIFUL job! Please keep up the EXCELLENT work! <3 Secondly, can you please add texture splatting for terrain with a GUI to control the different texture's qualities, also with the ability to save the terrain with the new texture on it?

Once again, please keep up the WONDERFUL work! <3

@arpu
Copy link

arpu commented Mar 13, 2020

there is a example in the threejs forum at https://discourse.threejs.org/t/how-to-create-a-multiple-textured-terrain/5069/6 ( i use this shader on https://vrland.io/worldg )

babylon has some ideas for texture splatting on 64 images at
https://forum.babylonjs.com/t/pbr-texture-splatting-up-to-64-textures/1994

@Thundros
Copy link
Author

@arpu : Thank you brother, but that doesn't really answer my question.

@gkjohnson
Copy link
Owner

Hello and thank you!

As much as I enjoy working on these experiments my free time is limited and I have to be selective about what I put my time into especially for free. And unfortunately texture splatting isn't something I have a need for or am interested in. I recommend studying the forum link that @arpu posted or asking another question there with what you have tried if the solutions posted aren't sufficient.

Again I'm always happy to hear people enjoy what I'm working on and if you get any use out of it I'd be excited to see what you use it for!

@arpu
Copy link

arpu commented Mar 15, 2020

@gkjohnson if you have ideas or shader how to implement i could try to make a example with 64 different textures ( this needs splat Atlas or tiles? )

@gkjohnson
Copy link
Owner

gkjohnson commented Mar 15, 2020

@arpu

@gkjohnson if you have ideas or shader how to implement i could try to make a example with 64 different textures ( this needs splat Atlas or tiles? )

So I'm not too familiar with this topic but here are the things that seem important:

  • High resolution splat index texture with the ability to index into multiple splat tiles and alpha blend them.

  • Avoiding the mipmap bleeding associated with texture atlases.

  • Avoiding the look of repetitious textures.

I've looked around briefly to see what other peoples results look like in other engines and here's what I might try:

  • Create a high resolution splat index texture with 8 bits per channel where each channel represents the index of a tile. That should give you 256 varieties of splat tiles to use. A second sibling texture with the same splat pattern can be used to hold the alpha blending or weights of splat tiles to use.

  • Slightly offset the uv scales and position for each splat tile layer so they can be overlaid to combat the look of repetition in the scene.

  • Associate a heightmap with each splat tile to further combat the look of repetition and blend them more interestingly and realistically.

The mipmap bleeding issue is the hardest on in webgl, I think. Here's what I would look into to solve that:

  • See how the mipmapping behavior of 3d textures works and set each splat tile to be a different layer in the 3d texture to sample from.

  • Build a custom mipmap pyramid and implement custom mipmap filtering for the terrain shader, which would likely be a performance hit but still workable.

I haven't read through the whole forum post you sent so I don't know what everyone else has tried but that's where I would start in order to do this.

Let me know if you wind up putting something together for this!

@arpu
Copy link

arpu commented Mar 22, 2020

thx a lot @gkjohnson for your informative post!

for now this looks to complicated for me :/

@gkjohnson
Copy link
Owner

@arpu

thx a lot @gkjohnson for your informative post!

for now this looks to complicated for me :/

Of course! It's definitely not all-or-nothing, either. I think just focusing on using a texture atlas with splat index map and alpha weight map would be a pretty big improvement. WebGL2 might be your best bet though because it supports Sampler2DArrays (ctrl +f "texture arrays"), which is different than an array of textures, and should address the mip map bleeding issue. But unfortunately they're not supported in three.js yet.

If you wind up giving it a try let met know if you need a little more guidance!

@arpu
Copy link

arpu commented Apr 27, 2020

ok cool looks doable with https://jsfiddle.net/zywmxLd6/

@arpu
Copy link

arpu commented Apr 27, 2020

will study some shader code from microsplat https://github.com/MathieuUnity/UnityProject/blob/f82c5a9a6493624e1ce4b019f5f99cea85bbe845/SemaineSpe/Assets/Imports/Map2/Core/Examples/Scene/MicroSplatData/MicroSplat.shader

looks this can blend 32 texture that would be fine

@Thundros
Copy link
Author

@arpu : Would be great if you could make example for this.

@gkjohnson
Copy link
Owner

ok cool looks doable with https://jsfiddle.net/zywmxLd6/

I didn't realize DataTexture2DArray was a part of THREE! Heh looks like it's undocumented at the moment. It would be more convenient to have a non Data- version such as Texture2DArray so you don't have to access the raw texture data. It might be worth adding a feature request for.

I'm excited to see what comes out of this!

@Thundros
Copy link
Author

Would be BEAUTIFUL if someone could create a splatmap / terrain texture quality example. <3 MUCH thanks!

@arpu
Copy link

arpu commented Apr 27, 2020

will bring it online what i have now with rgb blend map for 4 Textures

@Thundros
Copy link
Author

@arpu : wonderfully awesome! Please do share link! <3

@arpu
Copy link

arpu commented Apr 28, 2020

@Thundros there is this older example http://stemkoski.github.io/Three.js/Shader-Heightmap-Textures.html ( not from me)

@Thundros
Copy link
Author

@arpu : that's not the type of splatmap I was thinking of. I'm thinking of RGBA.

@arpu
Copy link

arpu commented May 19, 2020

@Thundros
Copy link
Author

Thundros commented May 20, 2020

@arpu : Will test this out now! :)

@gkjohnson
Copy link
Owner

@arpu

Looks great! That looks like it's got a lot of what we talked about (and more)! It seems a bit under documented, though. It looks like the license is MIT -- maybe it's worth adopting the project or working with that dev and making a nicer more modular package out of it with a nice editable demo? It seems like the kind of thing a lot of projects would benefit from if packaged right. Might be a good fit for the three.js examples folder, too.

@gkjohnson
Copy link
Owner

Also just FYI it looks like it requires WebGL2.

@simondevyoutube
Copy link

Sorry about the lack of documentation, I'll add some more once I get a few minutes. Kinda just made up things as I went, so the code is a bit stream of consciousness :(

Let me know if you all need any help adapting it, it'd be great to see other projects using it.

@gkjohnson
Copy link
Owner

@simondevyoutube

Kinda just made up things as I went, so the code is a bit stream of consciousness :(

I didn't mean to knock it! I think that's how some of the best work gets done. I just figured that if someone was going to update it to work in their project it might be nice to help the documentation along the way.

Thanks for your awesome work!

@Thundros
Copy link
Author

@simondevyoutube : Yes. thank you for your AWESOME work! It would DEFINITELY help ALOT of people if you could make this regular javascript not using modules! MUCH appreciated for your work! PLEASE give yourself a pat on the back, PLEASE keep up the GREAT WORK! <3

@Thundros
Copy link
Author

Thundros commented May 21, 2020

This needs to work with a splatmap.

Like this :

splatmap

The transparency is blends between different textures. The transparent white is a gravel-textured road with the transparency mixing inbetween textures, the transparent blue is a river, the green is grass, the light red is rock / gravel. the dark red is mountain-texture / rock-texture.

Here's better images than mine :

splat1

splat2

splat3

@simondevyoutube
Copy link

@simondevyoutube

Kinda just made up things as I went, so the code is a bit stream of consciousness :(

I didn't mean to knock it! I think that's how some of the best work gets done. I just figured that if someone was going to update it to work in their project it might be nice to help the documentation along the way.

Thanks for your awesome work!

Oh no worries, wasn't offended.

@simondevyoutube
Copy link

simondevyoutube commented May 21, 2020

Re: Thundros

Just FYI, my technique painted the splat values into vertices, since I can guarantee both ordering and texture indices per face. It's an important point for allowing the unlimited different textures.

If your use case absolutely requires a texture splat map, you'll have to modify this technique. I haven't given thought on how to make a splat texture work with this technique, so you'll have to start from scratch or go with the standard RGBA 4 texture setup.

@Thundros
Copy link
Author

:(

@gkjohnson
Copy link
Owner

gkjohnson commented May 22, 2020

@Thundros

:(

You're asking people to do a lot of non trivial work for you for free to fit your specific use cases (and it looks like in a lot of different repos). We have given you a lot of resources and places to start as well as offers of further guidance and @simondevyoutube has provided an incredibly generous start. Please put some effort into this yourself if you would like to see it happen.

You should be able to update @simondevyoutube's example to use index and weight textures to support what you're looking to do. Keep in mind creating a terrain with a blended system with > 4 terrain types like this is likely not as simple as just making textures in photoshop. A terrain editing system will probably be needed in order to keep the two textures in sync. Perhaps someone is generous to do this but I suggest putting some time in yourself to contribute back -- it's the only way to guarantee it happens the way you want. Everyone in this thread has done quite a bit.

@Thundros
Copy link
Author

No, I'm asking some people to be nice enough to help alot of people. Not just me. Anywho, I guess no one gives a fuck so closing this.

@arpu
Copy link

arpu commented Jun 11, 2020

this looks like a good start https://github.com/Zylann/godot_heightmap_plugin/blob/multisplat/addons/zylann.hterrain/shaders/multisplat16.shader

@arpu
Copy link

arpu commented Jun 16, 2020

hmm my initial plan was using compressedTextures with Basisu but looks like this is not supported by threejs https://discourse.threejs.org/t/is-it-possible-to-have-a-texture-array-of-compressed-textures/16213/3

@gkjohnson
Copy link
Owner

hmm my initial plan was using compressedTextures with Basisu but looks like this is not supported by threejs

I would definitely suggest making a feature request for it -- it seems webgl2 is becoming more nominally supported in threee.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants