Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

FC2a: one check for a name a Material's shader doesn't declare (uniform or storage buffer); materials.tsx back under 500 lines

shinyobjectz21182ec6bada
diff --git a/runtime/look/src/parts.rs b/runtime/look/src/parts.rs
index d8c2bf62..e8637643 100644
--- a/runtime/look/src/parts.rs
+++ b/runtime/look/src/parts.rs
@@ -52,7 +52,7 @@ pub fn own_uniforms(p: &mut Program, id: &str, its: &[Item], spec: impl Fn(&Item
let v = serde_json::json!({ "uniforms": s.get("uniforms").cloned().unwrap_or(Value::Null), "buffers": s.get("buffers").cloned().unwrap_or(Value::Null) });
Some((f, serde_json::json!({ "type": "own:uniforms", "value": v })))
}).collect();
- if each.windows(2).all(|w| w[0].1 == w[1].1) {
+ if each.iter().all(|(_, v)| Some(v) == each.first().map(|x| &x.1)) {
return;
}
// the part's spec carries its track's hash: parts share a Material (as Bevy's share one handle) only when their
diff --git a/sdk/render/src/3d/materials.tsx b/sdk/render/src/3d/materials.tsx
index 3ef08608..a52ef1d5 100644
--- a/sdk/render/src/3d/materials.tsx
+++ b/sdk/render/src/3d/materials.tsx
@@ -122,20 +122,14 @@ export interface SurfaceShaderSpec {
/** shader defs: each NAME a WESL condition for `@if(NAME)` (a number is true), and a whole number also
* `constants::NAME`; each set of defs compiles its own pipeline */
defs?: ShaderDefs;
- /** a <Material>'s own (docs/control.feature FC2a): its vertex shader file and what its Material methods give; set by
- * <Material>, not on a ShaderExtension */
+ /** a <Material>'s own (docs/control.feature FC2a): its vertex shader file and what its Material methods give, and its
+ * read-only storage buffers; set by <Material>, not on a ShaderExtension */
own?: OwnMaterialFields;
- /** a <Material>'s read-only storage buffers, set by <Material> */
buffers?: Record<string, (number | number[])[]>;
}
/** What a <Material>'s Material methods give: vertex_shader, alpha_mode, depth_bias and the faces its specialize culls. */
-export interface OwnMaterialFields {
- vertex?: string;
- alpha_mode?: unknown;
- depth_bias?: number;
- cull_mode?: "Front" | "Back" | null;
-}
+export type OwnMaterialFields = { vertex?: string; alpha_mode?: unknown; depth_bias?: number; cull_mode?: "Front" | "Back" | null };
export type ShaderDefs = Record<string, boolean | number>;
/** Shader defs checked (docs/shaders.feature SH8). */
diff --git a/systems/shader/src/layout.rs b/systems/shader/src/layout.rs
index bce1e0f0..0dc26d2e 100644
--- a/systems/shader/src/layout.rs
+++ b/systems/shader/src/layout.rs
@@ -132,9 +132,14 @@ pub fn pack(fields: &[(String, String)], uniforms: &[(String, Vec4)]) -> Result<
/// type) in slot order (ui_bind.rs's), and each value is packed in its type's layout, a scalar or vector from a number,
/// an array or a colour and a struct from {field: value}. A value for a uniform the source doesn't declare is refused,
/// as is a declared one without a value.
+/// The first name given that isn't declared.
+pub(crate) fn undeclared<'a>(given: &'a serde_json::Map<String, serde_json::Value>, declared: &[(String, String)]) -> Option<&'a String> {
+ given.keys().find(|k| !declared.iter().any(|(n, _)| n == *k))
+}
+
pub fn slots(src: &str, declared: &[(String, String)], given: &serde_json::Map<String, serde_json::Value>, defs: &[ShaderDefVal]) -> Result<[[Vec4; 16]; 8], String> {
use raea_sys_material::shader_material::uniform;
- if let Some(k) = given.keys().find(|k| !declared.iter().any(|(n, _)| n == *k)) {
+ if let Some(k) = undeclared(given, declared) {
return Err(format!("no uniform {k}"));
}
let mut out = [[Vec4::ZERO; 16]; 8];
diff --git a/systems/shader/src/own.rs b/systems/shader/src/own.rs
index 09584514..1397e4e7 100644
--- a/systems/shader/src/own.rs
+++ b/systems/shader/src/own.rs
@@ -219,7 +219,7 @@ pub fn build(world: &mut World, v: &Value, image: &mut impl FnMut(&mut World, &V
dims[1] = Some(h.clone());
}
// its storage buffers from the spec's `buffers`, each in its declared type's layout
- if let Some(k) = buffers.keys().find(|k| !storages.iter().any(|(n, _)| n == *k)) {
+ if let Some(k) = layout::undeclared(&buffers, &storages) {
return Err(format!("{path} has no storage buffer {k}"));
}
let mut b = Vec::new();