changeset 1008:443e8090614c

fix: some mesh attributes will be handled automatically, ignore them when doing mesh-material-shader compatability-check
author sam <sam@basx.dev>
date Tue, 16 Apr 2024 00:36:39 +0700
parents 6261baf55963
children 8b0a91fa2210
files semicongine/material.nim semicongine/mesh.nim semicongine/renderer.nim
diffstat 3 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/material.nim	Mon Apr 15 22:33:24 2024 +0700
+++ b/semicongine/material.nim	Tue Apr 16 00:36:39 2024 +0700
@@ -55,6 +55,8 @@
 proc assertCanRender*(shader: ShaderConfiguration, materialType: MaterialType) =
   for attr in shader.inputs:
     if attr.perInstance:
+      if attr.name in [TRANSFORM_ATTRIB, MATERIALINDEX_ATTRIBUTE]:
+        continue
       assert materialType.instanceAttributes.contains(attr.name), &"MaterialType '{materialType}' requires instance attribute '{attr.name}' in order to be renderable with the assigned shader '{shader}'"
       assert materialType.instanceAttributes[attr.name] == attr.theType, &"Instance attribute '{attr.name}' of MaterialType '{materialType}' is of type {materialType.instanceAttributes[attr.name]} but assigned shader '{shader}' declares type '{attr.theType}'"
     else:
--- a/semicongine/mesh.nim	Mon Apr 15 22:33:24 2024 +0700
+++ b/semicongine/mesh.nim	Tue Apr 16 00:36:39 2024 +0700
@@ -50,6 +50,8 @@
     else:
       assert false, &"Mesh '{mesh.name}' is missing required vertex attribute '{name}: {theType}' for {material.theType}"
   for name, theType in material.theType.instanceAttributes:
+    if name in [TRANSFORM_ATTRIB, MATERIALINDEX_ATTRIBUTE]:
+      continue
     if mesh.instanceData.contains(name):
       assert mesh.instanceData[name].theType == theType, &"{material.theType} expected instance attribute '{name}' to be '{theType}' but it is {mesh.instanceData[name].theType}"
     else:
--- a/semicongine/renderer.nim	Mon Apr 15 22:33:24 2024 +0700
+++ b/semicongine/renderer.nim	Tue Apr 16 00:36:39 2024 +0700
@@ -155,6 +155,7 @@
 
   # find all material data and group it by material type
   for mesh in scene.meshes:
+    assert mesh.material != nil, "Mesh {mesh} has no material assigned"
     if not scenedata.materials.contains(mesh.material.theType):
       scenedata.materials[mesh.material.theType] = @[]
     if not scenedata.materials[mesh.material.theType].contains(mesh.material):
@@ -167,7 +168,7 @@
     if not (MATERIALINDEX_ATTRIBUTE in mesh[].attributes):
       mesh[].initInstanceAttribute(MATERIALINDEX_ATTRIBUTE, uint16(scenedata.materials[mesh.material.theType].find(mesh.material)))
 
-  renderer.checkSceneIntegrity(scene)
+  # renderer.checkSceneIntegrity(scene)
 
   # create index buffer if necessary
   var indicesBufferSize = 0'u64