mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 06:00:20 +00:00
pbr: add "shaded" field to StandardMaterial
This commit is contained in:
parent
031a0c6d58
commit
6022ad2c4f
2 changed files with 12 additions and 4 deletions
|
@ -6,6 +6,9 @@ pub struct StandardMaterial {
|
|||
pub albedo: Color,
|
||||
#[shader_def]
|
||||
pub albedo_texture: Option<Handle<Texture>>,
|
||||
#[render_resources(ignore)]
|
||||
#[shader_def]
|
||||
pub shaded: bool,
|
||||
}
|
||||
|
||||
impl Default for StandardMaterial {
|
||||
|
@ -13,6 +16,7 @@ impl Default for StandardMaterial {
|
|||
StandardMaterial {
|
||||
albedo: Color::rgb(1.0, 1.0, 1.0),
|
||||
albedo_texture: None,
|
||||
shaded: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,12 +33,14 @@ layout(set = 3, binding = 1) uniform sampler StandardMaterial_albedo_texture_sam
|
|||
# endif
|
||||
|
||||
void main() {
|
||||
vec4 albedo = Albedo;
|
||||
vec4 output_color = Albedo;
|
||||
# ifdef STANDARDMATERIAL_ALBEDO_TEXTURE
|
||||
albedo *= texture(
|
||||
output_color *= texture(
|
||||
sampler2D(StandardMaterial_albedo_texture, StandardMaterial_albedo_texture_sampler),
|
||||
v_Uv);
|
||||
# endif
|
||||
|
||||
# ifdef STANDARDMATERIAL_SHADED
|
||||
vec3 normal = normalize(v_Normal);
|
||||
vec3 ambient = vec3(0.05, 0.05, 0.05);
|
||||
// accumulate color
|
||||
|
@ -51,7 +53,9 @@ void main() {
|
|||
// add light contribution
|
||||
color += diffuse * light.color.xyz;
|
||||
}
|
||||
output_color.xyz *= color;
|
||||
# endif
|
||||
|
||||
// multiply the light by material color
|
||||
o_Target = vec4(color, 1.0) * albedo;
|
||||
// o_Target = vec4(v_Normal, 1.0);
|
||||
o_Target = output_color;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue