feat: add production UI gallery and inspector system
CI / Format, lint, test, build (push) Waiting to run
CI / Format, lint, test, build (push) Waiting to run
This commit is contained in:
1 parent
cf6eaba534
commit
53dc1e44d8
95 files changed
+11003
-1652
No files matched your search
@@ -2,7 +2,7 @@ use avian3d::prelude::ColliderConstructor;
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{ColorDesc, MaterialDesc};
|
||||
use crate::{ColorDesc, EditorAssetRef, MaterialDesc};
|
||||
|
||||
/// Stable persisted identity for an actor. Bevy [`Entity`] IDs are runtime-only.
|
||||
#[derive(
|
||||
@@ -412,48 +412,6 @@ pub const COMPONENT_AUDIO_LISTENER_DESC: &str = "shared::components::AudioListen
|
||||
/// Stable imported sub-asset identifier used by authored audio clip references.
|
||||
pub const AUDIO_CLIP_SUB_ASSET_ID: &str = "audio:source";
|
||||
|
||||
/// Reference to an imported content-browser asset or sub-asset.
|
||||
#[derive(Reflect, Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct EditorAssetRef {
|
||||
/// Stable project asset registry UUID string.
|
||||
pub asset_id: String,
|
||||
/// Stable imported sub-asset ID inside the generated artifact.
|
||||
#[serde(default, alias = "mesh_label")]
|
||||
pub sub_asset_id: String,
|
||||
/// UI label cached for inspectors. The asset registry/artifact remains authoritative.
|
||||
#[serde(default)]
|
||||
pub label: String,
|
||||
/// Optional loadable project path cached for runtime hydration when the
|
||||
/// referenced asset is not available through an imported artifact lookup.
|
||||
#[serde(default)]
|
||||
pub source_path: Option<String>,
|
||||
}
|
||||
|
||||
impl EditorAssetRef {
|
||||
pub fn new(
|
||||
asset_id: impl Into<String>,
|
||||
sub_asset_id: impl Into<String>,
|
||||
label: impl Into<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
asset_id: asset_id.into(),
|
||||
sub_asset_id: sub_asset_id.into(),
|
||||
label: label.into(),
|
||||
source_path: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_source_path(mut self, source_path: impl Into<String>) -> Self {
|
||||
self.source_path = Some(source_path.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn is_resolved(&self) -> bool {
|
||||
!self.asset_id.trim().is_empty() && !self.sub_asset_id.trim().is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
/// Distance curve used by an authored spatial audio source.
|
||||
#[derive(Reflect, Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -1237,37 +1195,6 @@ fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// How a material should be resolved at runtime.
|
||||
#[derive(Reflect, Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub enum MaterialShaderKind {
|
||||
#[default]
|
||||
StandardLit,
|
||||
Unlit,
|
||||
Custom,
|
||||
}
|
||||
|
||||
/// Reference to a built-in or custom shader schema.
|
||||
#[derive(Reflect, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ShaderRefDesc {
|
||||
pub kind: MaterialShaderKind,
|
||||
#[serde(default)]
|
||||
pub schema_path: Option<String>,
|
||||
#[serde(default)]
|
||||
pub shader_path: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for ShaderRefDesc {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
kind: MaterialShaderKind::StandardLit,
|
||||
schema_path: None,
|
||||
shader_path: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Typed material parameter value exposed by a shader schema.
|
||||
/// Reflectable reference to an imported 3D model scene (glTF/GLB or FBX).
|
||||
/// Hydration turns this into a `WorldAssetRoot` on the entity.
|
||||
|
||||
@@ -19,6 +19,14 @@ mod prefab_overrides;
|
||||
mod renderer_material;
|
||||
mod rendering_profile_asset;
|
||||
|
||||
pub use material_schema::{
|
||||
standard_lit_input_schema, ColorDesc, EditorAssetRef, MaterialAlphaMode, MaterialInputDesc,
|
||||
MaterialInputGroupDesc, MaterialInputPresentation, MaterialInputSchema, MaterialInputSet,
|
||||
MaterialInputSource, MaterialInputTarget, MaterialParameter, MaterialParameterValue,
|
||||
MaterialRenderState, MaterialShaderKind, MaterialTextureBinding, MaterialTextureInputDesc,
|
||||
ShaderPropertyDesc, ShaderPropertyType, ShaderRefDesc, TextureChannel, TextureSemantic,
|
||||
};
|
||||
|
||||
pub use actor::{infer_actor_kind, validate_actor, ActorValidationError};
|
||||
pub use animation::*;
|
||||
pub use asset_fingerprint::AssetSourceFingerprint;
|
||||
@@ -33,12 +41,9 @@ pub use hydration::{
|
||||
StaticMeshArtifactCache,
|
||||
};
|
||||
pub use material_asset::{
|
||||
load_resolved_material_from_path, standard_lit_input_schema, MaterialAlphaMode, MaterialAsset,
|
||||
MaterialInputDesc, MaterialInputGroupDesc, MaterialInputPresentation, MaterialInputSchema,
|
||||
MaterialInputSet, MaterialInstanceAsset, MaterialProvenance, MaterialRenderState,
|
||||
MaterialTextureInputDesc, ShaderPropertyDesc, ShaderPropertyType, ShaderSchemaAsset,
|
||||
TextureSemantic, MATERIAL_ASSET_SCHEMA_VERSION, MATERIAL_INSTANCE_SCHEMA_VERSION,
|
||||
SURFACE_SHADER_SCHEMA_VERSION,
|
||||
apply_material_inputs_to_desc, load_resolved_material_from_path, material_inputs_from_desc,
|
||||
MaterialAsset, MaterialInstanceAsset, MaterialProvenance, ShaderSchemaAsset,
|
||||
MATERIAL_ASSET_SCHEMA_VERSION, MATERIAL_INSTANCE_SCHEMA_VERSION, SURFACE_SHADER_SCHEMA_VERSION,
|
||||
};
|
||||
pub use material_desc::*;
|
||||
pub use navigation::*;
|
||||
|
||||
+116
-451
@@ -4,8 +4,9 @@ use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
ColorDesc, EditorAssetRef, MaterialDesc, MaterialParameter, MaterialParameterValue,
|
||||
MaterialRef, MaterialShaderKind, MaterialTextureBinding, ShaderRefDesc, TextureChannel,
|
||||
EditorAssetRef, MaterialDesc, MaterialInputSchema, MaterialInputSet, MaterialInputSource,
|
||||
MaterialInputTarget, MaterialParameter, MaterialParameterValue, MaterialRef,
|
||||
MaterialRenderState, MaterialShaderKind, MaterialTextureBinding, ShaderRefDesc, TextureChannel,
|
||||
};
|
||||
|
||||
pub const MATERIAL_ASSET_SCHEMA_VERSION: u32 = 2;
|
||||
@@ -24,182 +25,124 @@ const fn default_surface_shader_schema_version() -> u32 {
|
||||
SURFACE_SHADER_SCHEMA_VERSION
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum MaterialAlphaMode {
|
||||
#[default]
|
||||
Opaque,
|
||||
Cutout,
|
||||
/// Converts the runtime/legacy descriptor into the lightweight authored input representation.
|
||||
pub fn material_inputs_from_desc(material: &MaterialDesc) -> MaterialInputSet {
|
||||
let mut values = vec![
|
||||
MaterialParameter {
|
||||
name: "base_color".into(),
|
||||
value: MaterialParameterValue::Color(material.base_color),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "metallic".into(),
|
||||
value: MaterialParameterValue::Float(material.metallic),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "roughness".into(),
|
||||
value: MaterialParameterValue::Float(material.roughness),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "emissive_color".into(),
|
||||
value: MaterialParameterValue::Color(material.emissive_color),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "emissive_intensity".into(),
|
||||
value: MaterialParameterValue::Float(material.emissive_intensity),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "uv_offset".into(),
|
||||
value: MaterialParameterValue::Vec2(material.uv_offset),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "uv_tiling".into(),
|
||||
value: MaterialParameterValue::Vec2(material.uv_tiling),
|
||||
},
|
||||
];
|
||||
for parameter in &material.parameters {
|
||||
if !is_standard_value_name(¶meter.name) {
|
||||
upsert_parameter(&mut values, parameter.clone());
|
||||
}
|
||||
}
|
||||
|
||||
let mut textures = Vec::new();
|
||||
if let Some(path) = material.base_color_texture.as_deref() {
|
||||
textures.push(path_texture_binding(
|
||||
"base_color",
|
||||
path,
|
||||
TextureChannel::Rgba,
|
||||
));
|
||||
}
|
||||
if let Some(path) = material.normal_map_texture.as_deref() {
|
||||
textures.push(path_texture_binding("normal", path, TextureChannel::Rgb));
|
||||
}
|
||||
if let Some(path) = material.metallic_roughness_texture.as_deref() {
|
||||
textures.push(path_texture_binding("occlusion", path, TextureChannel::R));
|
||||
textures.push(path_texture_binding("roughness", path, TextureChannel::G));
|
||||
textures.push(path_texture_binding("metallic", path, TextureChannel::B));
|
||||
}
|
||||
if let Some(path) = material.occlusion_texture.as_deref() {
|
||||
upsert_texture(
|
||||
&mut textures,
|
||||
path_texture_binding("occlusion", path, TextureChannel::R),
|
||||
);
|
||||
}
|
||||
if let Some(path) = material.emissive_texture.as_deref() {
|
||||
textures.push(path_texture_binding("emissive", path, TextureChannel::Rgb));
|
||||
}
|
||||
for texture in &material.textures {
|
||||
if !is_standard_texture_name(&texture.name) {
|
||||
upsert_texture(&mut textures, texture.clone());
|
||||
}
|
||||
}
|
||||
MaterialInputSet { values, textures }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
|
||||
pub struct MaterialRenderState {
|
||||
#[serde(default)]
|
||||
pub alpha_mode: MaterialAlphaMode,
|
||||
#[serde(default = "default_alpha_cutoff")]
|
||||
pub alpha_cutoff: f32,
|
||||
#[serde(default)]
|
||||
pub double_sided: bool,
|
||||
}
|
||||
|
||||
const fn default_alpha_cutoff() -> f32 {
|
||||
0.5
|
||||
}
|
||||
|
||||
impl Default for MaterialRenderState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
alpha_mode: MaterialAlphaMode::Opaque,
|
||||
alpha_cutoff: default_alpha_cutoff(),
|
||||
double_sided: false,
|
||||
/// Applies authored values to the runtime/legacy material representation.
|
||||
pub fn apply_material_inputs_to_desc(inputs: &MaterialInputSet, material: &mut MaterialDesc) {
|
||||
material.parameters.clear();
|
||||
material.textures.clear();
|
||||
for parameter in &inputs.values {
|
||||
match (parameter.name.as_str(), ¶meter.value) {
|
||||
("base_color", MaterialParameterValue::Color(value)) => material.base_color = *value,
|
||||
("metallic", MaterialParameterValue::Float(value)) => material.metallic = *value,
|
||||
("roughness", MaterialParameterValue::Float(value)) => material.roughness = *value,
|
||||
("emissive_color", MaterialParameterValue::Color(value)) => {
|
||||
material.emissive_color = *value
|
||||
}
|
||||
("emissive_intensity", MaterialParameterValue::Float(value)) => {
|
||||
material.emissive_intensity = *value
|
||||
}
|
||||
("uv_offset", MaterialParameterValue::Vec2(value)) => material.uv_offset = *value,
|
||||
("uv_tiling", MaterialParameterValue::Vec2(value)) => material.uv_tiling = *value,
|
||||
_ => upsert_parameter(&mut material.parameters, parameter.clone()),
|
||||
}
|
||||
}
|
||||
material.base_color_texture = binding_path(inputs.texture("base_color"));
|
||||
material.normal_map_texture = binding_path(inputs.texture("normal"));
|
||||
material.emissive_texture = binding_path(inputs.texture("emissive"));
|
||||
let roughness = binding_path(inputs.texture("roughness"));
|
||||
let metallic = binding_path(inputs.texture("metallic"));
|
||||
material.metallic_roughness_texture = match (roughness, metallic) {
|
||||
(Some(roughness), Some(metallic)) if roughness == metallic => Some(roughness),
|
||||
(Some(path), None) | (None, Some(path)) => Some(path),
|
||||
_ => None,
|
||||
};
|
||||
material.occlusion_texture = binding_path(inputs.texture("occlusion"));
|
||||
for texture in &inputs.textures {
|
||||
if !is_standard_texture_name(&texture.name) {
|
||||
upsert_texture(&mut material.textures, texture.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Canonical values and texture bindings consumed by both built-in and custom material schemas.
|
||||
///
|
||||
/// Values are keyed by stable input names. Validation rejects duplicates before publication;
|
||||
/// vectors are retained instead of maps so shader-defined presentation order remains serializable.
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
|
||||
pub struct MaterialInputSet {
|
||||
#[serde(default)]
|
||||
pub values: Vec<MaterialParameter>,
|
||||
#[serde(default)]
|
||||
pub textures: Vec<MaterialTextureBinding>,
|
||||
impl MaterialInputSource for MaterialDesc {
|
||||
fn to_material_inputs(&self) -> MaterialInputSet {
|
||||
material_inputs_from_desc(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl MaterialInputSet {
|
||||
pub fn from_material_desc(material: &MaterialDesc) -> Self {
|
||||
let mut values = vec![
|
||||
MaterialParameter {
|
||||
name: "base_color".into(),
|
||||
value: MaterialParameterValue::Color(material.base_color),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "metallic".into(),
|
||||
value: MaterialParameterValue::Float(material.metallic),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "roughness".into(),
|
||||
value: MaterialParameterValue::Float(material.roughness),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "emissive_color".into(),
|
||||
value: MaterialParameterValue::Color(material.emissive_color),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "emissive_intensity".into(),
|
||||
value: MaterialParameterValue::Float(material.emissive_intensity),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "uv_offset".into(),
|
||||
value: MaterialParameterValue::Vec2(material.uv_offset),
|
||||
},
|
||||
MaterialParameter {
|
||||
name: "uv_tiling".into(),
|
||||
value: MaterialParameterValue::Vec2(material.uv_tiling),
|
||||
},
|
||||
];
|
||||
for parameter in &material.parameters {
|
||||
if !is_standard_value_name(¶meter.name) {
|
||||
upsert_parameter(&mut values, parameter.clone());
|
||||
}
|
||||
}
|
||||
|
||||
let mut textures = Vec::new();
|
||||
if let Some(path) = material.base_color_texture.as_deref() {
|
||||
textures.push(path_texture_binding(
|
||||
"base_color",
|
||||
path,
|
||||
TextureChannel::Rgba,
|
||||
));
|
||||
}
|
||||
if let Some(path) = material.normal_map_texture.as_deref() {
|
||||
textures.push(path_texture_binding("normal", path, TextureChannel::Rgb));
|
||||
}
|
||||
if let Some(path) = material.metallic_roughness_texture.as_deref() {
|
||||
textures.push(path_texture_binding("occlusion", path, TextureChannel::R));
|
||||
textures.push(path_texture_binding("roughness", path, TextureChannel::G));
|
||||
textures.push(path_texture_binding("metallic", path, TextureChannel::B));
|
||||
}
|
||||
if let Some(path) = material.occlusion_texture.as_deref() {
|
||||
upsert_texture(
|
||||
&mut textures,
|
||||
path_texture_binding("occlusion", path, TextureChannel::R),
|
||||
);
|
||||
}
|
||||
if let Some(path) = material.emissive_texture.as_deref() {
|
||||
textures.push(path_texture_binding("emissive", path, TextureChannel::Rgb));
|
||||
}
|
||||
for texture in &material.textures {
|
||||
if !is_standard_texture_name(&texture.name) {
|
||||
upsert_texture(&mut textures, texture.clone());
|
||||
}
|
||||
}
|
||||
Self { values, textures }
|
||||
}
|
||||
|
||||
pub fn apply_to_material_desc(&self, material: &mut MaterialDesc) {
|
||||
material.parameters.clear();
|
||||
material.textures.clear();
|
||||
for parameter in &self.values {
|
||||
match (parameter.name.as_str(), ¶meter.value) {
|
||||
("base_color", MaterialParameterValue::Color(value)) => {
|
||||
material.base_color = *value
|
||||
}
|
||||
("metallic", MaterialParameterValue::Float(value)) => material.metallic = *value,
|
||||
("roughness", MaterialParameterValue::Float(value)) => material.roughness = *value,
|
||||
("emissive_color", MaterialParameterValue::Color(value)) => {
|
||||
material.emissive_color = *value
|
||||
}
|
||||
("emissive_intensity", MaterialParameterValue::Float(value)) => {
|
||||
material.emissive_intensity = *value
|
||||
}
|
||||
("uv_offset", MaterialParameterValue::Vec2(value)) => material.uv_offset = *value,
|
||||
("uv_tiling", MaterialParameterValue::Vec2(value)) => material.uv_tiling = *value,
|
||||
_ => upsert_parameter(&mut material.parameters, parameter.clone()),
|
||||
}
|
||||
}
|
||||
material.base_color_texture = binding_path(self.texture("base_color"));
|
||||
material.normal_map_texture = binding_path(self.texture("normal"));
|
||||
material.emissive_texture = binding_path(self.texture("emissive"));
|
||||
let roughness = binding_path(self.texture("roughness"));
|
||||
let metallic = binding_path(self.texture("metallic"));
|
||||
material.metallic_roughness_texture = match (roughness, metallic) {
|
||||
(Some(roughness), Some(metallic)) if roughness == metallic => Some(roughness),
|
||||
(Some(path), None) | (None, Some(path)) => Some(path),
|
||||
_ => None,
|
||||
};
|
||||
material.occlusion_texture = binding_path(self.texture("occlusion"));
|
||||
for texture in &self.textures {
|
||||
if !is_standard_texture_name(&texture.name) {
|
||||
upsert_texture(&mut material.textures, texture.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn texture(&self, name: &str) -> Option<&MaterialTextureBinding> {
|
||||
self.textures.iter().find(|binding| binding.name == name)
|
||||
}
|
||||
|
||||
pub fn validate_unique(&self) -> Result<(), String> {
|
||||
let mut names = std::collections::HashSet::new();
|
||||
for value in &self.values {
|
||||
if !names.insert(("value", value.name.as_str())) {
|
||||
return Err(format!(
|
||||
"material value `{}` is assigned more than once",
|
||||
value.name
|
||||
));
|
||||
}
|
||||
}
|
||||
for texture in &self.textures {
|
||||
if !names.insert(("texture", texture.name.as_str())) {
|
||||
return Err(format!(
|
||||
"material texture `{}` is assigned more than once",
|
||||
texture.name
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
impl MaterialInputTarget for MaterialDesc {
|
||||
fn apply_material_inputs(&mut self, inputs: &MaterialInputSet) {
|
||||
apply_material_inputs_to_desc(inputs, self);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,115 +363,6 @@ fn upsert_texture(values: &mut Vec<MaterialTextureBinding>, value: MaterialTextu
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub enum ShaderPropertyType {
|
||||
Bool,
|
||||
Float { min: Option<f32>, max: Option<f32> },
|
||||
Vec2,
|
||||
Vec3,
|
||||
Color,
|
||||
Enum { options: Vec<String> },
|
||||
Texture,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct MaterialInputGroupDesc {
|
||||
pub id: String,
|
||||
pub display_name: String,
|
||||
#[serde(default)]
|
||||
pub order: i32,
|
||||
#[serde(default)]
|
||||
pub advanced: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum TextureSemantic {
|
||||
#[default]
|
||||
Auto,
|
||||
Color,
|
||||
Normal,
|
||||
Scalar,
|
||||
Mask,
|
||||
Hdr,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct MaterialTextureInputDesc {
|
||||
#[serde(default)]
|
||||
pub semantic: TextureSemantic,
|
||||
#[serde(default)]
|
||||
pub default_channel: TextureChannel,
|
||||
#[serde(default)]
|
||||
pub allow_channel_override: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct MaterialInputDesc {
|
||||
pub name: String,
|
||||
pub display_name: String,
|
||||
#[serde(default)]
|
||||
pub group: String,
|
||||
#[serde(default)]
|
||||
pub order: i32,
|
||||
pub property_type: ShaderPropertyType,
|
||||
#[serde(default)]
|
||||
pub default_value: Option<MaterialParameterValue>,
|
||||
#[serde(default)]
|
||||
pub texture: Option<MaterialTextureInputDesc>,
|
||||
#[serde(default)]
|
||||
pub tooltip: String,
|
||||
#[serde(default)]
|
||||
pub advanced: bool,
|
||||
/// Authoring presentation only. Runtime evaluation continues to address inputs by `name`.
|
||||
#[serde(default)]
|
||||
pub presentation: MaterialInputPresentation,
|
||||
}
|
||||
|
||||
impl Default for MaterialInputDesc {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: String::new(),
|
||||
display_name: String::new(),
|
||||
group: String::new(),
|
||||
order: 0,
|
||||
property_type: ShaderPropertyType::Float {
|
||||
min: None,
|
||||
max: None,
|
||||
},
|
||||
default_value: None,
|
||||
texture: None,
|
||||
tooltip: String::new(),
|
||||
advanced: false,
|
||||
presentation: MaterialInputPresentation::Row,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Declares whether an input owns a visible row or is edited through another input's row.
|
||||
///
|
||||
/// Companion values remain independent in [`MaterialInputSet`]. This keeps the schema suitable for
|
||||
/// generated/custom shaders while allowing related controls such as emissive color and intensity
|
||||
/// to share one coherent Inspector row.
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum MaterialInputPresentation {
|
||||
#[default]
|
||||
Row,
|
||||
Companion {
|
||||
owner: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// Compatibility source alias for code that has not yet adopted the material-input terminology.
|
||||
pub type ShaderPropertyDesc = MaterialInputDesc;
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
|
||||
pub struct MaterialInputSchema {
|
||||
#[serde(default)]
|
||||
pub groups: Vec<MaterialInputGroupDesc>,
|
||||
#[serde(default)]
|
||||
pub inputs: Vec<MaterialInputDesc>,
|
||||
}
|
||||
|
||||
/// RON shader schema describing material inspector parameters.
|
||||
#[derive(Asset, TypePath, Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
@@ -552,181 +386,12 @@ impl ShaderSchemaAsset {
|
||||
}
|
||||
}
|
||||
|
||||
/// Engine-owned Standard Lit authoring schema. It is consumed by the same renderer used for
|
||||
/// project Surface schemas, so a future graph compiler only needs to emit this descriptor shape.
|
||||
pub fn standard_lit_input_schema() -> MaterialInputSchema {
|
||||
let groups = vec![
|
||||
MaterialInputGroupDesc {
|
||||
id: "surface_inputs".into(),
|
||||
display_name: "Surface Inputs".into(),
|
||||
order: 0,
|
||||
advanced: false,
|
||||
},
|
||||
MaterialInputGroupDesc {
|
||||
id: "advanced_inputs".into(),
|
||||
display_name: "Advanced Inputs".into(),
|
||||
order: 100,
|
||||
advanced: true,
|
||||
},
|
||||
MaterialInputGroupDesc {
|
||||
id: "uv_transform".into(),
|
||||
display_name: "UV Transform".into(),
|
||||
order: 90,
|
||||
advanced: false,
|
||||
},
|
||||
];
|
||||
let scalar_texture = |channel| MaterialTextureInputDesc {
|
||||
semantic: TextureSemantic::Scalar,
|
||||
default_channel: channel,
|
||||
allow_channel_override: true,
|
||||
};
|
||||
let inputs = vec![
|
||||
MaterialInputDesc {
|
||||
name: "base_color".into(),
|
||||
display_name: "Base Color".into(),
|
||||
group: "surface_inputs".into(),
|
||||
order: 0,
|
||||
property_type: ShaderPropertyType::Color,
|
||||
default_value: Some(MaterialParameterValue::Color(ColorDesc::default())),
|
||||
texture: Some(MaterialTextureInputDesc {
|
||||
semantic: TextureSemantic::Color,
|
||||
default_channel: TextureChannel::Rgba,
|
||||
allow_channel_override: false,
|
||||
}),
|
||||
tooltip: "Color multiplier applied to the base-color texture.".into(),
|
||||
advanced: false,
|
||||
presentation: MaterialInputPresentation::Row,
|
||||
},
|
||||
MaterialInputDesc {
|
||||
name: "metallic".into(),
|
||||
display_name: "Metallic".into(),
|
||||
group: "surface_inputs".into(),
|
||||
order: 10,
|
||||
property_type: ShaderPropertyType::Float {
|
||||
min: Some(0.0),
|
||||
max: Some(1.0),
|
||||
},
|
||||
default_value: Some(MaterialParameterValue::Float(0.0)),
|
||||
texture: Some(scalar_texture(TextureChannel::B)),
|
||||
tooltip: "Scalar multiplier; ARM/ORM uses the blue channel.".into(),
|
||||
advanced: false,
|
||||
presentation: MaterialInputPresentation::Row,
|
||||
},
|
||||
MaterialInputDesc {
|
||||
name: "roughness".into(),
|
||||
display_name: "Roughness".into(),
|
||||
group: "surface_inputs".into(),
|
||||
order: 20,
|
||||
property_type: ShaderPropertyType::Float {
|
||||
min: Some(0.0),
|
||||
max: Some(1.0),
|
||||
},
|
||||
default_value: Some(MaterialParameterValue::Float(0.65)),
|
||||
texture: Some(scalar_texture(TextureChannel::G)),
|
||||
tooltip: "Scalar multiplier; ARM/ORM uses the green channel.".into(),
|
||||
advanced: false,
|
||||
presentation: MaterialInputPresentation::Row,
|
||||
},
|
||||
MaterialInputDesc {
|
||||
name: "occlusion".into(),
|
||||
display_name: "Occlusion".into(),
|
||||
group: "surface_inputs".into(),
|
||||
order: 30,
|
||||
property_type: ShaderPropertyType::Float {
|
||||
min: Some(0.0),
|
||||
max: Some(1.0),
|
||||
},
|
||||
default_value: Some(MaterialParameterValue::Float(1.0)),
|
||||
texture: Some(scalar_texture(TextureChannel::R)),
|
||||
tooltip: "Ambient-occlusion strength; ARM/ORM uses the red channel.".into(),
|
||||
advanced: false,
|
||||
presentation: MaterialInputPresentation::Row,
|
||||
},
|
||||
MaterialInputDesc {
|
||||
name: "normal".into(),
|
||||
display_name: "Normal".into(),
|
||||
group: "surface_inputs".into(),
|
||||
order: 40,
|
||||
property_type: ShaderPropertyType::Float {
|
||||
min: Some(0.0),
|
||||
max: Some(1.0),
|
||||
},
|
||||
default_value: Some(MaterialParameterValue::Float(0.85)),
|
||||
texture: Some(MaterialTextureInputDesc {
|
||||
semantic: TextureSemantic::Normal,
|
||||
default_channel: TextureChannel::Rgb,
|
||||
allow_channel_override: false,
|
||||
}),
|
||||
tooltip: String::new(),
|
||||
advanced: false,
|
||||
presentation: MaterialInputPresentation::Row,
|
||||
},
|
||||
MaterialInputDesc {
|
||||
name: "emissive_color".into(),
|
||||
display_name: "Emissive".into(),
|
||||
group: "surface_inputs".into(),
|
||||
order: 50,
|
||||
property_type: ShaderPropertyType::Color,
|
||||
default_value: Some(MaterialParameterValue::Color(ColorDesc::srgb(
|
||||
1.0, 1.0, 1.0,
|
||||
))),
|
||||
texture: Some(MaterialTextureInputDesc {
|
||||
semantic: TextureSemantic::Color,
|
||||
default_channel: TextureChannel::Rgb,
|
||||
allow_channel_override: false,
|
||||
}),
|
||||
tooltip: "Emissive color multiplied by the texture and intensity.".into(),
|
||||
advanced: false,
|
||||
presentation: MaterialInputPresentation::Row,
|
||||
},
|
||||
MaterialInputDesc {
|
||||
name: "emissive_intensity".into(),
|
||||
display_name: "Emissive Intensity".into(),
|
||||
group: "surface_inputs".into(),
|
||||
order: 60,
|
||||
property_type: ShaderPropertyType::Float {
|
||||
min: Some(0.0),
|
||||
max: Some(50_000.0),
|
||||
},
|
||||
default_value: Some(MaterialParameterValue::Float(0.0)),
|
||||
texture: None,
|
||||
tooltip: "Emissive luminance multiplier in nits.".into(),
|
||||
advanced: false,
|
||||
presentation: MaterialInputPresentation::Companion {
|
||||
owner: "emissive_color".into(),
|
||||
},
|
||||
},
|
||||
MaterialInputDesc {
|
||||
name: "uv_offset".into(),
|
||||
display_name: "Offset".into(),
|
||||
group: "uv_transform".into(),
|
||||
order: 0,
|
||||
property_type: ShaderPropertyType::Vec2,
|
||||
default_value: Some(MaterialParameterValue::Vec2(Vec2::ZERO)),
|
||||
texture: None,
|
||||
tooltip: "Shared UV translation for every texture on this material.".into(),
|
||||
advanced: false,
|
||||
presentation: MaterialInputPresentation::Row,
|
||||
},
|
||||
MaterialInputDesc {
|
||||
name: "uv_tiling".into(),
|
||||
display_name: "Tiling".into(),
|
||||
group: "uv_transform".into(),
|
||||
order: 10,
|
||||
property_type: ShaderPropertyType::Vec2,
|
||||
default_value: Some(MaterialParameterValue::Vec2(Vec2::ONE)),
|
||||
texture: None,
|
||||
tooltip: "Shared UV scale for every texture on this material.".into(),
|
||||
advanced: false,
|
||||
presentation: MaterialInputPresentation::Row,
|
||||
},
|
||||
];
|
||||
MaterialInputSchema { groups, inputs }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
standard_lit_input_schema, MaterialAlphaMode, MaterialInputPresentation, ShaderPropertyType,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn material_v2_defaults_to_opaque() {
|
||||
|
||||
@@ -3,58 +3,10 @@
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{ComponentInstanceId, EditorAssetRef, ShaderRefDesc};
|
||||
|
||||
#[derive(Reflect, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[type_path = "shared::components"]
|
||||
pub enum MaterialParameterValue {
|
||||
Bool(bool),
|
||||
Float(f32),
|
||||
Vec2(Vec2),
|
||||
Vec3(Vec3),
|
||||
Color(ColorDesc),
|
||||
Enum(String),
|
||||
}
|
||||
|
||||
impl Default for MaterialParameterValue {
|
||||
fn default() -> Self {
|
||||
Self::Float(0.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Reflect, Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[type_path = "shared::components"]
|
||||
pub struct MaterialParameter {
|
||||
pub name: String,
|
||||
pub value: MaterialParameterValue,
|
||||
}
|
||||
|
||||
/// Channels sampled from a texture binding. Scalar material inputs use one channel while
|
||||
/// color/normal inputs use RGB or RGBA. The default preserves the pre-v2 whole-texture behavior.
|
||||
#[derive(Reflect, Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[type_path = "shared::components"]
|
||||
pub enum TextureChannel {
|
||||
R,
|
||||
G,
|
||||
B,
|
||||
A,
|
||||
Rgb,
|
||||
#[default]
|
||||
Rgba,
|
||||
}
|
||||
|
||||
#[derive(Reflect, Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[type_path = "shared::components"]
|
||||
pub struct MaterialTextureBinding {
|
||||
pub name: String,
|
||||
pub texture: Option<EditorAssetRef>,
|
||||
#[serde(default)]
|
||||
pub channel: TextureChannel,
|
||||
}
|
||||
use crate::{
|
||||
ColorDesc, ComponentInstanceId, EditorAssetRef, MaterialParameter, MaterialTextureBinding,
|
||||
ShaderRefDesc,
|
||||
};
|
||||
|
||||
/// Per-render-slot material override stored on scene actors.
|
||||
#[derive(Reflect, Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
@@ -76,34 +28,6 @@ pub struct MaterialOverride {
|
||||
pub slots: Vec<MaterialSlotOverride>,
|
||||
}
|
||||
|
||||
/// Serializable color description. This avoids coupling saved scenes to any internal color
|
||||
/// representation details.
|
||||
#[derive(Reflect, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||
#[reflect(Default, Debug, Serialize, Deserialize)]
|
||||
#[type_path = "shared::components"]
|
||||
pub struct ColorDesc {
|
||||
pub r: f32,
|
||||
pub g: f32,
|
||||
pub b: f32,
|
||||
pub a: f32,
|
||||
}
|
||||
|
||||
impl ColorDesc {
|
||||
pub const fn srgb(r: f32, g: f32, b: f32) -> Self {
|
||||
Self { r, g, b, a: 1.0 }
|
||||
}
|
||||
|
||||
pub fn to_color(self) -> Color {
|
||||
Color::srgba(self.r, self.g, self.b, self.a)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ColorDesc {
|
||||
fn default() -> Self {
|
||||
Self::srgb(0.8, 0.8, 0.8)
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolved runtime and legacy-compatible material representation. Project authoring uses
|
||||
/// `MaterialAsset`/`MaterialInputSet`; hydration maps this descriptor to renderer materials.
|
||||
#[derive(Component, Reflect, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
|
||||
Reference in new issue
Block a user