Are Red and Green somehow more dominant than Blue (RGB)? - opengl

In OpenGL, I made a sphere and gave every Fragment the Color of its normalized position. The sphere is right at the origin so the sphere should be covered with smooth color gradients between red, green, and blue, while on every axis, the color is pure(x - red, y - green, z - blue).
but not like I expected i see this shape when i look down the Z/Blue Axis
I played around a little and compared the gradients between the different colors
(looking down the x axis with zero red color)
In this image, it looks like the Green color is somehow more dominant than the blue, as if it was sprayed on top of it. Also the Blue seems to be deminished by the black.
(looking down the y axis with zero green color)
In this image there seems to be a smoother gradient but i´d still say there is more red than blue in the image but this might be my individual perception and the picture is not perfectly symmetrical aswell.
(looking down the z axis with zero blue color)
To me it looks like Green and Red are more dominant than blue for some reason.
But what originally brought up this question is the weird hard gradient i got (first image). I dont think it is a bug in my shaders, because i never treat any color individually.
What could cause this behaviour?
PS: I have not implemented alpha yet and i am not using alpha anywhere in my shader (where i use a vec4 for color, the 4th component is always 1.0)

Related

Negate Image Without gray Overlapping

Image negative effect is typically done like this:
pixel = rgb(1, 1 ,1) - pixel
but if the pixel color is close to gray, than:
pixel = rgb(1, 1, 1) - rgb(0.5, 0.5, 0.5) = 0.5
That's not a problem and it's how it should be, but for me it is, I am making a crosshair texture in my 3D game, which will be drawn in the center of the screen and I want it to have negative effect, reason for it is clearity, if I were to make crosshair white, it would not be visible when looking on white objects (I know I can make it with black outline so it is visible, but thats ugly), but it still has problems for grayish colors as I described, what can be done to fix that?

How to do single color linear interpolation?

I need to do color interpolation of single color(not interpolation from one color to another color).
For an example, if the color is yellow (dark yellow) should be interpolated to light yellow within certain duration, which means for each time step color interpolation should happen within the color and after that duration/time step reverse interpolation (light yellow to dark yellow) should start for certain time step, so this cycle continues until the user stops it through request command.
Basically I need to change brightness.
using color_t = std::array<float,3>;
// we can consider the value from 0-255
color_t yellow{1,1,0}; //as we increase yellow[2], it move towards light yellow
color_t green{0,1,0}; //dark green
// as we increase green[2],it move towards light green
color_t red{1,0,0};
// as we increase red[1],it move towards light red
color_t blue{0,0,1};
// as we increase blue[1],it move towards light blue
timeStepCount = 0;
time_step = 100;
void Linear(std::array<float,3>&color){
}
In the above function, RGB value (let's say for yellow) for color will be passed by reference, so for each time step, I need to get the different RGB values of the same color(as I mentioned above, from dark to light and light to dark).
I need to have the generic linear function, which should work for any color.
I know that I need to find a mathematical equation in order to solve it.
But also okay if I get any solution to above mentioned colors.

Shader that replaces colors

I want to make a shader that replace a color to be applied to a plain color character, but I can't just replace the color because the image contains pixels that are an average of two border colors.
For example the image looks like this:
Assuming that I want to change the color of the shirt, I want to replace the red color for a green one, but at the edges there are pixels that are not red:
Any ideas how to calculate the resultant color of one of those pixels?
Do you know which are the major colours in advance?
If not then a simple solution for finding them is to generate a histogram — scan the entire image and for each pixel that is the same as all four of its neighbours, add one to a count for the colour it contains. At the end, keep only those colours that fill at least a non-negligible portion of the display, e.g. at least 5% of those pixels that are not transparent.
Dealing with black borders is easy: use a luminance/chrominance colour space, and always leave luminance alone, remapping only chrominance. Factoring out brightness has a bonus: it collapses colour substitution from a 3d problem to a 2d problem.
If this weren't GLSL then a solid solution might be for each pixel that is not one of the selected major colours might be (i) find the nearest pixel that is a major colour; (ii) then find the nearest pixel that is a major colour but not the one found in (i). Use normal linear algebra to figure out the distance of that pixel on the 2d line from the one colour to the other. Substitute the colours, reinterpolate and output.
Being that it is GLSL, so "find the nearest" isn't especially realistic, assuming the number of major colours is small then just do it as distance from those lines. E.g. suppose you have five colours. Then that's 10 potential colour transitions in total — from each of the five colours there are four other options, suggesting twenty transitions, but half of them are exactly the same as the other half because they're just e.g. red to blue instead of blue to red. So ten.
Load those up as uniforms and just figure out which transition gradient the colour is closest to. Substitute the basis colours. Output.
So, in net:
transform (R, G, B) to (Y, x, y) — whether YUV or YIQ or Y doesn't matter, just pick one;
perform distance from a line for (x, y) and the colour transition gradients identified for this image;
having found the transition this pixel is closest to and its distance along that transition, substitute the end points, remap;
recombine with the original Y, convert back to RGB and output.
That's two dot products per colour transition gradient to establish closest, then a single mix to generate the output (x, y)/
Let Rx, Gx, Bx = Pixel values of color X (Red in your case) to be removed/replaced.
Let Ry, Gy, By = Pixel values of color Y (Green in your case) to be used as new color.
Then you will iterate over all pixels and using clever condition (below), identify the pixel that needs to be processed.
If Rc is current value of the selected pixel color (does not matter what combination of red and yellow is), then final values of the pixel are:
Rf = Rc - Rx + Ry
Gf = Gc - Gx + Gy
Bf = Bc - Bx + By
Of course, this processing should NOT happy for all pixels. Clever condition to identify only relevant pixels could be : If pixel color is Red or least one adjacent pixel is Red/Yellow.
UPDATE: Another clever condition using current pixel only:
This involves removing border colors YELLOW or BLACK color from the current color and checking if it is RED.
Rc - R(yellow) == R(RED) AND
Gc - G(yellow) == G(RED) AND
Bc - B(yellow) == B(RED)
OR
Rc - R(black) == R(RED) AND
Gc - G(black) == G(RED) AND
Bc - B(black) == B(RED)

How to create a texture alpha, with white and black colors only, in GLSL?

I am looking to reproduce the glow effect from this tutorial, if I understand well, we convert the first image to an "alpha texture" (black and white), and we blur the (rgb * a) texture.
How is it possible to create this alpha texture, so that some colors go to the white, and the other go to the black? I found this : How to render a texture with alpha? but I don't really know how to use these answers.
Thanks
It appears you are misunderstanding what that diagram is showing you. It is actually all one texture, but (a) shows the RGB color and (b) shows the alpha channel. (c) shows what happens when you multiply RGB by A.
Alpha is not actually "black and white", it is an abstract concept and amounts to a range of values between 0.0 and 1.0. For the human brain to make sense out of it, it interprets that as black (0.0) and white (1.0). In reality, alpha is whatever you want it to be and unrelated to color (though it can be used to do something to color).
Typically the alpha channel would be generated by a post-process image filter, that looks for areas of the texture with significantly above average luminance. In modern graphics engines HDR is used and any part of the scene with a color too bright to be displayed on a monitor is a candidate for glowing. The intensity of this glow is derived from just how much brighter the lighting at that point is than the monitor can display.
In this case, however, it appears to be human created. Think of the alpha channel like a mask, some artist looked at the UFO and decided that the areas that appear non-black in figure (b) were supposed to glow so a non-zero alpha value was assigned (with alpha = 1.0 glowing the brightest).
Incidentally, you should not be blurring the alpha mask. You want to blur the result of RGB * A. If you just blurred the alpha mask, then this would not resemble glowing at all. The idea is to blur the lit parts of the UFO that are supposed to glow and then add that on top of the base UFO color.

Multiple textures on one polygon OpenGL

So I have no idea how I should be doing what I want do so I'll explain as best as I can.
http://i.stack.imgur.com/j65H8.jpg
So imagine that entire image is a 2d square 128x128 and each color I want to apply a texture to that part of the 2d square. Also I want it to stretch as well so Red, Aqua, Green and Purple never stretch in any direction but Pink stretches all directions and then Grey, Yellow, Black and Orange stretch in the longest direction (grey/orange = width expands, yellow/black = height expands). When stretched it should look like this:
http://i.stack.imgur.com/wJiKv.jpg
Also I am using C++.