metal

Metal vertex shader draw points of a Texture

牧云@^-^@ 提交于 2019-12-24 11:01:30
问题 I want to execute Metal (or OpenGLES 3.0) shader that draws Points primitive with blending. To do that, I need to pass all the pixel coordinates of the texture to Vertex shader as vertices which computes the position of the vertex to be passed to fragment shader. The fragment shader simply outputs the color for the point with blending enabled. My problem is if there is an efficient was to pass coordinates of vertices to the vertex shader, since there would be too many vertices for 1920x1080

Metal - Namespace variable that is local to a thread?

与世无争的帅哥 提交于 2019-12-24 10:16:30
问题 I'm trying to create a Pseudo Random Number Generator (PRNG) in Metal, akin to thrust 's RNG , where every time you call the RNG within a thread it produces a different random number given a particular seed, which in this case, will be the thread_position_in_grid . I have it set up perfectly, and I get a nice uniformly random picture right now using the code I have. However, my code only works once per thread. I want to implement a next_rng() function that returns a new rng using the last

Just make a Metal frag shader a transparent color?

社会主义新天地 提交于 2019-12-24 03:34:28
问题 I have a simple pipeline descriptor let p = MTLRenderPipelineDescriptor() ... p.colorAttachments[0].pixelFormat = .bgra8Unorm The background is plain blue let bg = MTLClearColor(red: 0, green: 0, blue: 1, alpha: 1) let pass = MTLRenderPassDescriptor() pass.colorAttachments[0].loadAction = .clear pass.colorAttachments[0].clearColor = bg I simply draw a poly on to it, say a red one: fragment half4 fattie_fragment() { return half4(1,0,0, 1); } Or green ... fragment half4 fattie_fragment() {

Fill Path in Metal

﹥>﹥吖頭↗ 提交于 2019-12-24 03:23:42
问题 I creating a drawing Application in Metal. I need to create a Fill path using the users touchpoints. What algorithm can we used to achieve that effect in Metal. Here's an example image showing what I'm trying to do: 来源: https://stackoverflow.com/questions/54859460/fill-path-in-metal

iOS Metal. Why does simply changing colorPixelFormat result in brighter imagery?

人盡茶涼 提交于 2019-12-24 00:48:43
问题 In Metal on iOS the default colorPixelFormat is bgra8Unorm . When I change format to rgba16Float all imagery brightens. Why? An example: Artwork MTKView with format bgra8Unorm . Texture-mapped quad. Texture created with SRGB=false . MTKView with format rgba16Float . Texture-mapped quad. Texture created with SRGB=false . Why is everything brighter with rgba16Float . My understanding is that SRGB=false implies that no gamma correction is done when importing artwork. The assumption is the

MacOS MTKView metal self.device.newBufferWithBytes crashes with assert

别等时光非礼了梦想. 提交于 2019-12-23 22:14:28
问题 I want to draw a simple triangle and it crashes after I am trying to create MTLBuffer . static float vertexes[] = { 0.0, 0.5, 0.0, -0.5f, -0.5f, 0.0, 0.5, -0.5f, 0.0 }; id <MTLBuffer> buffer = [self.device newBufferWithBytes:vertexes length:sizeof(vertexes) options:MTLResourceStorageModePrivate]; Here is the assert: -[MTLDebugDevice newBufferWithBytes:length:options:]:392: failed assertion `storageModePrivate incompatible with ...WithBytes variant of newBuffer' So how to create a buffer from

ios metal: limit on number of variables used in a shader

牧云@^-^@ 提交于 2019-12-23 18:10:30
问题 I started receiving the following error today after adding some complexity to my shader: Execution of the command buffer was aborted due to an error during execution. Discarded (victim of GPU error/recovery) (IOAF code 5) What i discovered is that it has nothing to do with the actual added code but with fact i added more variables and function calls. I tried removing other complexities from the shader and the error was removed. Another thing i discovered is that problem also removed when i

How many times is the vertex shader called with metal?

泄露秘密 提交于 2019-12-23 10:39:12
问题 I've been learning some basic metal rendering, and I am stuck with some basic concepts: I know we can send vertex data to a shader using: renderEncoder.setVertexBuffer(vertexBuffer, offset: 0, index: 0) And then we can retrieve it in the shader with: vertex float4 basic_vertex(const device VertexIn* vertexIn [[ buffer(0) ]], unsigned int vid [[ vertex_id ]]) As I understand it, the vertex function will be called once per each vertex, and vertex_id will update on each call to contain the

How many times is the vertex shader called with metal?

跟風遠走 提交于 2019-12-23 10:38:20
问题 I've been learning some basic metal rendering, and I am stuck with some basic concepts: I know we can send vertex data to a shader using: renderEncoder.setVertexBuffer(vertexBuffer, offset: 0, index: 0) And then we can retrieve it in the shader with: vertex float4 basic_vertex(const device VertexIn* vertexIn [[ buffer(0) ]], unsigned int vid [[ vertex_id ]]) As I understand it, the vertex function will be called once per each vertex, and vertex_id will update on each call to contain the

Metal off-screen drawing with Multi-Sampling

孤者浪人 提交于 2019-12-23 09:58:24
问题 How do I render primitives into off screen texture, not directly into the screen? I have a set of triangles and corresponding color, I just want to draw them the same way I do to screen, but into off screen texture, that I can save into a file. Can anybody show me a code sample of that? 回答1: Ok, I realized it myself. This code does the job, with only exception that it draw too huge triangles, but that is a different topic for Vertex function. Here is my code: let fragmentProgram =