|
@@ -25,9 +25,11 @@ It takes as parameter the UV of the screen and returns a vec3 RGB with the color
|
|
|
special built-in varying: SCREEN_UV can be used to obtain the UV for
|
|
|
the current fragment. As a result, this simple 2D fragment shader:
|
|
|
|
|
|
-::
|
|
|
+.. code-block:: glsl
|
|
|
|
|
|
- COLOR=textureLod( SCREEN_TEXTURE, SCREEN_UV, 0.0);
|
|
|
+ void fragment() {}
|
|
|
+ COLOR=textureLod( SCREEN_TEXTURE, SCREEN_UV, 0.0);
|
|
|
+ }
|
|
|
|
|
|
results in an invisible object, because it just shows what lies behind.
|
|
|
|
|
@@ -45,7 +47,7 @@ special demo for *Screen Space Shaders*, that you can download to see
|
|
|
and learn. One example is a simple shader to adjust brightness, contrast
|
|
|
and saturation:
|
|
|
|
|
|
-::
|
|
|
+.. code-block:: glsl
|
|
|
|
|
|
shader_type canvas_item;
|
|
|
|
|
@@ -53,13 +55,15 @@ and saturation:
|
|
|
uniform float contrast = 1.0;
|
|
|
uniform float saturation = 1.0;
|
|
|
|
|
|
- vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
|
|
|
+ void fragment() {
|
|
|
+ vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
|
|
|
|
|
|
- c.rgb = mix(vec3(0.0), c.rgb, brightness);
|
|
|
- c.rgb = mix(vec3(0.5), c.rgb, contrast);
|
|
|
- c.rgb = mix(vec3(dot(vec3(1.0), c.rgb)*0.33333), c.rgb, saturation);
|
|
|
+ c.rgb = mix(vec3(0.0), c.rgb, brightness);
|
|
|
+ c.rgb = mix(vec3(0.5), c.rgb, contrast);
|
|
|
+ c.rgb = mix(vec3(dot(vec3(1.0), c.rgb)*0.33333), c.rgb, saturation);
|
|
|
|
|
|
- COLOR.rgb = c;
|
|
|
+ COLOR.rgb = c;
|
|
|
+ }
|
|
|
|
|
|
Behind the scenes
|
|
|
~~~~~~~~~~~~~~~~~
|
|
@@ -125,8 +129,10 @@ converted via the inverse projection matrix.
|
|
|
|
|
|
The following code retrieves the 3D position below the pixel being drawn:
|
|
|
|
|
|
-::
|
|
|
-
|
|
|
- float depth = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;
|
|
|
- vec4 upos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth*2.0-1.0,1.0);
|
|
|
- vec3 pixel_position = upos.xyz/upos.w;
|
|
|
+.. code-block:: glsl
|
|
|
+
|
|
|
+ void fragment() {
|
|
|
+ float depth = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;
|
|
|
+ vec4 upos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth*2.0-1.0,1.0);
|
|
|
+ vec3 pixel_position = upos.xyz/upos.w;
|
|
|
+ }
|