How to implement shadows to ShaderMaterial using big atmospheric scattering shader?

Hey everyone, i’m making models of solar system planets with realistic atmospheres and shadows, and got some problems, i need modify ShaderMaterial in the way that mesh could receive shadows from various objects (for example: from rings, satellites etc)

here is current result with ShaderMaterial

this is result with MeshStandartMaterial

(this is test model so Saturn rings around Earth are appropriate =))

i’m looking for solution to combine both results, to get and atmospheric scattering and shadows from objects at the planet disc, can anyone help me to find answer? source code of the scene and shaders i will publish if it is needed

You can use onBeforeCompile on the MeshStandardMaterial, you can override default vertex and fragment shaders. Then, to override or modify the output color of the material, all you need to do is override output_fragment chunk (in r154 it’ll be opaque_fragment):

shader.fragmentShader = shader.fragmentShader
.replace(
  '#include <output_fragment>',
  `
    // NOTE Modify outgoingLight.rgb and diffuseColor.a here
    
    outgoingLight.rgb = vec3(1.0, 0.0, 1.0);

    // NOTE Include original chunk
    #include <output_fragment>
  `
);

Example - line 47. You can set outgoingLight to a new value to override previous shader calculations entirely. Add to outgoingLight to brighten the previously calculated color. And multiply outgoingLight - to darken it / use it as a mask.

2 Likes

thanks for answer!

how to pass all uniforms by this way then? i got a really huge V- and F- shaders with multiple variables, uniforms and code lines, and still don’t understand how to mix all of it correctly with standard material code