[Shaders] Casting different shadows

Hello all!

I’ve been looking around everything for modding purposes and eventually got into the materials and shaders…
So… I played a bit around and changed some stuffs and at some point I came across this shader that - by testing - seems to be the one that makes objects cast shadows when added to their material:

"DIRECTIONAL_SHADOWMAP": {
			"state" : "states/voxel/replace.state",
			"shader" : "shaders/voxel/flat_color.shader",
			"inputs" : [
				{
					"name" : "flat_color",
					"default" : [0, 0, 0, 0]
				}
			]
		},

So, I’ve learned that basically adding this to any material of things that wouldn’t usually cast shadows will make them cast shadows - which is cool… But some things should probably have lighter shadows or even different colors for their shadows (like smoke) and so I thought about tweaking those “flat_color” values to get different shadows…

However no matter what I change, the shadows always look the same…

So my question - just out of curiosity this time - is basically: would it be possible to tweak the shaders to change shadows opacity, color and maybe even softness? And if possible, how could one achieve that? :slight_smile:

Thanks and have a great weekend, everyone :slight_smile:

1 Like

Yes, it’s possible to change how shadows are rendered, but I don’t remember details off the top of my head. @ayazar is currently optimizing our shadow rendering, so he may be able to give you some pointers.

2 Likes

Awesome :slight_smile:

I’ll continue messing around but would indeed appreciate some pointers! :slight_smile:

Inside deferred_lighting.shader you can see where the shadows are applied:


  #ifndef DISABLE_SHADOWS
    shadowTerm = getShadowValue_deferred(pos) * (1.0 - global_desaturate_multiplier);
  #endif

  vec4 lightColor = calcPhongDirectionalLight(camViewerPos, pos, normal.xyz, depthInfo.b, depthInfo.a) * shadowTerm;
  gl_FragColor = vec4(globalDesaturate(lightColor.rgb + lightAmbientColor), lightColor.a);

So right now shadows are just a multiplier against the light, meaning you’d have to modify this shader to get colored shadows.

2 Likes

Ohhhh, I see.
Thank you for the reply!

So, if I create a new shader based on this instead of modifying it (and then a new material to use it) I could possibly create a new type of shadow and it would work alongside the default shadows, right?

If so, I guess I might have a couple of ideas of where I could apply that… However if the shadow rendering is being reviewed/optimized, I suppose it would be wise to wait for that

Actually I’d recommend modifying this shader and setting it as an override in your mod. The way the deferred renderer works, the lighting is calculated separately in it’s own pass after all of the attributes are rendered into a gbuffer. Checkout deferred_light.material.json to see the shaders involved. And take a look in forward_postprocess.pipeline.xml to see how the whole deferred renderer pipeline is put together. (It’s an xml file that defines what commands are issued for a given frame, we have two one for low-quality and one for high-quality. The main difference is that the high quality is a deferred renderer and low quality is a forward renderer.)

1 Like

It would be super cool if we got graphics mods at some point, and system is pretty easy to work with since it can sort-of hotload changes. I should add this to the modding guide.

2 Likes

I see!
That’s some good information, thanks :slight_smile:

I’ll be soon ™ releasing (finally!) the mod I’ve been working for a few weeks now… It’s basically a whole new industry and tons of content from that industry: Glass

And it has some interesting stained glass panels and custom 1x1 windows for people to create “stained glass pixel art”. Light goes through the windows but I was thinking and maybe it would be beautiful and amazing to make the light actually pass through with a color (from the glass), so stained glass panels would cast beautiful colored “shadows”

I thought about doing that with modified shadows! Guess it’ll be an interesting project for a future update of the mod :slight_smile:

5 Likes