Posts

Post marked as solved
1 Replies
327 Views
Hello everyone, It's a nice holiday. I changed pixel value from uiimage, so produce other image. Code is this.    func normalize(_ image: UIImage) -> UIImage {     let width = 320     let height = 240     let bytesPerComponent = 4     let channel = 1     let imageSize = width * height * bytesPerComponent     guard Int(image.size.width) == width,        Int(image.size.height) == height,        image.cgImage?.bitsPerComponent == 8,        image.cgImage?.bitsPerPixel == 8     else { // setting include width, height type is uint8 and 1 channel       fatalError("\(#function) : you should fixed image setting")     }     let cgimage = image.cgImage     guard let originalData = cgimage?.dataProvider?.data,        let original = CFDataGetBytePtr(originalData)     else {       fatalError("\(#function) : get original buffer failed.")     }           imageData = UnsafeMutablePointer<Float32>.allocate(capacity: width * height)     guard let imageData = imageData else { fatalError("\(#function) : unknwon error") }     // 0 ~ 255 (uint8) -> -1.0 ~ 1.0 (float32)     let normValue: Float32 = 127.5     for w in 0..<width {       for h in 0..<height {         imageData[h * width + w] = (Float32(original[h * width + w]) - normValue) / normValue       }     }     guard let provider = CGDataProvider(data: Data(bytesNoCopy: imageData,                             count: imageSize,                             deallocator: .none) as CFData)     else {       fatalError("\(#function) : provider load failed.")     }     guard let cgImage = CGImage(width: width,                   height: height,                   bitsPerComponent: bytesPerComponent * 8,                   bitsPerPixel: bytesPerComponent * channel * 8,                   bytesPerRow: bytesPerComponent * channel * width,                   space: CGColorSpaceCreateDeviceGray(),                   bitmapInfo: CGBitmapInfo(rawValue: 0),                   provider: provider,                   decode: nil,                   shouldInterpolate: false,                   intent: .defaultIntent)     else {       fatalError("\(#function) : create cgimage failed by unknown error")     }     return UIImage(cgImage: cgImage)   } This code is done every frame, and produce this log, sometimes and logs are too much. [Mars] mapData:843: *** ImageIO - mmapped file changed (old: 6782 new: 6875) I don't know "843" mean and following number paste at tail of log, changed every times. I don't know it means warning or error and so on. It works well, it seems no problem, But I worried about too many logs and thread problem. I just feel bad. Have you see this log anyone?
Posted
by Wonki.
Last updated
.
Post marked as solved
4 Replies
595 Views
Hello everyone, I'm graphic beginner programmer I want to use 3d texture on metal for my projects... But I can't, because of error. I try example of this link.. fragment half4 mip_fragment ( VertexOutput in [[ stage_in ]], texture2d<float> backface [[ texture(0) ]], texture3d<float> volume [[ texture(1) ]] ) {   constexpr sampler s(s_address::clamp_to_edge, t_address::clamp_to_edge, min_filter::linear, mag_filter::linear); float3 rgb = backface.sample(s, in.pixelCoord).rgb;    float3 lookupColor = volume.sample(s, rgb, 0).rgb;    return half4(half3(lookupColor), 1.h); } But I get this errors. Fragment Function(mip_fragment): incorrect type of texture (MTLTextureType2D) bound at texture binding at index 1 (expect MTLTextureType3D) for volume[0]. And app is crashed. Please help me.
Posted
by Wonki.
Last updated
.
Post not yet marked as solved
3 Replies
444 Views
Hello everyone, I am studying apply metal to scenekit. I want to pass nil texture to fragment shader. But I don't know how... This code is for pass texture named volume to fragment shader using scntechnique. swift code if let path = Bundle.main.path(       forResource: "volumerendering-metal",       ofType: "plist")     {       if let dico1 = NSDictionary(contentsOfFile: path) {         let dico = dico1 as! [String: AnyObject]         let technique = SCNTechnique(dictionary: dico)                   let screenSize = NSValue(           cgSize: view.frame.size.applying(CGAffineTransform(scaleX: 2.0, y: 2.0)))         technique?.setValue(screenSize,                   forKeyPath: "screen_size")                   technique?.setValue(nil, forKey: "volume")        // or?  // technique?.setObject(nil, forKeyedSubscript: "volume" as NSCopying)                   scnView.technique = technique       }     } property list file <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>passes</key> <dict> <key>pass_backface</key> <dict> <key>metalVertexShader</key> <string>backface_vertex</string> <key>metalFragmentShader</key> <string>backface_fragment</string> <key>program</key> <string>doesntexist</string> <key>depthStates</key> <dict> <key>clear</key> <true/> </dict> <key>colorStates</key> <dict> <key>clear</key> <true/> <key>clearColor</key> <string>sceneBackground</string> </dict> <key>cullMode</key> <string>front</string> <key>includeCategoryMask</key> <string>2</string> <key>draw</key> <string>DRAW_NODE</string> <key>inputs</key> <dict> <key>aPos</key> <string>vertex-symbol</string> </dict> <key>outputs</key> <dict> <key>color</key> <string>backface</string> </dict> </dict> <key>pass_mip</key> <dict> <key>colorStates</key> <dict> <key>clear</key> <true/> <key>clearColor</key> <string>sceneBackground</string> </dict> <key>depthStates</key> <dict> <key>clear</key> <true/> </dict> <key>metalVertexShader</key> <string>mip_vertex</string> <key>metalFragmentShader</key> <string>mip_fragment</string> <key>program</key> <string>doesntexist</string> <key>cullMode</key> <string>back</string> <key>includeCategoryMask</key> <string>2</string> <key>draw</key> <string>DRAW_NODE</string> <key>inputs</key> <dict> <key>aPos</key> <string>vertex-symbol</string> <key>viewport</key> <string>screen_size</string> <key>backface</key> <string>backface</string> <key>volume</key> <string>volume</string> </dict> <key>outputs</key> <dict> <key>color</key> <string>COLOR</string> <key>depth</key> <string>DEPTH</string> </dict> </dict> </dict> <key>sequence</key> <array> <string>pass_backface</string> <string>pass_mip</string> </array> <key>targets</key> <dict> <key>backface</key> <dict> <key>type</key> <string>color</string> </dict> </dict> <key>symbols</key> <dict> <key>vertex-symbol</key> <dict> <key>semantic</key> <string>vertex</string> </dict> <key>screen_size</key> <dict> <key>type</key> <string>vec2</string> </dict> <key>volume</key> <dict> <key>type</key> <string>sampler3D</string> </dict> </dict> </dict> </plist> shader code fragment float4 mip_fragment (   VertexOutput in [[stage_in]]   , texture2d<float, access::sample> backface [[texture(0)]]   , texture2d<float, access::sample> volume [[texture(1)]] ) {   ...     if (is_null_texture(volume)) return float4(1, 0, 0, 0);   else return float4(0, 1, 0, 0); } I want to get red object but green object.... Because I want to set 3d texture at runtime. So before set it want to be nil, because error occurred. (https://developer.apple.com/forums/thread/688841)
Posted
by Wonki.
Last updated
.