metal

Passing values between SCNShadable entry points

两盒软妹~` 提交于 2020-06-25 18:04:27
问题 In an OpenGL program you typical declare something like this in a vertex shader varying bool aBooleanVariable; and then read the value in the fragment shader. How do you do this within the framework of an SCNShadable entry point? For example from SCNShaderModifierEntryPointGeometry to SCNShaderModifierEntryPointFragment . Receiving the argument seems to be defined by using the pragma arguments, I provide my test SCNShaderModifierEntryPointFragment to illustrate. #pragma arguments bool

iOS/Metal: how to read from the depth buffer at a point?

允我心安 提交于 2020-06-24 16:47:06
问题 I'd like to read from the depth buffer. In GL on OS X I could do: float depth[2][2]; // get 2x2 for bilinear interpolation glReadPixels(s.x, s.y, /*width*/2, /*height*/2, GL_DEPTH_COMPONENT, GL_FLOAT, depth); (Note that with OpenGL ES on iOS you can't read from the depth buffer) What's the equivalent with Metal? It looks like I need to do: _renderPassDescriptor.depthAttachment.storeAction = MTLStoreActionStore; And then somehow read from the buffer via the CPU? Though perhaps there's a better

Why is writing to a buffer from within a fragment shader disallowed in Metal?

社会主义新天地 提交于 2020-06-24 07:04:10
问题 As stated in the Metal Shading Language Guide: Writes to a buffer or a texture are disallowed from a fragment function. I understand that this is the case, but I'm curious as to why. Being able to write to a buffer from within a fragment shader is incredibly useful ; I understand that it is likely more complex on the hardware end to not know ahead of time the end location of memory writes for a particular thread, which you don't always know with raw buffer writes, but this is a capability

How do I keep the title bar from causing rendering issues in Metal?

自古美人都是妖i 提交于 2020-06-22 12:34:06
问题 The bounty expires in 3 days . Answers to this question are eligible for a +100 reputation bounty. AwesomeElephant8232 is looking for a more detailed answer to this question: Thanks, 0xBFE1A8, for your answer, but I have no idea how to create a custom metal view in a swift application, and render it on a background thread. There is also the problem with the white flicker. You only 1/4 solved my problem, so I am offering an additional 100 point bounty to solve the problem once and for all.

How do I correctly render a texture in a quad in Metal?

牧云@^-^@ 提交于 2020-06-17 01:58:26
问题 My issue is because a quad is just two triangles. The texture is not rendered consistently on each triangle, and the texture is broken across the border between the two triangles. I'm using a screenshot of my lovely Minecraft house as an example texture: Rendered textured quad As you see, from the top left of the screenshot and the bottom right, it seem to have been cut or folded or something. It's just distorted. And the distortion I speak of is NOT from the fact that it's being applied to a

Metal: linear texture filtering not working as expected

家住魔仙堡 提交于 2020-05-25 03:09:27
问题 I'm using Metal on iOS with the following fragment shader: constexpr sampler s(coord::normalized, address::clamp_to_zero, filter::linear); fragment half4 passThroughFragment(VertexInOut inFrag [[stage_in]], texture2d<float> tex [[ texture(0) ]]) { return half4(tex.sample(s, inFrag.uv)); } My texture is a 4x4 image. Despite the filtering set to linear, I get the following image, with nearest neighbor filtering: It seems that my uv's are fine, since when I modify the fragment shader as follows:

Metal rendering odd darker textures even with [MTKTextureLoader.Option.SRGB : false]?

。_饼干妹妹 提交于 2020-05-24 06:10:49
问题 I already checked this question. Using [MTKTextureLoader.Option.SRGB : false] in texture loader options doesn't work. All that happens is when I do [MTKTextureLoader.Option.SRGB : true] , it's a lot darker instead of slightly darker. There must be something else. Here is an example of this unwanted behavior. Here is the original texture for reference: As you can see I am using the mouse to hold the original packed ice texture over the rendered one. It's considerably lighter, even with

Can I use multiple MTLRenderPipelineStates in one MTLRenderCommandEncoder?

倖福魔咒の 提交于 2020-05-13 08:17:44
问题 I'm currently making simple UI for a game, and to draw each of the buttons I need to use 2 pipeline states (same vertex shader for each). One to draw a line strip for the border, with a static color fragment shader, and one to draw the inside of the button with a rippling gradient. I'm wondering if I need two different render command encoders, one per pipeline, or if I can do the following: let encoder = command.makeRenderCommandEncoder(descriptor: renderPassDesc) encoder

Can I use multiple MTLRenderPipelineStates in one MTLRenderCommandEncoder?

ぃ、小莉子 提交于 2020-05-13 08:17:32
问题 I'm currently making simple UI for a game, and to draw each of the buttons I need to use 2 pipeline states (same vertex shader for each). One to draw a line strip for the border, with a static color fragment shader, and one to draw the inside of the button with a rippling gradient. I'm wondering if I need two different render command encoders, one per pipeline, or if I can do the following: let encoder = command.makeRenderCommandEncoder(descriptor: renderPassDesc) encoder

Metal Texture is darker than original image

有些话、适合烂在心里 提交于 2020-05-13 07:58:25
问题 I am writing some code for a little program in macOS to play with image processing with Metal Performance Shaders. For some reason, the code below produces an image that looks significantly darker than the original. The code simply takes a texture, performs a little guassian blur on it, and then outputs the image to the MTKView. I cannot figure out why the resulting image is so dark, though. import Cocoa import Metal import MetalKit import CoreGraphics import MetalPerformanceShaders class