comparison tests/test_vulkan_wrapper.nim @ 650:be6e0f89645a

add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
author Sam <sam@basx.dev>
date Fri, 05 May 2023 23:45:50 +0700
parents c774b064def5
children 8f2eaf0d2808
comparison
equal deleted inserted replaced
649:c774b064def5 650:be6e0f89645a
115 attr[Vec3f]("color", memoryPerformanceHint=PreferFastWrite), 115 attr[Vec3f]("color", memoryPerformanceHint=PreferFastWrite),
116 attr[Vec3f]("translate", perInstance=true) 116 attr[Vec3f]("translate", perInstance=true)
117 ] 117 ]
118 vertexOutput = @[attr[Vec3f]("outcolor")] 118 vertexOutput = @[attr[Vec3f]("outcolor")]
119 uniforms = @[attr[float32]("time")] 119 uniforms = @[attr[float32]("time")]
120 # samplers = @[attr[Sampler2DType]("my_little_texture")]
120 fragOutput = @[attr[Vec4f]("color")] 121 fragOutput = @[attr[Vec4f]("color")]
121 vertexCode = compileGlslShader( 122 vertexCode = compileGlslShader(
122 stage=VK_SHADER_STAGE_VERTEX_BIT, 123 stage=VK_SHADER_STAGE_VERTEX_BIT,
123 inputs=vertexInput, 124 inputs=vertexInput,
124 uniforms=uniforms, 125 uniforms=uniforms,
126 # samplers=samplers,
125 outputs=vertexOutput, 127 outputs=vertexOutput,
126 main="""gl_Position = vec4(position + translate, 1.0); outcolor = color;""" 128 main="""gl_Position = vec4(position + translate, 1.0); outcolor = color;"""
127 ) 129 )
128 fragmentCode = compileGlslShader( 130 fragmentCode = compileGlslShader(
129 stage=VK_SHADER_STAGE_FRAGMENT_BIT, 131 stage=VK_SHADER_STAGE_FRAGMENT_BIT,
130 inputs=vertexOutput, 132 inputs=vertexOutput,
131 uniforms=uniforms, 133 uniforms=uniforms,
134 # samplers=samplers,
132 outputs=fragOutput, 135 outputs=fragOutput,
133 main="color = vec4(outcolor, 0.8);" 136 # main="color = texture(my_little_texture, outcolor.xy) * 0.5 + vec4(outcolor, 1) * 0.5;"
137 main="color = vec4(outcolor, 1) * 0.5;"
134 ) 138 )
135 var renderPass = engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode) 139 var renderPass = engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)
136 engine.setRenderer(renderPass) 140 engine.setRenderer(renderPass)
137 141
138 # INIT SCENES 142 # INIT SCENES
139 var scenes = [scene_simple(), scene_different_mesh_types(), scene_primitives()] 143 var scenes = [
140 var time = initShaderGlobal("time", 0.0'f32) 144 newScene("simple", scene_simple()),
145 newScene("different mesh types", scene_different_mesh_types()),
146 newScene("primitives", scene_primitives())
147 ]
141 for scene in scenes.mitems: 148 for scene in scenes.mitems:
142 scene.components.add time 149 scene.addShaderGlobal("time", 0.0'f32)
143 engine.addScene(scene, vertexInput) 150 engine.addScene(scene, vertexInput)
144 151
145 # MAINLOOP 152 # MAINLOOP
146 echo "Setup successfull, start rendering" 153 echo "Setup successfull, start rendering"
147 for i in 0 ..< 3: 154 for i in 0 ..< 3:
148 for scene in scenes: 155 for scene in scenes.mitems:
149 for i in 0 ..< 1000: 156 for i in 0 ..< 1000:
150 if engine.updateInputs() != Running or engine.keyIsDown(Escape): 157 if engine.updateInputs() != Running or engine.keyIsDown(Escape):
151 engine.destroy() 158 engine.destroy()
152 return 159 return
153 setValue[float32](time.value, get[float32](time.value) + 0.0005) 160 var time = scene.getShaderGlobal("time")
161 setValue[float32](time, get[float32](time) + 0.0005)
154 engine.renderScene(scene) 162 engine.renderScene(scene)
155 echo "Rendered ", engine.framesRendered, " frames" 163 echo "Rendered ", engine.framesRendered, " frames"
156 echo "Processed ", engine.eventsProcessed, " events" 164 echo "Processed ", engine.eventsProcessed, " events"
157 165
158 # cleanup 166 # cleanup