Is there a glColorMask equivalent in SceneKit? - 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.

Related

#react-three/fiber: RingGeomertry doesn't take the color & shadow

There is something bugging me when using ring geometry. When I attach meshStandardMaterial and specify a color, it always shows as black. I can't use meshBasicMaterial because it's not affected by light. Ring geometry does not react like 3D geometries like sphere.
What i want to do is to show the color of the ring and it receive the shadow from the sphere.
I'm using #react-three/fiber as library to render, you can see the example:
https://codesandbox.io/s/zealous-hawking-llp33w?file=/src/App.js:0-811
I don't know if I'm missing something to understand which material to use, i'm new in #react-three/fiber or Three.js.
Thanks

Bit blit Bitmaps (WriteableBitmapEx Framework)

I've not fully understand the basics of Bit blit bitmaps.
I'm using the WriteableBitmapEx framework (WPF). My bitmap represents a map and what I wanna achieve is to copy a (moving) symbol into that map.
For actual copying, I use the function Blit:
_bitmap.Blit(myObject.Value.Location.ToWindowsPoint(), symbol, rect, Colors.Cyan,
WriteableBitmapExtensions.BlendMode.Additive);
where symbol is a png image(transparent background).
This works in prinicpal but I do not understand how the color (Colors.Cyan) is applied by the blend mode. I've tried out all available blend modes but I've not succeeded in getting Cyan as the color of the symbol or I got the color but then the transparent background was also copied to the source bitmap (black background).
Is 'Bliting' the wrong approach for my use case?
Thanks.
A much easier approach is to use images (corresponding WPF ui element) and layer it above the bitmap. This has also the advantage that you can move the image without redrawing the bitmap at all.

Rectangular shaped Gradient Fill

I'm currently looking to achieve a gradient effect a bit like the rectangle in http://pjnicholson.com/Fireworks/fillgradients.htm
If I compromise a little I can get close to this using RadialGradientBrush... but is there any (not too painful) way to achieve the rectangular effect?
Use an ImageBrush instead and use this image (or a similar image generated using some image editor) for the background of your rectangle.
One solution a colleague and I came with was to derive a new Panel that used a WriteableBitmap as the source for its background.
The panel will give you the dimensions you need to make your WriteableBitmap. Using whatever algorithm you want you can fill it appropriately. In our case, we needed a radial or cone gradient, but the same concept applies.
Additionally, you can create several properties on your new control to specify the colors for the gradient. We adapted a LinearGradientBrush for our needs, but if you're working on just two colors, simple properties may suffice.
I don't have the code handy but will try to find it and post an update later. But the above should get you going.

WPF Image, changing color of pixels

I have a problem. I need to fill (or repaint) some pixels at image, stored in Image control. This is a png image. I mean, that all black pixels should be filled with, for example, red color. How can I do this? I thought I can access directly to pixels and using XOR change special bits, but I don't know how to do this. Or maybe there is an easier way?
The GetPixel and SetPixel methods should work for what you need.
This answer has a code sample that you should be able to adopt for your use.

Change Alpha Blend Mode in WPF?

The System.Drawing.Graphics class has a property CompositionMode with two options: SourceOver (which, based on the alpha component, blends whatever is drawn with the background already existing) or SourceCopy which simply overwrites the background with whatever is being drawn.
Does something similar exist in WPF?
In WPF when i draw a PolyLine for example on top of another the new PolyLine always alphablends with the background. I think that is independent of the container being used. I am using a Canvas but could not find a blend mode property anywhere. What I want to do is what the SourceCopy compositionmode mentioned above does. I.e. the new PolyLine should simply overwrite whatever is already on the Canvas.
Is there a simple way to do that, short of using pixel shaders (which - as far as I understand - wouldn't work anyways because I don't have access to the Canvas backbuffer).
I am not stuck with a Canvas and would be happy to use any container that supports overwrite mode.
I currently have a solution based on a WriteableBitmap for which I obtain a System.Drawing.Graphics context and then manipulate the CompositionMode. It works but since my window is fullscreen that solution has serious performance impacts.
Clarification and example:
The WPF window is fully transparent and so is the Canvas (back ground color(0,0,0,0)). Now I draw a PolyLine with a Color.FromArgb(128,128,0,0). I now have a semi-transparent red polyline. Next I draw the same PolyLine with Color.FromArgb(0,0,0,0). The result is the same as before because of the alpha blending taking place. What I want, however, is that the red polyline is erased with the second polyline (which is exactly what the SourceCopy mode in the Graphics class does.
I think all you need to do is make sure that the brushes used to fill/stroke the PolyLine have fully opaque alpha values (i.e. 255). Then the background shouldn't be blended into it.
You could apply a Clipping Mask, this way you can provide the path to clip over the elements that are below it, but it might be tough to maintain after a lot elements are required to be clipped...

Resources