Tag: 金属

用平移手势上下左右旋转相机

我想使用opengl lookat函数向上或向下,向左或向右旋转摄像头(360度视图),使用opengl lookat函数,我使用swift和Metal(在本例中为Metal = opengl es)。 这里是代码: lookat函数(这个函数在另一个ViewController中,它是inheritance了ViewController的主要ViewController和pan手势函数): let viewMatrix = lookAt(location, center: ktarget, up: up) viewDidLoad和var: var ktarget = V3f() var up = V3f() let location =V3f() override func viewDidLoad() { super.viewDidLoad() location = V3f(0.0, 0.0, -2.0) ktarget = V3f(0.0, 0.0, 0.0) up = V3f(0.0, 1.0, 0.0) } 平底锅手势: func pan(panGesture: UIPanGestureRecognizer){ up = […]

使用MTKTextureLoader加载远程图像

我试图用这个代码加载一个远程图像到一个MTLTexture, let textureLoader = MTKTextureLoader(device: device) textureLoader.newTexture(withContentsOf: url, options: options) { [weak self] (texture, error) in if let t = texture { completion(t) } else { if let desc = error?.localizedDescription { NSLog(desc) } completion(nil) } } 如果URL来自Bundle资源,那么它就起作用,例如 let url = Bundle.main.url(forResource: name, withExtension: ext) 但是,如果我通过这样的事情,它会失败, let url = URL(string: "http://example.com/images/bla_bla.jpg") 有了这个错误, Could not find […]

以video捕捉SkeneKit场景

我正在使用SceneKit与金属(不是OpenGL),并希望允许用户录制他玩游戏的video。 任何想法如何将场景渲染到video? (没有必要logging现场audio,这可能会使它更简单)

如何在顶点/片段着色器中使用3×3 2D变换(金属)

我有一个简单的任务,但显然我还是不明白在着色器中的投影是如何工作的。 我需要在纹理四边形(2个三angular形)上进行2D透视变换,但在视觉上它看起来不正确(例如,梯形比CPU版本中的梯形略高或更拉伸)。 我有这个结构: struct VertexInOut { float4 position [[position]]; float3 warp0; float3 warp1; float3 warp2; float3 warp3; }; 在顶点着色器中,我做了类似的事情( texCoords是四angular的像素坐标,单应texCoords是以像素坐标计算的): v.warp0 = texCoords[vid] * homographies[0]; 然后在像这样的片段着色器中: return intensity.sample(s, inFrag.warp0.xy / inFrag.warp0.z); 结果不是我所期望的。 我花了几个小时,但我无法弄清楚。 通风 更新: 这些是CPU的代码和结果(又名预期结果 ): // _image contains the original image cv::Matx33d h(1.03140473, 0.0778113901, 0.000169219566, 0.0342947133, 1.06025684, 0.000459250761, -0.0364957005, -38.3375587, 0.818259298); cv::Mat dest(_image.size(), […]

在金属着色语言中创build全局可访问的常量缓冲区

我有一个关于金属常量缓冲区的问题。 我们假设,我有这样的东西: …list of includes goes here… using namespace metal; struct ConstantBuffer { float ANY_VALUE; }; struct VS_INPUTS { float4 i_pos_ms [ [ attribute ( 0 ) ] ] ; } ; struct V2P_STRUCT { float4 v_pos_out [ [ position ] ] ; } ; float3 CalcSomething() { return float3(ANY_VALUE, ANY_VALUE, ANY_VALUE); // !!!!!!!! } […]

ios metal:限制着色器中使用的variables数量

添加一些复杂度到我的着色器后,我开始收到以下错误: Execution of the command buffer was aborted due to an error during execution. Discarded (victim of GPU error/recovery) (IOAF code 5) 我发现,它与实际添加的代码没有任何关系,但事实上我添加了更多的variables和函数调用。 我尝试从着色器中删除其他复杂性,并删除了错误。 另一件我发现的问题是,当我把快速的math设置为false时,问题也消除了。 我的第一个猜测是,当快速math运算时,variables的数量有一些限制。 有这样的限制吗? 任何其他想法为什么会出现这样的错误?

更新Metal中的MTLBuffer的内容

我需要帮助来replaceMTLBuffer的内容而不创build一个新的。 两种情况下的内容都是浮动数组。 let vector:[Float] = [0,1,2,3,4,5,6,7,8,9] let byteLength = arr1.count*MemoryLayout<Float>.size let buffer = metalDevice.makeBuffer(bytes: &vector, length: byteLength, options: MTLResourceOptions()) let vector2:[Float] = [10,20,30,40,50,60,70,80,90] 我明白buffer.contents()给了我们一个UnsafeMutableRawPointer 。 我想从vector2中创build一个新的UnsafeMutableRawPointer并replace缓冲区的内容。 提前致谢!

iOS 8.3 – 金属,find零,同时展开一个可选值

在苹果发布iOS 8.3之前,我的代码工作,但是因为更新XCode抱怨find一个零值,即使我的值都没有零(我在debugging时validation了这一点)。 为了理智,我重新写了我的程序来渲染一个简单的三angular形与金属屏幕,但同样的错误抛出。 我有一个3顶点的数组,然后乘以数组的大小,以获得缓冲区的大小,并通过OptionCPUCacheModeDefault传递一个nil参数可能是导致我的问题。 // Test array of vertices let ASVertices:[Float] = [ 0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0 ] // Other Metal init code… // Set the buffers let dataSize = ASVertices.count * sizeofValue(ASVertices[0]) vertexBuffer = ASDevice.newBufferWithBytes(ASVertices, length: dataSize, options: MTLResourceOptions.OptionCPUCacheModeDefault) 当我debugging,我可以看到dataSize是36(9 * 4)预期,所以我相当难dataSize ,为什么我fatal error when unwrapping an optional value时,得到一个fatal […]

使用MTKView显示JPEG图像

有没有办法通过MTKView和MTLBuffer(和iPhone 6 +内)显示JPEG图像。 我已经尝试了以下方式(这只是testing): – (id<MTLBuffer>)testBuffer { if (!_testBuffer) { // NSString *path = [[NSBundle mainBundle] pathForResource:@"testImage" ofType:@"jpg"]; NSData *imageData = [NSData dataWithContentsOfFile:path]; _testBuffer = [self.device newBufferWithBytes:imageData.bytes length:imageData.length options:MTLResourceCPUCacheModeWriteCombined]; } return _testBuffer; } – (void)drawInMTKView:(MTKView *)view { MTLRenderPassDescriptor* renderPassDescriptor = view.currentRenderPassDescriptor; id <MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer]; id <MTLRenderCommandEncoder> renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; [renderEncoder drawPrimitives:MTLPrimitiveTypePoint […]

金属离屏绘图与多采样

如何将原始图像渲染到屏幕外的纹理,而不是直接进入屏幕? 我有一套三angular形和相应的颜色,我只是想画他们一样的方式,我屏幕,但进入屏幕外的纹理,我可以保存到一个文件。 任何人都可以给我看一个代码示例吗?