ClarkThyLord / Voxel-Core

Voxel plugin for the Godot game engine!
https://godotengine.org/asset-library/asset/465
MIT License
453 stars 28 forks source link

Raw color/HDR color support #61

Open NykolaR opened 2 years ago

NykolaR commented 2 years ago

First of all, love the tool, is amazing to work with.

I'm not sure if this is a bug or a technical limitation, but if you set your voxels color attribute into HDR space, when placed the color value seems to be clamped back into linear range (see screenshot below, left is voxel placed, right is the voxel placement preview rendering correctly). I haven't looked into the source code but am hoping to later this week to see if I can figure it out. Can use material emission to resolve this, but I think the raw color value workflow should also be valid, so that multiple emission levels can be used while keeping material count to a minimum, and just for convenience.

image

EDIT: I feel like I've made some progress, but am still bamboozled. It seems like both the placement preview cube and the voxelmesh are assembled using voxel_tool.gd using SurfaceTool, and are both setting the vertex colors correctly as far as I can tell from debugging, so I can't tell why only the preview mesh is displaying the colors properly. I was thinking it might have to do with how the material on the preview is displayed, but as far as I can tell it's setup in voxel_cursor.gd setup, and doesn't seem to do anything out of the ordinary. For now I feel like I'm at a bit of a dead end, but I'm gonna look at it some more again some other time

ClarkThyLord commented 2 years ago

Thanks, I'm glad you found it useful. As to what you're describing, I'm not too sure. From what I understand, you're saying that that the voxels look different in scene than they do in the VoxelSet Editor's VoxelViewer when you're editing them, right?

If that's the case then it might be because the VoxelSet Editor's VoxelViewer uses its own environment, which you can change to your project's environment by right clicking on the VoxelViewer's background and pressing "Change environment" in the context menu. The default environment for the VoxelViewer is here.

From what I understand HDR has more to do with how the used environment is setup, see docs.

NykolaR commented 2 years ago

I can probably explain what's going on a little more clearly, but I'm not sure if it's going to be solvable, from everything I looked at in the voxel core code it seems like it should work, so I either missed something or I feel like it might be something to do with how the SurfaceTool maps vertex colors.

Basically to generate these HDR colors, the 2 main ways to do that are by using emission which currently works great but if you want multiple emission amounts you end up with a bunch of materials being used, and it is a bit of a hassle if using custom shaders on the voxel models instead of the generated ones. You can also get the same HDR effect by setting your albedo to be greater than vec3(1, 1, 1), which you can do in the voxel editor since it uses Godots color selector (so basically, instead of a color being composed of 4 0-255 ints, it's instead composed of 4 floats, see screenshot below for my test voxel color setup)

image

In the VoxelObject when placing these voxels with Raw/HDR colors, the transparent placement preview voxel will correctly react to the environment and glow, but as soon as you place it the color gets clamped down and loses all it's HDR data. If you create a voxel set and set a voxels color to something really high like the above image with the Raw toggle, and start placing it into a scene that has an environment with tonemapping and/or glow postprocess you'll see what I'm talking about right away