R2 Core Shaders
Data Structures | Functions
R2Refraction.h File Reference

Functions and types to render generic refraction. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  R2_refraction_t
 

Functions

vec4 R2_refractionMasked (const R2_refraction_t refraction, const vec4 position_here_clip, const vec3 delta)
 

Detailed Description

Functions and types to render generic refraction.

Definition in file R2Refraction.h.

Function Documentation

§ R2_refractionMasked()

vec4 R2_refractionMasked ( const R2_refraction_t  refraction,
const vec4  position_here_clip,
const vec3  delta 
)

Calculate masked refraction using a given delta vector.

Parameters
refractionBasic refraction parameters
position_here_clipThe clip-space coordinates of the surface
deltaThe delta vector
Returns
A refracted sample

Definition at line 30 of file R2Refraction.h.

34 {
35  vec3 delta_scaled = delta * refraction.scale;
36 
37  vec3 position_here_ndc = vec3 (position_here_clip.xyz / position_here_clip.w);
38  vec2 position_here_uv = (position_here_ndc.xy + 1.0) * 0.5;
39 
40  vec3 position_there_ndc = position_here_ndc + delta_scaled;
41  vec2 position_there_uv = (position_there_ndc.xy + 1.0) * 0.5;
42 
43  vec4 scene_there = texture (refraction.scene, position_there_uv);
44  float mask = texture (refraction.mask, position_there_uv).x;
45  vec4 scene_here = texture (refraction.scene, position_here_uv);
46 
47  return mix (scene_here, scene_there, mask) * vec4 (refraction.color, 1.0);
48 }
sampler2D mask
An image to mask sampling to avoid bleeding.
Definition: R2Refraction.h:16
float scale
A scaling values for sampled refraction values.
Definition: R2Refraction.h:9
vec3 color
A color by which to multiply the final refracted image.
Definition: R2Refraction.h:11
sampler2D scene
Definition: R2Refraction.h:14