Skip to content

Commit

Permalink
fix depth calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
yukiny0811 committed Feb 2, 2024
1 parent fbc09d6 commit bb6175a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Examples/ExampleVisionOS/ExampleVisionOS/SampleSketch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ final class SampleSketch: Sketch {

override func draw(encoder: SCEncoder) {
setFog(color: f4.one, density: 0.02)
color(0.8, 0.1, 0.5, 0.8)
for z in -count...count {
for y in -count...count {
for x in -count...count {
if x == 0 && y == 0 && z == 0 {
continue
}
let r = Float(x + count) / Float(count * 2)
let g = Float(y + count) / Float(count * 2)
let b = Float(z + count) / Float(count * 2)
color(r, g, b, 0.8)
box(Float(x) * 15, Float(y) * 15, Float(z) * 15, 1, 1, 1)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class NormalBlendRendererVision: RendererBase {
renderPipelineDescriptor.vertexDescriptor = vertexDescriptor

renderPipelineState = try! ShaderCore.device.makeRenderPipelineState(descriptor: renderPipelineDescriptor)
let depthStencilDescriptor = Self.createDepthStencilDescriptor(compareFunc: .less, writeDepth: true)
let depthStencilDescriptor = Self.createDepthStencilDescriptor(compareFunc: .greater, writeDepth: true)
self.depthStencilState = ShaderCore.device.makeDepthStencilState(descriptor: depthStencilDescriptor)!

super.init(drawProcess: sketch)
Expand Down Expand Up @@ -106,10 +106,14 @@ public class NormalBlendRendererVision: RendererBase {

let renderPassDescriptor = MTLRenderPassDescriptor()
renderPassDescriptor.colorAttachments[0].texture = drawable.colorTextures[0]
renderPassDescriptor.depthAttachment.texture = drawable.depthTextures[0]
renderPassDescriptor.colorAttachments[0].loadAction = .clear
renderPassDescriptor.colorAttachments[0].storeAction = .store
renderPassDescriptor.colorAttachments[0].clearColor = .init(red: 0, green: 0, blue: 0, alpha: 0)
renderPassDescriptor.depthAttachment.texture = drawable.depthTextures[0]
renderPassDescriptor.depthAttachment.loadAction = .clear
renderPassDescriptor.depthAttachment.storeAction = .store
renderPassDescriptor.depthAttachment.clearDepth = 0.0
renderPassDescriptor.rasterizationRateMap = drawable.rasterizationRateMaps.first
let renderCommandEncoder = commandBuffer?.makeRenderCommandEncoder(descriptor: renderPassDescriptor)

Self.setDefaultBuffers(encoder: renderCommandEncoder!)
Expand Down

0 comments on commit bb6175a

Please sign in to comment.