bevy_sky_gradient 0.3.0

Sky rendering plugin for bevy featuring, sky gradient, aurora / northern lights, stars, sun, day-night cycle
Documentation
use bevy::mesh::MeshVertexBufferLayoutRef;
use bevy::pbr::{MaterialPipeline, MaterialPipelineKey};
use bevy::prelude::*;
use bevy::render::render_resource::{
    AsBindGroup, CompareFunction, RenderPipelineDescriptor, SpecializedMeshPipelineError,
};
use bevy::shader::ShaderRef;

use crate::bind_groups::AuroraBindGroup;

#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)]
pub struct AuroraMaterial {
    #[uniform(0)]
    pub aurora_settings: crate::bind_groups::AuroraBindGroup,

    #[texture(1, dimension = "3d")]
    #[sampler(2)]
    pub noise3_image: Handle<Image>,
}

impl Material for AuroraMaterial {
    fn vertex_shader() -> ShaderRef {
        crate::assets::FULL_AURORA_SHADER_HANDLE.into()
    }
    fn fragment_shader() -> ShaderRef {
        crate::assets::FULL_AURORA_SHADER_HANDLE.into()
    }

    fn specialize(
        _pipeline: &MaterialPipeline,
        descriptor: &mut RenderPipelineDescriptor,
        _layout: &MeshVertexBufferLayoutRef,
        _key: MaterialPipelineKey<Self>,
    ) -> Result<(), SpecializedMeshPipelineError> {
        if let Some(depth_stencil) = &mut descriptor.depth_stencil {
            depth_stencil.depth_write_enabled = false;
            depth_stencil.depth_compare = CompareFunction::Always;
        }

        Ok(())
    }
}

impl Default for AuroraMaterial {
    fn default() -> Self {
        AuroraMaterial {
            aurora_settings: AuroraBindGroup::default(),
            noise3_image: Handle::default(),
        }
    }
}