Darkening sides of custom mesh without seperate textures

Hey, basically I have code generating a big custom mesh made out of blocks. Right now it looks rather plain though since it’s all textured the same way. Is there any way to turn specific cube faces darker (or specific vertices) without using a seperate texture?

For reference, this is what it looks like right now:

I assume that you are looking for a solution that doesn’t require custom shaders.
If that’s the case, you can set UseVertexColor to true for your material instance and create a Color vertexbuffer for your mesh where you can specify the color for each vertex.
This will work with (SP)Lighting.j3md and Unshaded.j3md.

If you are already using a custom material, you’ll have to implement it yourself with the inColor attribute that you can get from the vertex shader .

You mean like light and shadows?

I believe he meant the same effect that you get in voxel games when you select an object a black bound box.

Sort of a simulation. I want to darken for instance the bottom side of a block and brighten the top to give it contrast and make it look more 3D. A full light system isn’t needed

I am using a custom material, how would I go about doing that?

Is your material based on Unshaded.j3md?
Because using one directional light plus one ambient light really won’t hurt performance too much. And it’ll do exactly what you want to achieve.

1- Set the color of each vertex in the Color vertexbuffer.
2- Pass the vertex color from the vertex shader to the fragment shader and use it to change the output color

Vertex Shader

in vec4 inColor;
out vec4 vColor;

void main(){

Fragment shader

in vec4 vColor;

void main(){

I mean, it sounds like what you want is lighting… and there is literally no reason not to just use lighting.

Your choices are:

  1. include per vertex colors (and make sure the corners of common faces are shared and not all corners at the same spot… ie: 24 vertexes instead of 6) and then do lighting calculations yourself to figure out what you want the color to be.

  2. include per vertex normals (and make sure the corners of common faces are shared and not all corners at the same spot… ie: 24 vertexes instead of 6) and then use the lighting shader.

It’s not really any more expensive.

The benefit of the second way is that you still have vertex colors available if you want them for something else.

I think what you mean is baked lighting aka cellular automata.

There are countless papers on this but the basic technique is creating a height map which is useful for a ton of reasons, namely what the sun can light and where to plant vegetation or not, and using cellular automata for things like torches and lava and caves aka light propagation.

For every air block that is above the height map give it full light, else reduce the light in a cellular automata fashion. Taking block densities into account and such. that way caves go dark as they become deep. And so on. It is a wonderful technique.

I don’t really want to build in a full lighting system just yet but what I mean is for instance in the game Minecraft you have a lighting system. But it also has a system that slightly darkens sides of the blocks regardless of lighting. This makes it look 3D instead of just flat textures when put on a larger scale.

Here’s an example picture:

That’s lighting. It’s the least amount of effort to get where you want to go. And costs nothing more than anything else that would imitate it.

Minecraft also uses ‘smooth shading’ which is based on a texture atlas of an overlay texture to darken certain corners/edges and provides a sort of fake AO. That’s not lighting but does require a separate set of texture coordinates and a separate atlas of the AO cells.

Edit: note by “lighting” here I’m not at all referring to the light propagation using cellular automata. I’m referring to different shading based on what is/isn’t facing the light.

1 Like

Check this out

1 Like