comparison tests/test_vulkan_wrapper.nim @ 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 0c3f4f6f1aa2
comparison
equal deleted inserted replaced
784:fa39e67dded7 785:1880ab140165
39 ) 39 )
40 mat3 = Material( 40 mat3 = Material(
41 name: "mat3", 41 name: "mat3",
42 materialType: "my_special_material", 42 materialType: "my_special_material",
43 constants: { 43 constants: {
44 "colors": toGPUValue(newVec4f(0.5, 0.5, 0)) 44 "color": toGPUValue(newVec4f(0.5, 0.5, 0))
45 }.toTable 45 }.toTable
46 ) 46 )
47 47
48 proc scene_different_mesh_types(): Entity = 48 proc scene_different_mesh_types(): Entity =
49 result = newEntity("root", [], 49 result = newEntity("root", [],
153 proc main() = 153 proc main() =
154 var engine = initEngine("Test") 154 var engine = initEngine("Test")
155 155
156 # INIT RENDERER: 156 # INIT RENDERER:
157 const 157 const
158 shaderConfiguration = createShaderConfiguration( 158 shaderConfiguration1 = createShaderConfiguration(
159 inputs=[ 159 inputs=[
160 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), 160 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
161 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), 161 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite),
162 attr[Vec3f]("translate", perInstance=true), 162 attr[Vec3f]("translate", perInstance=true),
163 attr[uint16]("materialIndex", perInstance=true), 163 attr[uint16]("materialIndex", perInstance=true),
172 attr[Sampler2DType]("my_little_texture", arrayCount=2) 172 attr[Sampler2DType]("my_little_texture", arrayCount=2)
173 ], 173 ],
174 vertexCode="""gl_Position = vec4(position + translate, 1.0); outcolor = color; materialIndexOut = materialIndex;""", 174 vertexCode="""gl_Position = vec4(position + translate, 1.0); outcolor = color; materialIndexOut = materialIndex;""",
175 fragmentCode="color = texture(my_little_texture[materialIndexOut], outcolor.xy) * 0.5 + outcolor * 0.5;", 175 fragmentCode="color = texture(my_little_texture[materialIndexOut], outcolor.xy) * 0.5 + outcolor * 0.5;",
176 ) 176 )
177 shaderConfiguration2 = createShaderConfiguration(
178 inputs=[
179 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
180 attr[Vec3f]("translate", perInstance=true),
181 ],
182 intermediates=[attr[Vec4f]("outcolor")],
183 outputs=[attr[Vec4f]("color")],
184 uniforms=[attr[Vec4f]("color")],
185 vertexCode="""gl_Position = vec4(position + translate, 1.0); outcolor = Uniforms.color;""",
186 fragmentCode="color = outcolor;",
187 )
177 engine.initRenderer({ 188 engine.initRenderer({
178 "my_material": shaderConfiguration, 189 "my_material": shaderConfiguration1,
179 "my_special_material": shaderConfiguration, 190 "my_special_material": shaderConfiguration2,
180 }.toTable) 191 }.toTable)
181 192
182 # INIT SCENES 193 # INIT SCENES
183 var scenes = [ 194 var scenes = [
184 newScene("simple", scene_simple(), transformAttribute=""), 195 newScene("simple", scene_simple(), transformAttribute=""),