changeset 267:a107d9ef1a1f

add: flat attribute for shader in/outputs
author Sam <sam@basx.dev>
date Sun, 28 May 2023 18:09:20 +0700
parents fd1a95f433d1
children d16fd73959c1
files src/semicongine/core/gpu_data.nim src/semicongine/resources/mesh.nim
diffstat 2 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/semicongine/core/gpu_data.nim	Sun May 28 17:52:03 2023 +0700
+++ b/src/semicongine/core/gpu_data.nim	Sun May 28 18:09:20 2023 +0700
@@ -150,6 +150,7 @@
     thetype*: DataType
     arrayCount*: uint32
     perInstance*: bool
+    noInterpolation: bool
     memoryPerformanceHint*: MemoryPerformanceHint
 
 func vertexInputs*(attributes: seq[ShaderAttribute]): seq[ShaderAttribute] =
@@ -292,6 +293,7 @@
   name: string,
   perInstance=false,
   arrayCount=0'u32,
+  noInterpolation=false,
   memoryPerformanceHint=PreferFastRead,
 ): auto =
   ShaderAttribute(
@@ -299,6 +301,7 @@
     thetype: getDataType[T](),
     perInstance: perInstance,
     arrayCount: arrayCount,
+    noInterpolation: noInterpolation,
     memoryPerformanceHint: memoryPerformanceHint,
   )
 
@@ -1059,7 +1062,8 @@
   var i = 0'u32
   for attribute in group:
     assert attribute.arrayCount == 0, "arrays not supported for shader vertex attributes"
-    result.add &"layout(location = {i}) in {attribute.thetype.glslType} {attribute.name};"
+    let flat = if attribute.noInterpolation: "flat " else: ""
+    result.add &"layout(location = {i}) {flat}in {attribute.thetype.glslType} {attribute.name};"
     for j in 0 ..< attribute.thetype.numberOfVertexInputAttributeDescriptors:
       i += attribute.thetype.nLocationSlots
 
@@ -1092,5 +1096,6 @@
   var i = 0'u32
   for attribute in group:
     assert attribute.arrayCount == 0, "arrays not supported for outputs"
-    result.add &"layout(location = {i}) out {attribute.thetype.glslType} {attribute.name};"
+    let flat = if attribute.noInterpolation: "flat " else: ""
+    result.add &"layout(location = {i}) {flat}out {attribute.thetype.glslType} {attribute.name};"
     i += 1
--- a/src/semicongine/resources/mesh.nim	Sun May 28 17:52:03 2023 +0700
+++ b/src/semicongine/resources/mesh.nim	Sun May 28 18:09:20 2023 +0700
@@ -12,7 +12,13 @@
 
 import ./image
 
-let DEFAULTEXTURE = Texture(image: newImage(1, 1, @[[255'u8, 255'u8, 255'u8, 255'u8]]), sampler: DefaultSampler())
+let DEFAULTSAMPLER = Sampler(
+    magnification: VK_FILTER_NEAREST,
+    minification: VK_FILTER_NEAREST,
+    wrapModeS: VK_SAMPLER_ADDRESS_MODE_REPEAT,
+    wrapModeT: VK_SAMPLER_ADDRESS_MODE_REPEAT,
+  )
+let DEFAULTEXTURE = Texture(image: newImage(1, 1, @[[255'u8, 255'u8, 255'u8, 255'u8]]), sampler: DEFAULTSAMPLER)
 
 type
   glTFHeader = object