From 7e31e71d5be4954dc995ba083fb452b692b7182f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 15 Jun 2016 20:54:37 +0200 Subject: [PATCH] Split up more into files --- cores/libretro-ffmpeg/fft/fft.cpp | 65 +------------------ ...fft_fragment_program_heightmap.glsl.frag.h | 18 +++++ .../gl_shaders/fft_vertex_program.glsl.vert.h | 1 + .../fft_vertex_program_heightmap.glsl.vert.h | 43 ++++++++++++ .../fft/gl_shaders/shaders_common.h | 4 +- 5 files changed, 66 insertions(+), 65 deletions(-) create mode 100644 cores/libretro-ffmpeg/fft/gl_shaders/fft_fragment_program_heightmap.glsl.frag.h create mode 100644 cores/libretro-ffmpeg/fft/gl_shaders/fft_vertex_program_heightmap.glsl.vert.h diff --git a/cores/libretro-ffmpeg/fft/fft.cpp b/cores/libretro-ffmpeg/fft/fft.cpp index 1c6bdeefb6..993f9470ee 100644 --- a/cores/libretro-ffmpeg/fft/fft.cpp +++ b/cores/libretro-ffmpeg/fft/fft.cpp @@ -89,67 +89,8 @@ typedef struct GLFFT unsigned depth; } glfft_t; -static const char vertex_program_heightmap[] = - "#version 300 es\n" - "layout(location = 0) in vec2 aVertex;\n" - "uniform sampler2D sHeight;\n" - "uniform mat4 uMVP;\n" - "uniform ivec2 uOffset;\n" - "uniform vec4 uHeightmapParams;\n" - "uniform float uAngleScale;\n" - "out vec3 vWorldPos;\n" - "out vec3 vHeight;\n" - - "#define PI 3.141592653\n" - - "void main() {\n" - " vec2 tex_coord = vec2(aVertex.x + float(uOffset.x) + 0.5, -aVertex.y + float(uOffset.y) + 0.5) / vec2(textureSize(sHeight, 0));\n" - - " vec3 world_pos = vec3(aVertex.x, 0.0, aVertex.y);\n" - " world_pos.xz += uHeightmapParams.xy;\n" - - " float angle = world_pos.x * uAngleScale;\n" - " world_pos.xz *= uHeightmapParams.zw;\n" - - " float lod = log2(world_pos.z + 1.0) - 6.0;\n" - " vec4 heights = textureLod(sHeight, tex_coord, lod);\n" - - " float cangle = cos(angle);\n" - " float sangle = sin(angle);\n" - - " int c = int(-sign(world_pos.x) + 1.0);\n" - " float height = mix(heights[c], heights[1], abs(angle) / PI);\n" - " height = height * 80.0 - 40.0;\n" - - " vec3 up = vec3(-sangle, cangle, 0.0);\n" - - " float base_y = 80.0 - 80.0 * cangle;\n" - " float base_x = 80.0 * sangle;\n" - " world_pos.xy = vec2(base_x, base_y);\n" - " world_pos += up * height;\n" - - " vWorldPos = world_pos;\n" - " vHeight = vec3(height, heights.yw * 80.0 - 40.0);\n" - " gl_Position = uMVP * vec4(world_pos, 1.0);\n" - "}"; - -static const char fragment_program_heightmap[] = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 FragColor;\n" - "in vec3 vWorldPos;\n" - "in vec3 vHeight;\n" - - "vec3 colormap(vec3 height) {\n" - " return 1.0 / (1.0 + exp(-0.08 * height));\n" - "}" - - "void main() {\n" - " vec3 color = mix(vec3(1.0, 0.7, 0.7) * colormap(vHeight), vec3(0.1, 0.15, 0.1), clamp(vWorldPos.z / 400.0, 0.0, 1.0));\n" - " color = mix(color, vec3(0.1, 0.15, 0.1), clamp(1.0 - vWorldPos.z / 2.0, 0.0, 1.0));\n" - " FragColor = vec4(color, 1.0);\n" - "}"; - +#include "gl_shaders/fft_vertex_program_heightmap.glsl.vert.h" +#include "gl_shaders/fft_fragment_program_heightmap.glsl.frag.h" #include "gl_shaders/fft_vertex_program.glsl.vert.h" static const char fragment_program_resolve[] = @@ -706,7 +647,7 @@ static void fft_init_block(glfft_t *fft) int pos = 0; fft->block.prog = fft_compile_program(fft, - vertex_program_heightmap, fragment_program_heightmap); + fft_vertex_program_heightmap, fft_fragment_program_heightmap); glUseProgram(fft->block.prog); glUniform1i(glGetUniformLocation(fft->block.prog, "sHeight"), 0); diff --git a/cores/libretro-ffmpeg/fft/gl_shaders/fft_fragment_program_heightmap.glsl.frag.h b/cores/libretro-ffmpeg/fft/gl_shaders/fft_fragment_program_heightmap.glsl.frag.h new file mode 100644 index 0000000000..8915e3d61e --- /dev/null +++ b/cores/libretro-ffmpeg/fft/gl_shaders/fft_fragment_program_heightmap.glsl.frag.h @@ -0,0 +1,18 @@ +#include "shaders_common.h" + +static const char *fft_fragment_program_heightmap = GLSL_300( + precision mediump float; + out vec4 FragColor; + in vec3 vWorldPos; + in vec3 vHeight; + + vec3 colormap(vec3 height) { + return 1.0 / (1.0 + exp(-0.08 * height)); + } + + void main() { + vec3 color = mix(vec3(1.0, 0.7, 0.7) * colormap(vHeight), vec3(0.1, 0.15, 0.1), clamp(vWorldPos.z / 400.0, 0.0, 1.0)); + color = mix(color, vec3(0.1, 0.15, 0.1), clamp(1.0 - vWorldPos.z / 2.0, 0.0, 1.0)); + FragColor = vec4(color, 1.0); + } +); diff --git a/cores/libretro-ffmpeg/fft/gl_shaders/fft_vertex_program.glsl.vert.h b/cores/libretro-ffmpeg/fft/gl_shaders/fft_vertex_program.glsl.vert.h index 4f56c6667f..9bc86b7f79 100644 --- a/cores/libretro-ffmpeg/fft/gl_shaders/fft_vertex_program.glsl.vert.h +++ b/cores/libretro-ffmpeg/fft/gl_shaders/fft_vertex_program.glsl.vert.h @@ -1,6 +1,7 @@ #include "shaders_common.h" static const char *fft_vertex_program = GLSL_300( + precision mediump float; layout(location = 0) in vec2 aVertex; layout(location = 1) in vec2 aTexCoord; uniform vec4 uOffsetScale; diff --git a/cores/libretro-ffmpeg/fft/gl_shaders/fft_vertex_program_heightmap.glsl.vert.h b/cores/libretro-ffmpeg/fft/gl_shaders/fft_vertex_program_heightmap.glsl.vert.h new file mode 100644 index 0000000000..a5ea0adb2e --- /dev/null +++ b/cores/libretro-ffmpeg/fft/gl_shaders/fft_vertex_program_heightmap.glsl.vert.h @@ -0,0 +1,43 @@ +#include "shaders_common.h" + +static const char *fft_vertex_program_heightmap = GLSL_300( + layout(location = 0) in vec2 aVertex; + uniform sampler2D sHeight; + uniform mat4 uMVP; + uniform ivec2 uOffset; + uniform vec4 uHeightmapParams; + uniform float uAngleScale; + out vec3 vWorldPos; + out vec3 vHeight; + + void main() { + vec2 tex_coord = vec2(aVertex.x + float(uOffset.x) + 0.5, -aVertex.y + float(uOffset.y) + 0.5) / vec2(textureSize(sHeight, 0)); + + vec3 world_pos = vec3(aVertex.x, 0.0, aVertex.y); + world_pos.xz += uHeightmapParams.xy; + + float angle = world_pos.x * uAngleScale; + world_pos.xz *= uHeightmapParams.zw; + + float lod = log2(world_pos.z + 1.0) - 6.0; + vec4 heights = textureLod(sHeight, tex_coord, lod); + + float cangle = cos(angle); + float sangle = sin(angle); + + int c = int(-sign(world_pos.x) + 1.0); + float height = mix(heights[c], heights[1], abs(angle) / 3.141592653); + height = height * 80.0 - 40.0; + + vec3 up = vec3(-sangle, cangle, 0.0); + + float base_y = 80.0 - 80.0 * cangle; + float base_x = 80.0 * sangle; + world_pos.xy = vec2(base_x, base_y); + world_pos += up * height; + + vWorldPos = world_pos; + vHeight = vec3(height, heights.yw * 80.0 - 40.0); + gl_Position = uMVP * vec4(world_pos, 1.0); + } +); diff --git a/cores/libretro-ffmpeg/fft/gl_shaders/shaders_common.h b/cores/libretro-ffmpeg/fft/gl_shaders/shaders_common.h index d3d27f0e6a..61b5ac1006 100644 --- a/cores/libretro-ffmpeg/fft/gl_shaders/shaders_common.h +++ b/cores/libretro-ffmpeg/fft/gl_shaders/shaders_common.h @@ -4,13 +4,11 @@ #if defined(HAVE_OPENGLES) #define CG(src) "" #src #define GLSL(src) "precision mediump float;\n" #src -#define GLSL_330(src) "#version 330 es\nprecision mediump float;\n" #src -#define GLSL_300(src) "#version 300 es\nprecision mediump float;\n" #src +#define GLSL_300(src) "#version 300 es\n" #src #else #define CG(src) "" #src #define GLSL(src) "" #src #define GLSL_300(src) "#version 300 es\n" #src -#define GLSL_330(src) "#version 330 core\n" #src #endif #endif