diff options
author | clayjohn <claynjohn@gmail.com> | 2022-02-19 16:08:53 -0800 |
---|---|---|
committer | clayjohn <claynjohn@gmail.com> | 2022-04-26 11:48:39 -0700 |
commit | 2f2064fe3d08b71491a7e8ea01b91af71ae05c93 (patch) | |
tree | 305126ead809646e04808e57a5b7da52406344fb /drivers/gles3/shaders | |
parent | d9d871dfbf661b329269d7c70a631e3405602e63 (diff) |
Overhaul GLES3: Add basis for 3D renderer, overhaul materials and textures
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r-- | drivers/gles3/shaders/SCsub | 1 | ||||
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 2 | ||||
-rw-r--r-- | drivers/gles3/shaders/sky.glsl | 179 |
3 files changed, 181 insertions, 1 deletions
diff --git a/drivers/gles3/shaders/SCsub b/drivers/gles3/shaders/SCsub index 2f56b77bdc..8443b5df85 100644 --- a/drivers/gles3/shaders/SCsub +++ b/drivers/gles3/shaders/SCsub @@ -5,3 +5,4 @@ Import("env") if "GLES3_GLSL" in env["BUILDERS"]: env.GLES3_GLSL("canvas.glsl") env.GLES3_GLSL("copy.glsl") + env.GLES3_GLSL("sky.glsl") diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 8812447f6e..86ea82c92c 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -286,7 +286,7 @@ in vec2 pixel_size_interp; layout(location = 0) out vec4 frag_color; #ifdef MATERIAL_UNIFORMS_USED -uniform MaterialUniforms{ +layout(std140) uniform MaterialUniforms{ //ubo:4 #MATERIAL_UNIFORMS diff --git a/drivers/gles3/shaders/sky.glsl b/drivers/gles3/shaders/sky.glsl new file mode 100644 index 0000000000..0faa3eb70c --- /dev/null +++ b/drivers/gles3/shaders/sky.glsl @@ -0,0 +1,179 @@ +/* clang-format off */ +#[modes] + +mode_background = +mode_half_res = #define USE_HALF_RES_PASS +mode_quarter_res = #define USE_QUARTER_RES_PASS +mode_cubemap = #define USE_CUBEMAP_PASS +mode_cubemap_half_res = #define USE_CUBEMAP_PASS \n#define USE_HALF_RES_PASS +mode_cubemap_quarter_res = #define USE_CUBEMAP_PASS \n#define USE_QUARTER_RES_PASS + +#[specializations] + +#[vertex] + +#ifdef USE_GLES_OVER_GL +#define lowp +#define mediump +#define highp +#else +precision highp float; +precision highp int; +#endif + +out vec2 uv_interp; +/* clang-format on */ + +void main() { + // One big triangle to cover the whole screen + vec2 base_arr[3] = vec2[](vec2(-1.0, -2.0), vec2(-1.0, 2.0), vec2(2.0, 2.0)); + uv_interp = base_arr[gl_VertexID]; + gl_Position = vec4(uv_interp, 1.0, 1.0); +} + +/* clang-format off */ +#[fragment] + +#define M_PI 3.14159265359 + +#ifdef USE_GLES_OVER_GL +#define lowp +#define mediump +#define highp +#else +#if defined(USE_HIGHP_PRECISION) +precision highp float; +precision highp int; +#else +precision mediump float; +precision mediump int; +#endif +#endif + +in vec2 uv_interp; + +/* clang-format on */ + +uniform samplerCube radiance; //texunit:-1 +#ifdef USE_CUBEMAP_PASS +uniform samplerCube half_res; //texunit:-2 +uniform samplerCube quarter_res; //texunit:-3 +#else +uniform sampler2D half_res; //texunit:-2 +uniform sampler2D quarter_res; //texunit:-3 +#endif + +layout(std140) uniform CanvasData { //ubo:0 + mat3 orientation; + vec4 projection; + vec4 position_multiplier; + float time; + float luminance_multiplier; + float pad1; + float pad2; +}; + +layout(std140) uniform GlobalVariableData { //ubo:1 + vec4 global_variables[MAX_GLOBAL_VARIABLES]; +}; + +struct DirectionalLightData { + vec4 direction_energy; + vec4 color_size; + bool enabled; +}; + +layout(std140) uniform DirectionalLights { //ubo:2 + DirectionalLightData data[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS]; +} +directional_lights; + +#ifdef MATERIAL_UNIFORMS_USED +layout(std140) uniform MaterialUniforms{ +//ubo:3 + +#MATERIAL_UNIFORMS + +} material; +#endif + +#GLOBALS + +#ifdef USE_CUBEMAP_PASS +#define AT_CUBEMAP_PASS true +#else +#define AT_CUBEMAP_PASS false +#endif + +#ifdef USE_HALF_RES_PASS +#define AT_HALF_RES_PASS true +#else +#define AT_HALF_RES_PASS false +#endif + +#ifdef USE_QUARTER_RES_PASS +#define AT_QUARTER_RES_PASS true +#else +#define AT_QUARTER_RES_PASS false +#endif + +layout(location = 0) out vec4 frag_color; + +void main() { + vec3 cube_normal; + cube_normal.z = -1.0; + cube_normal.x = (uv_interp.x + projection.x) / projection.y; + cube_normal.y = (-uv_interp.y - projection.z) / projection.w; + cube_normal = mat3(orientation) * cube_normal; + cube_normal.z = -cube_normal.z; + cube_normal = normalize(cube_normal); + + vec2 uv = uv_interp * 0.5 + 0.5; + + vec2 panorama_coords = vec2(atan(cube_normal.x, cube_normal.z), acos(cube_normal.y)); + + if (panorama_coords.x < 0.0) { + panorama_coords.x += M_PI * 2.0; + } + + panorama_coords /= vec2(M_PI * 2.0, M_PI); + + vec3 color = vec3(0.0, 0.0, 0.0); + float alpha = 1.0; // Only available to subpasses + vec4 half_res_color = vec4(1.0); + vec4 quarter_res_color = vec4(1.0); + vec4 custom_fog = vec4(0.0); + +#ifdef USE_CUBEMAP_PASS + vec3 inverted_cube_normal = cube_normal; + inverted_cube_normal.z *= -1.0; +#ifdef USES_HALF_RES_COLOR + half_res_color = texture(samplerCube(half_res, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), inverted_cube_normal) * luminance_multiplier; +#endif +#ifdef USES_QUARTER_RES_COLOR + quarter_res_color = texture(samplerCube(quarter_res, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), inverted_cube_normal) * luminance_multiplier; +#endif +#else +#ifdef USES_HALF_RES_COLOR + half_res_color = textureLod(sampler2D(half_res, material_samplers[SAMPLER_LINEAR_CLAMP]), uv, 0.0) * luminance_multiplier; +#endif +#ifdef USES_QUARTER_RES_COLOR + quarter_res_color = textureLod(sampler2D(quarter_res, material_samplers[SAMPLER_LINEAR_CLAMP]), uv, 0.0) * luminance_multiplier; +#endif +#endif + + { + +#CODE : SKY + + } + + frag_color.rgb = color * position_multiplier.w / luminance_multiplier; + frag_color.a = alpha; + + // Blending is disabled for Sky, so alpha doesn't blend + // alpha is used for subsurface scattering so make sure it doesn't get applied to Sky + if (!AT_CUBEMAP_PASS && !AT_HALF_RES_PASS && !AT_QUARTER_RES_PASS) { + frag_color.a = 0.0; + } +} |