Posts

Showing posts with the label shader

Which texel value is returned during Point sampling of the texture when more than one texels are at the equal distance?

Image
Which texel value is returned during Point sampling of the texture when more than one texels are at the equal distance? Which texel value is returned by the sampler during Point/Nearest neighbor sampling when more than one texels are at the equal distance? Eg: In this case (after magnification) where for many pixels (or texture coordinates), 2 texels are at the same distance from its center. Which texel will be returned for the sampling of these pixels. black dots = center of the pixel yellow dots = center of the texel 1 Answer 1 From the OpenGL Wiki: If GL_NEAREST is used, then the implementation will select the texel nearest the texture coordinate So ultimately, the graphics card vendor decides what they consider the nearest texel. A possible formula multiplies the texture coordinates by the image width / image height and rounds it down to get the texel index. (i, j) = floor(uv * (width, height)),...

Writing 0-Alpha in Metal shader doesn't render correctly

Writing 0-Alpha in Metal shader doesn't render correctly I'm trying to Chroma-Key an mp4 video playing over a UIView. I'm getting a texture every frame like so: var fullTex:CVMetalTexture? let w = CVPixelBufferGetWidthOfPlane(pixelBuffer, 0); let h = CVPixelBufferGetHeightOfPlane(pixelBuffer, 0); CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, videoTextureCache!, pixelBuffer, nil, MTLPixelFormat.bgra8Unorm, w, h, 0, &fullTex) let fullTexture:MTLTexture? = CVMetalTextureGetTexture(fullTex!) Passing it to my shader like this: let commandBuffer = commandQueue.makeCommandBuffer()! let commandEncoder = commandBuffer.makeComputeCommandEncoder()! commandEncoder.setCom...