how to disable depth test but enable update depth texture(like glDepthMask(GL_TRUE)) in metal? - opengl-es-2.0

In OpenGL, we can disable depth test and only update depth texture(the depth texture is bind to GL_DEPTH_ATTACHMENT of FBO by glFramebufferTexture2D) in the following ways:
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDisable(GL_DEPTH_TEST) means all the fragments will "always pass", so I set MTLCompareFunctionAlways to depthCompareFunction of MTLDepthStencilDescriptor.
glDepthMask(GL_TRUE) means the depth texture will be updated with the fragments depth value, whatever value it previously had. In Metal, I set true to depthWriteEnabled of MTLDepthStencilDescriptor.
Unfortunately, the final render result is wrong. Is that I understand it wrong? If yes, then how to set it in the correct way in Metal.

Even if the depth buffer exists and the depth mask is non-zero, the depth buffer is not updated if the depth test is disabled. In order to unconditionally write to the depth buffer, the depth test should be enabled and set to GL_ALWAYS by glDepthFunc.

Related

What is the right way to use Logic operations (VkLogicOp) in vulkan

I have a case where I am writing to integer framebuffers, and I want to use logic operations when writing to pixels in the fragment shader. These are the steps I followed:
When creating the logical device, I set the VkPhysicalDeviceFeatures.logicOp to VK_TRUE (so this feature is enabled)
when creating the pipeline, I set VkPipelineColorBlendStateCreateInfo.logicOpEnable to VK_TRUE, and VkPipelineColorBlendStateCreateInfo.logicOp to VK_LOGIC_OP_COPY.
My framebuffer format is VK_FORMAT_R32G32B32A32_SINT
Once I render the frame, I see that nothing is getting updated in the frame buffer. Is there any step I am missing? (btw, I don't get any validation errors).
Thanks!

What is the use of .range field when updating a buffer descriptor?

When I went to update a UNIFORM_BUFFER descriptor, I set up the buffer info:
VkDescriptorBufferInfo buffer_info;
buffer_info.buffer = /* SOME BUFFER */;
buffer_info.offset = 0;
buffer_info.range = 0; // I assume this doesn't do any thing for this use
And then vkUpdateDescriptorSets().
Get the validation layer error:
VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which
is not allowed.. The Vulkan spec states: If range is not equal to
VK_WHOLE_SIZE, range must be greater than 0
My question is, isn't the job of the buffer info to tell which buffer and what offset to read from the shaders at a particular descriptor set and binding? I didn't think the size of the buffer mattered because generally that's how these things work, you usually specify a buffer and offset and then you read outside that buffer in the shader at your peril.
Let's just I write the wrong range, what would that do? If I write a 32 and in the shader I access 64 bytes in, what happens? Is this argument for validation warnings?
Edit: I just want to clarify the range argument can't mean how much of the buffer I want to copy, what I'm writing to is essentially a pointer. The actual writing of the buffer data is done in a buffer to buffer copy transfer.
A descriptor describes a (usually memory) resource being used by a shader in some capacity. Buffers do have a size, but a shader can use a subset of a buffer's memory range. The descriptor describes which portion of the buffer is being used.
If a descriptor should use the whole size of the buffer assigned to it (starting at offset), that's what VK_WHOLE_SIZE is for.
This allows you to have multiple uniform buffers provided by the same VkBuffer resource. You can even use dynamic uniform block descriptors to change the offset/range without changing the buffer binding itself. This is faster than switching descriptor sets, thus making it easier to provide per-object data.
Let's just I write the wrong range, what would that do?
If the range is smaller than the size of the uniform block specified in the shader, then you'll get a validation failure/undefined behavior.

What is mouseResponse threshold and why should we set a specific threshold?

I am beginner.I just started coding in codeacademy.In a certain level,the gave me a task which is relatate with threshold.So,my question is what is mouseResponse threshold and why should we set a specific threshold?
The actual question is give below:
1.
Three variables let you experiment with the animation physics: mouseResponseThreshold, friction, and rotationForce.
mouseResponseThreshold affects how close the mouse pointer needs to be to affect the dots that make up the letters. The larger the number, the more powerful the effect of the mouse interaction. Experiment with changing the mouseResponseThreshold to different numbers and running your code!
And the hint is "Try starting out by setting the threshold to 150."
What is mouseResponse threshold
This is distance from the mouse position to your target's position (in this case, the target is the "...dots that make up your letters").
Why should I set it
You need to set it so that your code knows at what distance it needs to do a certain operation.

The best way to change background color in image in Cocoa

Little description:
I get an image from my scanner using Capture Core Framework and background color is gray. So I want to do white background.
I'm looking for best way to remove this color. I looked at Image Core Filters. And as I understood I should use those ones, but I couldn't find included/ready filterfor this task. So, Do I have to write it myself?
It means to remove color I should write my own filter and apply it to my images? Right? Thank you.
UPD: I develop for Mac os
Why not just simply change the brightness of your image? If this gray background color value is fixed then you can increase the brightness a little bit, as a preprocess step, until you're satisfied.
A filter isn't quite the right tool for the job here. Filters apply a colour-shifting algorithm, pixel by pixel, to all of the pixels in an image.
This would be appropriate in your case if there was something completely unique about the pixels that you want to turn to white. For example, if the background you wish to eliminate was in a very narrow colour range that did not occur in any other part of the image. This is the technique used in greenscreen/bluescreen filming, which only works if that green or blue colour does not occur anywhere in the image regions you want to keep.
But - as you say in one of your comments - you cannot do this as that grey level you want to get rid of will not be unique to the background, so any filter you apply that would pick out those pixes may also affect pixels in the scanned subjectmatter.
What you really need is a way to select a region of interest and apply a filter to that region alone. You could use openCV for this. In fact it has a function that can achieve your result in one go:
http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=floodfill#int
floodFill(InputOutputArray image, //image to process
Point seedPoint, //starting pixel
Scalar newVal, //New value of the repainted domain pixels
Rect* rect, //optional output param (you won't need it)
Scalar loDiff, //max lower brightness/colour diff to select
Scalar upDiff, //max upper brightness/colour diff to select
int flags) //you want FLOODFILL_FIXED_RANGE
This function starts from a seedPoint, which should be any pixel that you can guarantee will be a part of the background grey you want to eliminate. (0,0) might work for you. It then interrogates neighbouring pixels, including them in the ROI array if they are sufficiently similar. The resulting array is a connected region. If your background grey uniformly falls between loDiff and upDiff - and your subject scan has a defined edge which does NOT fall into this range, you will get your result - selection and remapping of all background pixels to newVal (white).

How to reset OpenGL program's uniform attribute value to default?

Let's say I have an OpenGL program that has a uniform attribute "diffuseColor". I have set it as following:
GLint location = glGetUniformLocation(handle, "diffuseColor");
glUniform3f(location, 1, 0, 0);
Now I would like to return it to the default value, which is encoded in the shader code. I do not have access to the source code, but I can call OpenGL API functions on the compiled program. Is there a way to read default value and set it with glUniform3f? Or even better, is there a something like glResetUniform3f(GLint loc)?
Uniform initializers are applied upon linking the program. The value can then be read using glGetUniformfv/glGetUniformiv. There is no way to read the initial value of the uniform after you changed the uniform value.
There is no way to reset a single uniform to its initial value, but relinking the program will reset all uniforms in it. Linking a program is a costly operation and should be avoided in between frames.