Mercurial > games > semicongine
changeset 785:1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 19 Aug 2023 23:30:25 +0700 |
parents | fa39e67dded7 |
children | 956e9c7e36da |
files | src/semicongine/mesh.nim tests/test_vulkan_wrapper.nim |
diffstat | 2 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/semicongine/mesh.nim Sat Aug 19 22:24:06 2023 +0700 +++ b/src/semicongine/mesh.nim Sat Aug 19 23:30:25 2023 +0700 @@ -236,8 +236,10 @@ proc updateAttributeData*[T: GPUType|int|uint|float](mesh: Mesh, attribute: string, data: seq[T]) = if mesh.vertexData.contains(attribute): + assert data.len < mesh.vertexData[attribute].len setValues(mesh.vertexData[attribute], data) elif mesh.instanceData.contains(attribute): + assert data.len < mesh.instanceData[attribute].len setValues(mesh.instanceData[attribute], data) else: raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") @@ -245,8 +247,10 @@ proc updateAttributeData*[T: GPUType|int|uint|float](mesh: Mesh, attribute: string, i: uint32, value: T) = if mesh.vertexData.contains(attribute): + assert i < mesh.vertexData[attribute].len setValue(mesh.vertexData[attribute], i, value) elif mesh.instanceData.contains(attribute): + assert i < mesh.instanceData[attribute].len setValue(mesh.instanceData[attribute], i, value) else: raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}")
--- a/tests/test_vulkan_wrapper.nim Sat Aug 19 22:24:06 2023 +0700 +++ b/tests/test_vulkan_wrapper.nim Sat Aug 19 23:30:25 2023 +0700 @@ -41,7 +41,7 @@ name: "mat3", materialType: "my_special_material", constants: { - "colors": toGPUValue(newVec4f(0.5, 0.5, 0)) + "color": toGPUValue(newVec4f(0.5, 0.5, 0)) }.toTable ) @@ -155,7 +155,7 @@ # INIT RENDERER: const - shaderConfiguration = createShaderConfiguration( + shaderConfiguration1 = createShaderConfiguration( inputs=[ attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), @@ -174,9 +174,20 @@ vertexCode="""gl_Position = vec4(position + translate, 1.0); outcolor = color; materialIndexOut = materialIndex;""", fragmentCode="color = texture(my_little_texture[materialIndexOut], outcolor.xy) * 0.5 + outcolor * 0.5;", ) + shaderConfiguration2 = createShaderConfiguration( + inputs=[ + attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), + attr[Vec3f]("translate", perInstance=true), + ], + intermediates=[attr[Vec4f]("outcolor")], + outputs=[attr[Vec4f]("color")], + uniforms=[attr[Vec4f]("color")], + vertexCode="""gl_Position = vec4(position + translate, 1.0); outcolor = Uniforms.color;""", + fragmentCode="color = outcolor;", + ) engine.initRenderer({ - "my_material": shaderConfiguration, - "my_special_material": shaderConfiguration, + "my_material": shaderConfiguration1, + "my_special_material": shaderConfiguration2, }.toTable) # INIT SCENES