SceneKit background too bright when applying camera frame MTLTexture as a background - ios

I'm trying to convert a camera frame to a MTLTexture and then use it as a SceneKit background. The texture is created successfully, and looks like it should when inspecting it. However, when I set the following:
scene.background.contents = texture
It appears too bright / washed out. Any ideas how to fix this?
Update 1: Gist here

It turns out what was causing the washed out effect in the texture was the pixel format. It should be .bgra8Unorm_srgb (not .bgra8Unorm).

Related

GLKView snapshot returning bad colors

I'm doing some fun shader stuff, but when I call snapshot I get some strange coloring artifacts. In particular, it seems that the red channel is...stuck high, maybe?
UIImage* image = [(GLKView*)self.view snapshot];
Not sure what other code to show, because it doesn't matter if I then turn that into a JPEG and save it to the roll, or just display it in a UIImageView directly, it has a strange red tint.
Some slight chance that this question is also relevant, but it has no answers ~ https://stackoverflow.com/questions/24447265/how-to-avoid-shadows-over-the-glkview-object-in-ios
It ... actually seems to be fixed if I set the view's drawableColorFormat to GLKViewDrawableColorFormatRGB565 ... so ... could anyone explain why that might be?

Sketch App Paint Blending OpenGLES

Can anyone suggest why my low opacity painting does this weird blending, while the SketchBookX app does it perfect?
In both images attached the vertical strokes on the left are done at full opacity, the strokes on the right are done at low opacity. The top image is mine and as you can see the strokes on the right at low opacity turn a orange-red color and don't blend/mesh with the full opacity strokes. But the SketchBookX app blends perfectly and maintains the same color.
I'm using glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) and have tried many variations with no luck, so I'm starting to think there are other things that are giving me this problem.
Do I need to handle this problem in the fragment shader? I currently have this,gl_FragColor = color * rotatedTexture; I'm using PNGs for brush textures.
UPDATE: Im getting the same results without using a texture. gl_FragColor = color;
I want it to be like mixing ink, not like mixing light :)

Sprite Kit - Low Resolution Texture on Retina when using textureFromNode

For my game I am trying to create custom textures from two other textures. This is to allow for a varietly of colours, etc in my sprites.
To do this, I'm creating a sprite by adding both textures together, then applying this to a new SKTexture by using
SKTexture *texture = [self.view textureFromNode:newSprite];
This works great on the whole and I get a nice custom texture. Except when trying my game on Retina devices, where the texture is the correct size on the screen, but clearly a lower resolution.
The textures are all there and properly named so I don't believe that that is an issue.
Has anyone encountered this, or know how I can create the proper #2x texture?
I finally (accidentally) figured out how to fix this. The node which you are creating a texture from has to be added to the scene. Otherwise you will get a non-retina size for your texture.
It's not ideal as it would be nice to create textures without having to add them onto the screen.
I've discovered another way of improving the fidelity of textures created from ShapeNodes, not quite related to this question - but useful intel.
Create your shape at x2 its size and width.
Create all the fonts and other shapes at the same oversized ratio.
Make sure your positioning is relative to this overall size, (e.g. don't use absolute sizes, use relative sizes to the container.)
When you create the texture as a sprite it'll be huge - but then apply
sprite.scale = 0.5; // if you were using 2x
I've found this makes it look much higher resolution, no graininess, no fuzziness on fonts, sharp corners.
I also used tex.filteringMode = SKTextureFilteringNearest;
Thus: it doesn't have to be added to the scene and then removed.

Brush tool texture for a painting app

Im working on a painting app which has a tool to brush similar to a painting brush. I've implemented so far through cocos2d, a format like the image
. But my client wants clear edged texture as the image Also the color of the former image is some what blurring indeed. How I can reduce blurring of the sprite image? The image I am using as a texture is the image. Im using a code derived from the Cocos2d RenderTextureTest.
Also, the blend function Im using like in the below code
[brush setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE}];
[brush.texture setAliasTexParameters];
where, brush is my sprite with the above mentioned texture.
Is there any other way to get the sharp edges as in the later image? Or how I can make the image stop blurring? I am struggling it for last few months. Please some experts look into this and help me.

How can I alphablend only certain parts of a texture in DX 9?

How can I alphablend only certain parts of a texture in DX 9?
For example, layers in Photoshop (or any other photo editing program that supports layers).
You can draw something in a layer (background filled with alpha), then place the layer over the original image (draw the texture on the screen) which leads to the original image + ONLY the things I drew in the layer.
Yes, I know my english is not very "shiny".
Thank you very much, in advance!
P.S. The background of my texture IS filled with alpha.
So you have setup the alpha on the texture you wish to overlay such that 0 is transparent (ie shows whats underneath) and 1 is opaque (ie shows the overlay texture)?
If so then you just need to set up a a simple blend mode:
pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
Make sure you draw the background first! Also note that values between 0 and 1 represent a linear interpolation between background and the overlay texture.

Resources