texture with alpha component rendered offscreen: dots pattern in a multisample renderPass - vulkan

I create an offscreen texture with alpha component, samples in the offscreen renderPass is VK_SAMPLE_COUNT_1_BIT.
When I use this texture in a VK_SAMPLE_COUNT_4_BIT renderPass, I get black dots pattern where there is an alpha component.
I understand why, but I don't know how to solve this problem.
I thought I could use an offscreen renderpass with VK_SAMPLE_COUNT_4_BIT with another VK_SAMPLE_COUNT_1_BIT attachment to resolve into, but my texture would still be VK_SAMPLE_COUNT_1_BIT.
So I'm not sure it will solve the black dots issue, and I prefer to seek advice before I get into big changes.
-------- edit 1 --------
The dots appear when I use these VkPipelineMultisampleStateCreateInfo setting:
.alphaToCoverageEnable = VK_TRUE;
.alphaToOneEnable = VK_TRUE;
If these two setting are set to VK_FALSE, I've got transparent texture but without any gradient, it's transparent or opaque.
Here are my VkPipelineColorBlendAttachmentState setting for both offscreen and texturing renderPass:
.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
.colorBlendOp = VK_BLEND_OP_ADD;
.alphaBlendOp = VK_BLEND_OP_ADD;
When I look at the offscreen texture with a green "clear color", I can see the gradient of transparency, so I suppose the offscreen renderPass is correctly set.
-------- edit 2 --------
I modified the offscreen renderPass in order to use the same sample count as in the onscreen, or final, renderPass, by hadding a resolve attachment with VK_SAMPLE_COUNT_1_BIT.
I still have dots if I set .alphaToCoverageEnable and .alphaToOneEnable to VK_TRUE.
When set to false, the full image is semi-transparent, even the opaques parts.

Related

TCPDF - Cropping polygons

I'm using TCPDF::Polygon() to render coastline (land) coordinates from a text file on top of a blue TCPDF::Rect(). The text file contains coastlines for the entire world, however by specifying a center latitude and longitude in the map projection, together with some multiplication to get a 'zooming' effect, I manage to display the desired area within the A4 page.
Problem:
As you can see by the image the coastlines are drawn all the way to the edge of the document (and beyond). Although most of the coastline coordinates from the text file are 'outside' the document's visible area they are still taking up some hundred kilobytes in the output file.
Is there a nice way to 'crop' the coastline-polygon, so that the coastlines fit nicely inside the blue area and the excess vertecies are completely excluded from the document (not taking up file space)?
Solution:
The 'cropping' I was looking for is done using clipping, as suggested by #Rad Lexus:
// Start clipping
$pdf->StartTransform();
// Draw clipping rectangle
$pdf->Rect($DOC_MARG, $DOC_MARG, $MAP_W, $MAP_H, 'CNZ');
// -- Draw all polygons here (land areas) --
// Stop clipping
$pdf->StopTransform();
Source: https://stackoverflow.com/a/9400490/2667737
To save space in the output file I check every pixel in each polygon (land area) and render only the polygons that has one or more pixels within the bounds of the page - also suggested by #Rad. In the example view in my first post, the size was halved using this method.
Thanks for the help!

Photoshop layer blending - null out background

Is it possible using layer blending and maybe masking to null out the background(transparent) using a picture with the product in place and one without the product as a background reference picture.
Like a layer mask that only reveals where images are different. (Product and shadow)
Thanks in advance.
Totally possbile but i'm not sure you'll get the desired effect. If you want to subtract absolutely just the areas where there are color differences that means shadow edges will be pixelated. Nonetheless, here's how you do it
Set up your layers like so:
Layer 1 (background + product baked in on top)
Layer 2 (background only)
Set Layer 1 blending mode to "Difference" --All the pixels with the same color information will turn black.
Flatten this and we'll call it "Layer 3 (Difference)"
Go into Layer 3's FX Styles. Under Blending Options, all the way at the bottom you'll find "Blend if:"
Set this to Gray and slide the "This layer:" markers until it says 0 0.
Voila. You have the mask to put on your original Layer 1 that eliminates all pixels with the same information.

OpenGL multi texture masking

I fallowed #Stefan Monov tutorial in this question. And everything works, but I need to make it working with my brush. I need to do so:
// Next, we want a blendfunc that doesn't change the color of any pixels,
// but rather replaces the framebuffer alpha values with values based
// on the whiteness of the mask. In other words, if a pixel is white in the mask,
// then the corresponding framebuffer pixel's alpha will be set to 1.
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO);
// Now "draw" the mask (again, this doesn't produce a visible result, it just
// changes the alpha values in the framebuffer)
drawQuad(maskTexture);
would be not a static texture, but dynamic shape. I mean, i'm trying to implement brush witch is doing such a thing that is written by #Stefan Monov. So I need that this place could be implemented in other - (void) function, so that it could be called, when coordinates changes (when user draws). I tried a variety of ways to change the sequence of your code, but it does not work correctly then. Now my bursh code is:
glEnable(GL_BLEND);
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO);
glPointSize(100);
glBegin(GL_POINTS);
glColorMask(1.0,1.0,1.0, 1.0);
glVertex2f(loc.x, loc.y);
glEnd();
glDisable(GL_BLEND);
It is called when mouse is dragged. "loc" is dragged mouse coordinates. Afcourse its not working now at all, because of blendFunc and code's sequence. When I leave sequence as #Stefan Monov described, it works, but it draws one point and drags it when mouse is dragged. Becouse after drawing point, other textures is being redrawed too. Any, at least similar, solution for it?
To make it more clear i'll show how I want my APP to work.
Here is the original code:
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ZERO);
drawQuad(backgroundTexture);
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO);
drawQuad(maskTexture);
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
drawQuad(foregroundTexture);
Now its working like this:
Draws background
Draws mask
Draws foreground
I need it to work like this:
Draws bacground
Draws foreground
Draws mask
But if i change the order of drawings it stops working. Ignores mask.
Expected result foto:
Your attempt to draw the mask last makes no sense really.
Drawing the mask only modifies what's in the alpha channel, and the alpha channel itself is not visible in any way in the final image.
The only use of the mask is to modify what's drawn after it.

OpenGL ES OBJ Loading Transparency Issues

Hi I am working on an OBJ loader for use in iOS programming, I have managed to load the vertices and the faces but I have an issue with the transparency of the faces.
For the colours of the vertices I have just made them for now, vary from 0 - 1. So each vertex will gradually change from black to white. The problem is that the white vertices and faces seem to appear over the black ones. The darker the vertices the more they appeared covered.
For an illustration of this see the video I posted here < http://youtu.be/86Sq_NP5jrI >
The model here consists of two cubes, one large cube with a smaller one attached to a corner.
How do you assign a color to vertex? I assume, that you have RGBA render target. So you need to setup color like this:
struct color
{
u8 r, g, b, a;
};
color newColor;
newColor.a = 255;//opaque vertex, 0 - transparent
//other colors setup

Drawing an angle/angular/"Conical"/"Arcing" gradient in Objective-C (IOS) using Core Graphics

I'm trying to draw a "conical"/"arcing" gradient (I don't know what would be the correct term for this) (Photoshop calls it an "angle" gradient —your friendly neighborhood stackoverflow editor) using Objective-C (IOS), pretty much exactly like the image shown in the following thread.
After days of googling and searching the internet to no avail, I've decided to ask for help here.
A little background on what I'm trying to do. My objective is to create a custom UIView, which is circular progress bar, a ring basicly, somewhat similar to the activity indicator as seen in the TweetBot iPhone app (displays when you drag to refresh, which can be seen in action here, around 17-18 seconds into the video, on top of the iphone screen). I want the progress indicator (the fill of the ring) to be a simple two color gradient, which can be set programmatically, and the view to be resizable.
Filling the ring shape with a gradient that "follows" the arc of the ring is where I'm stuck. The answers that I get from googling, reading Apple's Core Graphics documentation on gradients and searching on SO are either about radial gradients or linear/axial gradients, which is not what I'm trying to achieve.
The thread linked above suggests using pre-made images, but this isn't an option because the colors of the gradient should be settable, the view should be resizable and the fill of the progress bar isn't always 100% full obviously (which would be the state of the gradient as shown in the picture in the thread above).
The only solution that I've come up with is to draw the gradient "manually", so without using a CGGradientRef, clipping small slices of the gradient with single solid color fills within a circular path. I don't know exactly how well this will perform when the bar is being animated though, it shouldn't be that bad, but it might be a problem.
So my first question:
Is there an easier/different solution to draw a conical/arcing gradient in Objective-C (IOS) than the solution I've come up with?
Second question:
If I have to draw the gradient manually in my view using the solution I came up with, how can I determine or calculate (if this is even possible) the value (HEX or RGBA) of each color "slice" of the gradient that I'm trying to draw, as illustrated in the image below.
(Can't link image) gradient slice illustration
Looks to me like a job for a pixel shader. I remember seeing a Quartz Composer example that simulated a radar sweep, and that used a pixel shader to produce an effect like you're describing.
Edit:
Found it. This shader was written by Peter Graffignino:
kernel vec4 radarSweep(sampler image, __color color1,__color color2, float angle, vec4 rect)
{
vec4 val = sample(image, samplerCoord(image));
vec2 locCart = destCoord();
float theta, r, frac, angleDist;
locCart.x = (locCart.x - rect.z/2.0) / (rect.z/2.0);
locCart.y = (locCart.y - rect.w/2.0) / (rect.w/2.0);
// locCart is now normalized
theta = degrees(atan(locCart.y, locCart.x));
theta = (theta < 0.0) ? theta + 360.0 : theta;
r = length(locCart);
angleDist = theta - angle;
angleDist = (angleDist < 0.0) ? angleDist + 360.0 : angleDist;
frac = 1.0 - angleDist/360.0;
// sum up 3 decaying phosphors with different time constants
val = val*exp2(-frac/.005) + (val+.1)*exp2(-frac/.25)*color1 + val*exp2(-frac/.021)*color2;
val = r > 1.0 ? vec4(0.0, 0.0,0.0,0.0) : val; // constrain to circle
return val;
}
The thread linked above suggests using pre-made images, but this isn't an option because the colors of the gradient should be settable, the view should be resizable and the fill of the progress bar isn't always 100% full obviously (which would be the state of the gradient as shown in the picture in the thread above).
Not a problem!
Use the very black-to-white image from the other question (or a bigger version if you need one), in the following fashion:
Clip to whatever shape you want to draw the gradient in.
Fill with the color at the end of the gradient.
Use the black-to-white gradient image as a mask.
Fill with the color at the start of the gradient.
You can rotate the gradient by rotating the mask image.
This only supports the simplest case of a gradient with a color at each extreme end; it doesn't scale to three or more colors and doesn't support unusual gradient stop positioning.
FYI: here's also a good tutorial for creating a circular progress bar using Quartz drawing.
http://www.turnedondigital.com/blog/quartz-tutorial-how-to-draw-in-quartz/