Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
shader:start [2025/05/21 14:22] – [Normalized input Coordinates] mh | shader:start [2025/06/02 21:23] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 9: | Line 9: | ||
==== Normalized input Coordinates ==== | ==== Normalized input Coordinates ==== | ||
- | Generally the '' | + | Generally the **'' |
Different compilers use different syntax to describe the resolution. Here we'll use Shadertoy' | Different compilers use different syntax to describe the resolution. Here we'll use Shadertoy' | ||
Line 57: | Line 57: | ||
float d = length(uv); | float d = length(uv); | ||
float r = .3 | float r = .3 | ||
- | float c = 1.-smoothstep(r, | + | float c = smoothstep(r, |
// Output to screen | // Output to screen | ||
Line 88: | Line 88: | ||
</ | </ | ||
+ | <WRAP info> | ||
+ | **Note :** when adding or removing regions in this manner, the color value for each RGB component of each pixel **can go** below 0.0 and above 1.0. | ||
+ | |||
+ | Shaders will automatically clamp the output between 0.0 and 1.0 but during the calculation of the color, the real value must be taken into account. | ||
+ | |||
+ | This behavior can lead to unexpected behaviors and colors in certain regions where multiple subtractions/ | ||
+ | |||
+ | ==== Rectangle ==== | ||
+ | |||
+ | To draw a rectangle we can use a function that draws bands using **'' | ||
+ | |||
+ | The band function would look like this | ||
+ | |||
+ | <code glsl> | ||
+ | float drawBand(float t, float start, float end, float blur){ | ||
+ | float step1 = smoothstep(start-blur, | ||
+ | float step2 = smoothstep(end+blur, | ||
+ | | ||
+ | return step1*step2; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Then get a rectangle by calling this function twice on the x and y : | ||
+ | |||
+ | <code glsl> | ||
+ | float mask = 0.; | ||
+ | float b = .01; | ||
+ | | ||
+ | mask = drawBand(uv.x, | ||
+ | mask *= drawBand(uv.y, | ||
+ | </ | ||
==== Adding Color ==== | ==== Adding Color ==== | ||