Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
35 views

Handling multiple render targets of differing sizes in Metal

I would like to use a fragment shader with multiple render targets to output YCbCr data from RGB input, where the Y data is written to one texture and the CbCr to another, smaller texture (due to ...
tenuki's user avatar
  • 370
0 votes
0 answers
62 views

Finding x/y screen position of a Metal fragment shader modifier for custom ARKit/SceneKit occlusion

I have a simple ARKit/SceneKit app that draws a cube in front of the camera. Using the depth map, I want to hide the cube pixels that are occluded by an object. RealityKit supports occlusion, but ...
Steve Potter's user avatar
  • 1,919
0 votes
0 answers
108 views

Metal: Blending issues when rendering to a custom render texture

Goal: Render solid color quads with 0.5 alpha to my own transparent render target texture, then map the texture to a quad and render it to the screen. The texture should blend correctly (normal blend ...
Brian Spilner's user avatar
0 votes
0 answers
43 views

Issues with Vertical Stretching and Horizontal Movement in Metal Shading Language Ray Tracing Shader

I'm currently learning Metal Shading Language and have been experimenting with a custom shader for ray tracing. The shader compiles and runs without errors, but I've encountered two issues that seem ...
Arthur TL's user avatar
1 vote
1 answer
379 views

Fragment shader mixes uv coordinates

I try to understand how shaders work, just first steps. With some tutorials I made a view, vertex shader and fragment shader. Wow. It works. But when I started to play with it, I found something ...
Łukasz's user avatar
  • 805
0 votes
1 answer
154 views

Is it possible to fill in Stencil Buffer programmatically via fragment shader in Metal?

Do stencil buffer can only be filled in by some hard-coded rules during geometry drawing (like depth buffer), or is it possible to fill it in completely programmatically with the help of full-screen ...
simd's user avatar
  • 2,019
1 vote
1 answer
176 views

Render into 2 offscreen textures at once in Metal fragment shader

Metal fragment shader render into its render target by explicitly returning float4 value. Does it mean that fragment shader can only render in one texture at once? I'd like to render into 2 textures ...
simd's user avatar
  • 2,019
0 votes
1 answer
82 views

iOS Metal: Why does this seemingly unrelated shader code change cause anti-aliasing to break?

I'm new to Metal and my OpenGL experience is probably around a decade old at this point. I'm wondering if someone can help me figure out why a seemingly unrelated shader change cause the aliasing to ...
Iain Stanford's user avatar
0 votes
0 answers
140 views

Metal Alpha Blending to create smooth line

I am trying to implement the method of drawing a smooth line through a large number of 3D points shown here --> https://ahmetkermen.com/simple-smooth-line-drawing-with-opengl. I have a small quad ...
PhilBot's user avatar
  • 30
1 vote
1 answer
94 views

Is there a way read constant value from fragment shader in cpu side?

I am studying with raywenderlich metal by tutorials book. there is an example in the book about selection object. I am new in Metal and I am sorry about my English. typedef struct { uint width; ...
Mehmet Deran's user avatar
0 votes
1 answer
70 views

why xcode frame capture's fs invocations number aren't corrent?

I write an example that using offline render. using frame capture i can get fs invocations number of this offline render, but it is strange that the number is the result of multiplication of render ...
Bowen Zhen's user avatar
4 votes
1 answer
380 views

Is there a way to bind assets once instead of with every command encoder?

I'm rendering a vertex/frag shader with a compute kernel. Every frame I am binding large assets (such as a 450MB texture) in the usual way: computeEncoder.setTexture(highResTexture, index: 0) ...
Jeshua Lacock's user avatar
0 votes
2 answers
191 views

Normalized uv for shaderModifiers .fragment attached to SCNGeometry (SCNPlane)

seems quite difficult for me to get this info so I will ask here directly. Q: How do I get the correct normalized UV when dealing with shaderModifiers .fragment attached to a geometry in a SCNNode? ...
czane's user avatar
  • 422
0 votes
0 answers
184 views

MetalKit - How to fade pixels within a single render pass

I have a Metal based rendering pipeline that renders a few overlapping squares. It loops over all the squares and draws them to the screen starting from the one furthest to the back and ending with ...
iosdev55's user avatar
  • 129
2 votes
0 answers
649 views

Translating an OpenGL ES 2.0 shader code to Metal (for ARKit scene)

In the past, we had code written in the OpenGL ES 2.0 shader language we used in the Scenekit class. But OpenGL is no longer available for ARkit it's deprecated. Therefore, we have to rewrite these ...
Oktay Kurt's user avatar
1 vote
1 answer
693 views

iOS Metal - can I used reduced precision half values for vertex position and color?

I'm trying to experiment with saving memory when rendering a point cloud in Metal. I saw a tutorial which advised using half types (probably on Mac). I would like to try returning half for the vertex ...
Alex Stone's user avatar
  • 47.3k
-1 votes
1 answer
131 views

METAL - Fragment shader is producing noise

I am trying to use basic lighting techniques described in Metal By Tutorials to produce a diffuse, ambient, and specular light on my models. I have used this lighting algorithm plenty of times and it ...
Jamie2020's user avatar
1 vote
1 answer
1k views

Metal fragment shader - How do I assign each pixel a color based on the uniforms that I can adjust via the draw function?

I have a MTKView that is rendering a cube that is sized so that one of its faces fills the entire screen. I am passing a struct variable (called theuniforms) that contains a random Float to the ...
Jamie2020's user avatar
2 votes
3 answers
763 views

How do you get Xcode to use syntax editing and code completion on Metal Shader Modifiers?

Beginning my adventure down the path of learning all about both Metal and shaders. Currently I'm using this example from here to experiment with. As you can see, he's storing his shader in a separate ...
Mark A. Donohoe's user avatar
1 vote
1 answer
823 views

IOS Metal Fragment shader file compilation

I have fragment shader "fsh" file and I am trying to compile it, it is originally taken from Shadertoy, and it is in GLSL, I am trying to port it to METAL, and I am getting the following error: ...
Burak Ozdemir's user avatar
2 votes
1 answer
1k views

Modify Metal fragment shading based on vertex world position Y coordinate

I am trying to use a Metal fragment shader with SCNTechnique to modify the fragment color based on the vertex Y world position. My understanding so far SCNTechnique can be configured with a sequence ...
CloakedEddy's user avatar
  • 1,985
0 votes
1 answer
449 views

Creating texture in Vertex shader and passing to Fragment to achieve smudging brush with Metal?

I am trying to add a smudge effect to my paint brush project. To achieve that, I think I need to sample the the current results (which is in paintedTexture) from the start of the brush stroke ...
Jeshua Lacock's user avatar
0 votes
0 answers
239 views

How do I draw a packed 16-bit pixel format texture with metal?

I am new to metal and I managed to draw simple 32-bit rgba textures, but I cannot find any example on how to draw a 16-bit one (5_5_5_1 bgra, 5_6_5 bgr or 4_4_4_4 bgra). I think the creation of the ...
Radu Iulian's user avatar
1 vote
0 answers
94 views

What's the most efficient way to write a video shader that uses many previous input frames?

I'm writing a video effect in iOS using Metal that requires pixel data of the current frame as well as many previous frames of the original input video. Is there a common pattern or best practice for ...
Ian Pearce's user avatar
0 votes
0 answers
271 views

Why does Metal slow down when the number of fragment shader arguments increases?

I have a very basic fragment shader that accepts an array of array textures defined like so: fragment float4 shader(RasterizerData in [[ stage_in ]], sampler sampler2d [[ ...
kennyc's user avatar
  • 5,660
8 votes
1 answer
5k views

Passing a float or color into a Metal fragment shader from Swift

I'm trying to write a fragment shader in Metal but can't get my head around how to pass in single values (e.g. float, float4 or half4). My shaders are as follows: #include <metal_stdlib> using ...
Doug's user avatar
  • 3,170
1 vote
1 answer
1k views

Implementing toon effect with Metal shader and SceneKit

I would like to improve my recent question and implement toon effect like this using Metal (fragment) shader in SceneKit. Here is my fragment shader implementing both simple phong lighting and toon ...
Martin Pilch's user avatar
  • 3,295
1 vote
1 answer
2k views

How Do I Enable MSAA for a Render to Texture iOS App

I have a working render to texture toy iOS app. The issue is it has a ton of jaggies because it is point sampled and not anti-aliasied: I increased the sample count in my MTKView subclass to 4 to ...
dugla's user avatar
  • 12.9k
1 vote
0 answers
1k views

Mixing Two Textures in Metal Shader

I have two transparent textures. First one is Source texture, Second one is Mask Texture. I want to mix two textures. Scenario 1 source texture having color and Alpha Mask Texture Having color and ...
Ruban4Axis's user avatar
4 votes
1 answer
3k views

Metal shader in SceneKit to outline an object

I'm playing around and trying to implement Metal shader in SceneKit that will outline an object. The idea is to draw an outline (or silhouette) similar to this image found in this blogpost (the ...
Martin Pilch's user avatar
  • 3,295
2 votes
1 answer
792 views

How to pass a variable number of MTLTextures to a fragment shader?

What is the correct syntax for passing a variable number of MTLTexture's as an array to a fragment shader? This StackOverflow Question: "How to use texture2d_array array in metal?" mentions the use ...
kennyc's user avatar
  • 5,660
1 vote
1 answer
674 views

Metal fragment shader -- are the color values already quantized to 8 bits?

I'm trying to implement some simple dithering in my Metal fragment shader, to get rid of banding across gradients. It is not working, and I am wondering if it is just a bug or if the color values ...
bsabiston's user avatar
  • 741
1 vote
0 answers
52 views

Is there a glColorMask equivalent in SceneKit?

Is there a way to only write certain components of the color into the image buffer in SceneKit like with glColorMask in OpenGL? I tried the SCNMaterial's property .colorBufferWriteMask, but no luck.
user973224's user avatar
6 votes
0 answers
717 views

How to change MTKView current drawable size

Apple documentation says the MTKView current drawable default size is derived from the current view’s size, in native pixels. Is there any way to make MTKView current drawable half of the device's ...
Kasun Palihakkara's user avatar
2 votes
2 answers
3k views

Getting error message "[CAMetalLayerDrawable texture] should not be called after already presenting this drawable. Get a nextDrawable instead."

I just need to render multiple objects simultaneously. But I am getting an error as mention. Here I am passing multiple objects to my render func. var sceneObject:Array<Node> = [objectToDraw,...
Kasun Palihakkara's user avatar
1 vote
1 answer
1k views

MTLTexture from MTLBuffer issue

I have results of compute shader stored in MTLBuffer. Each element of MTLBuffer is a UInt16. I am trying to pass the results to a fragment shader that displays the result by interpreting the elements ...
Deepak Sharma's user avatar
0 votes
1 answer
532 views

Metal shader interpolate values in buffer

I need to pass a buffer to Metal fragment shader which is an array of N float values. But I want the shader to interpolate values if the width of the texture to which it is drawn is more than N pixels....
Deepak Sharma's user avatar
1 vote
0 answers
1k views

Metal shader 3D texture lookup

I created a 3D texture from a LUT file on iOS as follows: let dim = 33 let textureDescriptor = MTLTextureDescriptor() textureDescriptor.textureType = .type3D textureDescriptor....
Deepak Sharma's user avatar
1 vote
0 answers
81 views

Metal fragment shader bound resource acting erratically on macOS

This problem has been stumping me, and I can't figure it out. I've got a few different shaders which use the same resource, a structure with a bunch of lighting values. The first shader to use it ...
bsabiston's user avatar
  • 741
1 vote
0 answers
376 views

Metal shaders: converting non-position fragment shader arguments to windows/pixel coords?

In my Metal app I need to do some distance comparisons between the fragment position and a baseline, which I pass in from the vertex shader. The fragment position comes to the fragment shader in ...
bsabiston's user avatar
  • 741
1 vote
2 answers
691 views

Shared variables in Fragment shaders in Metal or OpenGLES

This might be unlikely, but is there a concept of shared global variables that can be updated in each pass of fragment shaders in either Metal & OpenGLES? I want to update some statistics after ...
Deepak Sharma's user avatar
1 vote
0 answers
659 views

Random error noise in Metal fragment shader

my circle got distorted, bad. I'm writing a fragment shader to do some image transformation and I'm seeing some random error noise, not sure what's up. I'm merging two textures, one read with .read(...
Heestand XYZ's user avatar
  • 2,183
0 votes
0 answers
550 views

Metal [[early_fragment_tests]] on frag shader works on Mac OSX, but not iOS

With Metal, does it matter whether or not I have anything attached to the color targets in order to use early_fragment_tests on iOS? When I add early_fragment_tests to my frag shader, then it seems ...
bsabiston's user avatar
  • 741
1 vote
0 answers
858 views

How to rotate an image in a Metal Fragment Shader?

this is what I've tried: float ang = atan2(v - 0.5, u - 0.5) + (r / 360) * pi * 2; float amp = sqrt(pow(u - 0.5, 2) + pow(v - 0.5, 2)); float2 uv = float2(sin(ang) * amp, cos(ang) * amp) + 0.5; ...
Heestand XYZ's user avatar
  • 2,183
1 vote
1 answer
942 views

Metal fragment shader A-Buffer produces shimmering glitch

I'm implementing an A-Buffer in Metal for Mac, and it is almost working -- except that I am seeing shimmering glitches wherever triangles overlap. It seems like the buffers involved may not be ...
bsabiston's user avatar
  • 741
0 votes
0 answers
88 views

Metal fragment shader appears to write twice for a single triangle?

I'm trying to debug my Metal shader -- from using the GPU frame capture, I can see that the framebuffer values are twice what I would expect. For example, I am using the ADD blend operation, with ...
bsabiston's user avatar
  • 741
2 votes
1 answer
5k views

How to use texture2d_array array in metal?

I have been trying to use texture2d_array for my application of live filters in metal. But I'm not getting the proper result. Im creating the texture array like this, Code: Class MetalTextureArray. ...
Shreesha Kedlaya's user avatar
1 vote
1 answer
824 views

Not able to access a struct object properly inside fragment shader in Metal?

I have two sections in my question: First Section I have a requirement where I have to pass a structure containing 3 values of a color (RGB) varying from 0 - 1 but it turns out whatever values Im ...
Shreesha Kedlaya's user avatar
1 vote
1 answer
1k views

Metal Fragment Shader, access current framebuffer color

I am writing a metal shader. All I want is to access the current color of the fragment. For example. At the end of my fragment shader, when I put return currentColor + 0.1, for example The result ...
Ruan Sunkel's user avatar
0 votes
2 answers
585 views

Metal kernel shader -- fade implementation

I haven't written many Metal kernel shaders yet; here's a fledgling "fade" shader between two RGBX-32 images, using a tween value of 0.0 to 1.0 between inBuffer1 (0.0) to inBuffer2 (1.0). Is there ...
zzyzy's user avatar
  • 983