fenomas / noa

Experimental voxel game engine.
MIT License
612 stars 87 forks source link

How to create emissive/lighting blocks? #22

Closed Nesh108 closed 7 years ago

Nesh108 commented 7 years ago

Hey!

I just implemented the cloud generation but I noticed that, like all the other blocks, they are affected by the lighting. I tried setting the clouds not opaque or making it a fluid but they still are very dark underneath:

dark_clouds

Would there be a way to create blocks with an emissive color/texture (the only problem being with emissive color, is that you would lose the alpha channel as it only accepts Color3)? Same would be interesting for blocks which actually generate light, that would be sweet to have as a parameter like being a fluid or a solid.

EDIT: I thought about it and I would probably want the clouds to be affected by lighting in general just not have such a strong dark area underneath. Otherwise they would show up even when it's pitch dark.

Nesh108 commented 7 years ago

I actually found the problem to be my setting of the light. Sorry about that!

fenomas commented 7 years ago

Hey, sorry for the delay and glad it worked out.

To explain just a little what's going on here, my understanding of (and use of) materials (and below that shader features) is very basic. Right now every terrain mesh without a texture shares the same material, and every piece of mesh with a texture uses a clone of that same material.

The work is done in rendering.js#makeTerrainMaterial, but the details are purely whatever worked at the time. E.g. if you asked why the user-specified texture gets set to the material's diffuseTexture if alpha is needed, and the ambientTexture otherwise, the only answer is because things seemed to work as intended that way. (I'm secretly hoping some shader wizard will come along someday and improve this, or tell me how to improve it, etc.)