From 653359911adbe2abcc29f8f5d3f91948086c5de6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 28 May 2016 18:18:23 +0200 Subject: [PATCH] Cleanup shaders --- .../gl_shaders/core_alpha_blend.glsl.frag.h | 20 +++-- .../gl_shaders/core_alpha_blend.glsl.vert.h | 28 +++--- .../gl_shaders/core_opaque.glsl.frag.h | 18 ++-- .../gl_shaders/core_opaque.glsl.vert.h | 24 +++--- .../gl_shaders/legacy_opaque.glsl.frag.h | 16 ++-- .../gl_shaders/legacy_opaque.glsl.vert.h | 18 ++-- .../legacy_pipeline_xmb_ribbon.glsl.vert.h | 85 ++++++++++--------- ...acy_pipeline_xmb_ribbon_simple.glsl.vert.h | 62 +++++++------- .../gl_shaders/modern_alpha_blend.glsl.frag.h | 23 ++--- .../gl_shaders/modern_alpha_blend.glsl.vert.h | 35 ++++---- .../gl_shaders/modern_opaque.glsl.frag.h | 22 +++-- .../gl_shaders/modern_opaque.glsl.vert.h | 24 +++--- .../modern_pipeline_xmb_ribbon.glsl.vert.h | 6 +- ...ern_pipeline_xmb_ribbon_simple.glsl.vert.h | 62 +++++++------- gfx/drivers/gl_shaders/opaque.cg.h | 63 +++++++------- .../pipeline_xmb_ribbon.glsl.frag.h | 36 ++++---- .../pipeline_xmb_ribbon_simple.glsl.frag.h | 22 +++-- gfx/drivers/gl_shaders/shaders_common.h | 8 ++ 18 files changed, 322 insertions(+), 250 deletions(-) create mode 100644 gfx/drivers/gl_shaders/shaders_common.h diff --git a/gfx/drivers/gl_shaders/core_alpha_blend.glsl.frag.h b/gfx/drivers/gl_shaders/core_alpha_blend.glsl.frag.h index d324e14336..f114cf33d8 100644 --- a/gfx/drivers/gl_shaders/core_alpha_blend.glsl.frag.h +++ b/gfx/drivers/gl_shaders/core_alpha_blend.glsl.frag.h @@ -1,8 +1,12 @@ -static const char *stock_fragment_core_blend = - "uniform sampler2D Texture;\n" - "in vec2 tex_coord;\n" - "in vec4 color;\n" - "out vec4 FragColor;\n" - "void main() {\n" - " FragColor = color * texture(Texture, tex_coord);\n" - "}"; +#include "shaders_common.h" + +static const char *stock_fragment_core_blend = GLSL( + uniform sampler2D Texture; + in vec2 tex_coord; + in vec4 color; + out vec4 FragColor; + + void main() { + FragColor = color * texture(Texture, tex_coord); + } +); diff --git a/gfx/drivers/gl_shaders/core_alpha_blend.glsl.vert.h b/gfx/drivers/gl_shaders/core_alpha_blend.glsl.vert.h index 8e7bad2e83..4f50e836f7 100644 --- a/gfx/drivers/gl_shaders/core_alpha_blend.glsl.vert.h +++ b/gfx/drivers/gl_shaders/core_alpha_blend.glsl.vert.h @@ -1,12 +1,16 @@ -static const char *stock_vertex_core_blend = - "in vec2 TexCoord;\n" - "in vec2 VertexCoord;\n" - "in vec4 Color;\n" - "uniform mat4 MVPMatrix;\n" - "out vec2 tex_coord;\n" - "out vec4 color;\n" - "void main() {\n" - " gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0);\n" - " tex_coord = TexCoord;\n" - " color = Color;\n" - "}"; +#include "shaders_common.h" + +static const char *stock_vertex_core_blend = GLSL( + in vec2 TexCoord; + in vec2 VertexCoord; + in vec4 Color; + uniform mat4 MVPMatrix; + out vec2 tex_coord; + out vec4 color; + + void main() { + gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0); + tex_coord = TexCoord; + color = Color; + } +); diff --git a/gfx/drivers/gl_shaders/core_opaque.glsl.frag.h b/gfx/drivers/gl_shaders/core_opaque.glsl.frag.h index 7074aac0b3..ed3dc1ceed 100644 --- a/gfx/drivers/gl_shaders/core_opaque.glsl.frag.h +++ b/gfx/drivers/gl_shaders/core_opaque.glsl.frag.h @@ -1,7 +1,11 @@ -static const char *stock_fragment_core = - "uniform sampler2D Texture;\n" - "in vec2 tex_coord;\n" - "out vec4 FragColor;\n" - "void main() {\n" - " FragColor = vec4(texture(Texture, tex_coord).rgb, 1.0);\n" - "}"; +#include "shaders_common.h" + +static const char *stock_fragment_core = GLSL( + uniform sampler2D Texture; + in vec2 tex_coord; + out vec4 FragColor; + + void main() { + FragColor = vec4(texture(Texture, tex_coord).rgb, 1.0); + } +); diff --git a/gfx/drivers/gl_shaders/core_opaque.glsl.vert.h b/gfx/drivers/gl_shaders/core_opaque.glsl.vert.h index eac8a11414..622ebf112b 100644 --- a/gfx/drivers/gl_shaders/core_opaque.glsl.vert.h +++ b/gfx/drivers/gl_shaders/core_opaque.glsl.vert.h @@ -1,10 +1,14 @@ -static const char *stock_vertex_core = - "in vec2 TexCoord;\n" - "in vec2 VertexCoord;\n" - "in vec4 Color;\n" - "uniform mat4 MVPMatrix;\n" - "out vec2 tex_coord;\n" - "void main() {\n" - " gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0);\n" - " tex_coord = TexCoord;\n" - "}"; +#include "shaders_common.h" + +static const char *stock_vertex_core = GLSL( + in vec2 TexCoord; + in vec2 VertexCoord; + in vec4 Color; + uniform mat4 MVPMatrix; + out vec2 tex_coord; + + void main() { + gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0); + tex_coord = TexCoord; + } +); diff --git a/gfx/drivers/gl_shaders/legacy_opaque.glsl.frag.h b/gfx/drivers/gl_shaders/legacy_opaque.glsl.frag.h index 4c8850853a..7d1d90cf06 100644 --- a/gfx/drivers/gl_shaders/legacy_opaque.glsl.frag.h +++ b/gfx/drivers/gl_shaders/legacy_opaque.glsl.frag.h @@ -1,6 +1,10 @@ -static const char *stock_fragment_legacy = - "uniform sampler2D Texture;\n" - "varying vec4 color;\n" - "void main() {\n" - " gl_FragColor = color * texture2D(Texture, gl_TexCoord[0].xy);\n" - "}"; +#include "shaders_common.h" + +static const char *stock_fragment_legacy = GLSL( + uniform sampler2D Texture; + varying vec4 color; + + void main() { + gl_FragColor = color * texture2D(Texture, gl_TexCoord[0].xy); + } +); diff --git a/gfx/drivers/gl_shaders/legacy_opaque.glsl.vert.h b/gfx/drivers/gl_shaders/legacy_opaque.glsl.vert.h index 93f3042b7e..b862d600f1 100644 --- a/gfx/drivers/gl_shaders/legacy_opaque.glsl.vert.h +++ b/gfx/drivers/gl_shaders/legacy_opaque.glsl.vert.h @@ -1,7 +1,11 @@ -static const char *stock_vertex_legacy = - "varying vec4 color;\n" - "void main() {\n" - " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" - " gl_TexCoord[0] = gl_MultiTexCoord0;\n" - " color = gl_Color;\n" - "}"; +#include "shaders_common.h" + +static const char *stock_vertex_legacy = GLSL( + varying vec4 color; + + void main() { + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + gl_TexCoord[0] = gl_MultiTexCoord0; + color = gl_Color; + } +); diff --git a/gfx/drivers/gl_shaders/legacy_pipeline_xmb_ribbon.glsl.vert.h b/gfx/drivers/gl_shaders/legacy_pipeline_xmb_ribbon.glsl.vert.h index f3f6954d6d..df61461af8 100644 --- a/gfx/drivers/gl_shaders/legacy_pipeline_xmb_ribbon.glsl.vert.h +++ b/gfx/drivers/gl_shaders/legacy_pipeline_xmb_ribbon.glsl.vert.h @@ -1,45 +1,50 @@ -static const char *stock_vertex_xmb_legacy = - "#define COMPAT_VARYING varying\n" - "#define COMPAT_ATTRIBUTE attribute\n" - "COMPAT_ATTRIBUTE vec3 VertexCoord;\n" - "uniform float time;\n" - "COMPAT_VARYING vec3 fragVertexEc;\n" - "float iqhash( float n )\n" - "{\n" - " return fract(sin(n)*43758.5453);\n" - "}\n" - "float noise( vec3 x )\n" - "{\n" - " vec3 p = floor(x);\n" - " vec3 f = fract(x);\n" - " f = f*f*(3.0-2.0*f);\n" - " float n = p.x + p.y*57.0 + 113.0*p.z;\n" - " return mix(mix(mix( iqhash(n+0.0 ), iqhash(n+1.0 ),f.x),\n" - " mix( iqhash(n+57.0 ), iqhash(n+58.0 ),f.x),f.y),\n" - " mix(mix( iqhash(n+113.0), iqhash(n+114.0),f.x),\n" - " mix( iqhash(n+170.0), iqhash(n+171.0),f.x),f.y),f.z);\n" - "}\n" - "float xmb_noise2( vec3 x )\n" - "{\n" - " return cos((x.z*1.0)*2.0);" - "}\n" - "void main()\n" - "{\n" - " vec3 v = vec3(VertexCoord.x, 0.0, VertexCoord.y);\n" - " vec3 v2 = v;\n" - " vec3 v3 = v;\n" +#include "shaders_common.h" - " v.y = xmb_noise2(v2)/6.0;\n" +static const char *stock_vertex_xmb_legacy = GLSL( + attribute vec3 VertexCoord; + uniform float time; + varying vec3 fragVertexEc; - " v3.x = v3.x + time/5.0;\n" - " v3.x = v3.x / 2.0;\n" + float iqhash( float n ) + { + return fract(sin(n)*43758.5453); + } - " v3.z = v3.z + time/10.0;\n" - " v3.y = v3.y + time/100.0;\n" + float noise( vec3 x ) + { + vec3 p = floor(x); + vec3 f = fract(x); + f = f*f*(3.0-2.0*f); + float n = p.x + p.y*57.0 + 113.0*p.z; + return mix(mix(mix( iqhash(n+0.0 ), iqhash(n+1.0 ),f.x), + mix( iqhash(n+57.0 ), iqhash(n+58.0 ),f.x),f.y), + mix(mix( iqhash(n+113.0), iqhash(n+114.0),f.x), + mix( iqhash(n+170.0), iqhash(n+171.0),f.x),f.y),f.z); + } - " v.z = v.z + noise(v3*7.0)/15.0;\n" - " v.y = v.y + noise(v3*7.0)/15.0 + cos(v.x*2.0-time/5.0)/5.0 - 0.3;\n" + float xmb_noise2( vec3 x ) + { + return cos((x.z*1.0)*2.0); + } - " gl_Position = vec4(v, 1.0);\n" - " fragVertexEc = gl_Position.xyz;\n" - "}\n"; + void main() + { + vec3 v = vec3(VertexCoord.x, 0.0, VertexCoord.y); + vec3 v2 = v; + vec3 v3 = v; + + v.y = xmb_noise2(v2)/6.0; + + v3.x = v3.x + time/5.0; + v3.x = v3.x / 2.0; + + v3.z = v3.z + time/10.0; + v3.y = v3.y + time/100.0; + + v.z = v.z + noise(v3*7.0)/15.0; + v.y = v.y + noise(v3*7.0)/15.0 + cos(v.x*2.0-time/5.0)/5.0 - 0.3; + + gl_Position = vec4(v, 1.0); + fragVertexEc = gl_Position.xyz; + } +); diff --git a/gfx/drivers/gl_shaders/legacy_pipeline_xmb_ribbon_simple.glsl.vert.h b/gfx/drivers/gl_shaders/legacy_pipeline_xmb_ribbon_simple.glsl.vert.h index 41c26eef18..1713451fd2 100644 --- a/gfx/drivers/gl_shaders/legacy_pipeline_xmb_ribbon_simple.glsl.vert.h +++ b/gfx/drivers/gl_shaders/legacy_pipeline_xmb_ribbon_simple.glsl.vert.h @@ -1,29 +1,33 @@ -static const char *stock_vertex_xmb_simple_legacy = - "#define COMPAT_VARYING varying\n" - "#define COMPAT_ATTRIBUTE attribute\n" - "COMPAT_ATTRIBUTE vec3 VertexCoord;\n" - "uniform float time;\n" - "float iqhash( float n )\n" - "{\n" - " return fract(sin(n)*43758.5453);\n" - "}\n" - "float noise( vec3 x )\n" - "{\n" - " vec3 p = floor(x);\n" - " vec3 f = fract(x);\n" - " f = f*f*(3.0-2.0*f);\n" - " float n = p.x + p.y*57.0 + 113.0*p.z;\n" - " return mix(mix(mix( iqhash(n+0.0 ), iqhash(n+1.0 ),f.x),\n" - " mix( iqhash(n+57.0 ), iqhash(n+58.0 ),f.x),f.y),\n" - " mix(mix( iqhash(n+113.0), iqhash(n+114.0),f.x),\n" - " mix( iqhash(n+170.0), iqhash(n+171.0),f.x),f.y),f.z);\n" - "}\n" - "void main()\n" - "{\n" - " vec3 v = vec3(VertexCoord.x, 0.0, VertexCoord.y);\n" - " vec3 v2 = v;\n" - " v2.x = v2.x + time/2.0;\n" - " v2.z = v.z * 3.0;\n" - " v.y = -cos((v.x+v.z/3.0+time)*2.0)/10.0 - noise(v2.xyz)/4.0;\n" - " gl_Position = vec4(v, 1.0);\n" - "}\n"; +#include "shaders_common.h" + +static const char *stock_vertex_xmb_simple_legacy = GLSL( + attribute vec3 VertexCoord; + uniform float time; + float iqhash( float n ) + { + return fract(sin(n)*43758.5453); + } + + float noise( vec3 x ) + { + vec3 p = floor(x); + vec3 f = fract(x); + f = f*f*(3.0-2.0*f); + float n = p.x + p.y*57.0 + 113.0*p.z; + + return mix(mix(mix( iqhash(n+0.0 ), iqhash(n+1.0 ),f.x), + mix( iqhash(n+57.0 ), iqhash(n+58.0 ),f.x),f.y), + mix(mix( iqhash(n+113.0), iqhash(n+114.0),f.x), + mix( iqhash(n+170.0), iqhash(n+171.0),f.x),f.y),f.z); + } + + void main() + { + vec3 v = vec3(VertexCoord.x, 0.0, VertexCoord.y); + vec3 v2 = v; + v2.x = v2.x + time/2.0; + v2.z = v.z * 3.0; + v.y = -cos((v.x+v.z/3.0+time)*2.0)/10.0 - noise(v2.xyz)/4.0; + gl_Position = vec4(v, 1.0); + } +); diff --git a/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.frag.h b/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.frag.h index 5ceed75833..5c88721dd6 100644 --- a/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.frag.h +++ b/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.frag.h @@ -1,10 +1,13 @@ -static const char *stock_fragment_modern_blend = - "#ifdef GL_ES\n" - "precision mediump float;\n" - "#endif\n" - "uniform sampler2D Texture;\n" - "varying vec2 tex_coord;\n" - "varying vec4 color;\n" - "void main() {\n" - " gl_FragColor = color * texture2D(Texture, tex_coord);\n" - "}"; +#include "shaders_common.h" + +static const char *stock_fragment_modern_blend = GLSL( + #ifdef GL_ES + precision mediump float; + #endif + uniform sampler2D Texture; + varying vec2 tex_coord; + varying vec4 color; + void main() { + gl_FragColor = color * texture2D(Texture, tex_coord); + } +); diff --git a/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.vert.h b/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.vert.h index 201bb50909..6d908c8bba 100644 --- a/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.vert.h +++ b/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.vert.h @@ -1,15 +1,20 @@ -static const char *stock_vertex_modern_blend = - "#ifdef GL_ES\n" - "precision mediump float;\n" - "#endif\n" - "attribute vec2 TexCoord;\n" - "attribute vec2 VertexCoord;\n" - "attribute vec4 Color;\n" - "uniform mat4 MVPMatrix;\n" - "varying vec2 tex_coord;\n" - "varying vec4 color;\n" - "void main() {\n" - " gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0);\n" - " tex_coord = TexCoord;\n" - " color = Color;\n" - "}"; +#include "shaders_common.h" + +static const char *stock_vertex_modern_blend = GLSL( + #ifdef GL_ES + precision mediump float; + #endif + + attribute vec2 TexCoord; + attribute vec2 VertexCoord; + attribute vec4 Color; + uniform mat4 MVPMatrix; + varying vec2 tex_coord; + varying vec4 color; + + void main() { + gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0); + tex_coord = TexCoord; + color = Color; + } +); diff --git a/gfx/drivers/gl_shaders/modern_opaque.glsl.frag.h b/gfx/drivers/gl_shaders/modern_opaque.glsl.frag.h index 186546902e..050cd3152c 100644 --- a/gfx/drivers/gl_shaders/modern_opaque.glsl.frag.h +++ b/gfx/drivers/gl_shaders/modern_opaque.glsl.frag.h @@ -1,9 +1,13 @@ -static const char *stock_fragment_modern = - "#ifdef GL_ES\n" - "precision mediump float;\n" - "#endif\n" - "uniform sampler2D Texture;\n" - "varying vec2 tex_coord;\n" - "void main() {\n" - " gl_FragColor = vec4(texture2D(Texture, tex_coord).rgb, 1.0);\n" - "}"; +#include "shaders_common.h" + +static const char *stock_fragment_modern = GLSL( + #ifdef GL_ES + precision mediump float; + #endif + uniform sampler2D Texture; + varying vec2 tex_coord; + + void main() { + gl_FragColor = vec4(texture2D(Texture, tex_coord).rgb, 1.0); + } +); diff --git a/gfx/drivers/gl_shaders/modern_opaque.glsl.vert.h b/gfx/drivers/gl_shaders/modern_opaque.glsl.vert.h index fd5d93aafe..751375794b 100644 --- a/gfx/drivers/gl_shaders/modern_opaque.glsl.vert.h +++ b/gfx/drivers/gl_shaders/modern_opaque.glsl.vert.h @@ -1,12 +1,16 @@ +#include "shaders_common.h" + /* Need to duplicate these to work around broken stuff on Android. * Must enforce alpha = 1.0 or 32-bit games can potentially go black. */ -static const char *stock_vertex_modern = - "attribute vec2 TexCoord;\n" - "attribute vec2 VertexCoord;\n" - "attribute vec4 Color;\n" - "uniform mat4 MVPMatrix;\n" - "varying vec2 tex_coord;\n" - "void main() {\n" - " gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0);\n" - " tex_coord = TexCoord;\n" - "}"; +static const char *stock_vertex_modern = GLSL( + attribute vec2 TexCoord; + attribute vec2 VertexCoord; + attribute vec4 Color; + uniform mat4 MVPMatrix; + varying vec2 tex_coord; + + void main() { + gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0); + tex_coord = TexCoord; + } +); diff --git a/gfx/drivers/gl_shaders/modern_pipeline_xmb_ribbon.glsl.vert.h b/gfx/drivers/gl_shaders/modern_pipeline_xmb_ribbon.glsl.vert.h index 2bd5e2ddbf..e69a81b803 100644 --- a/gfx/drivers/gl_shaders/modern_pipeline_xmb_ribbon.glsl.vert.h +++ b/gfx/drivers/gl_shaders/modern_pipeline_xmb_ribbon.glsl.vert.h @@ -1,9 +1,7 @@ static const char *stock_vertex_xmb_modern = - "#define COMPAT_VARYING out\n" - "#define COMPAT_ATTRIBUTE in\n" - "COMPAT_ATTRIBUTE vec3 VertexCoord;\n" + "in vec3 VertexCoord;\n" "uniform float time;\n" - "COMPAT_VARYING vec3 fragVertexEc;\n" + "out vec3 fragVertexEc;\n" "float iqhash( float n )\n" "{\n" " return fract(sin(n)*43758.5453);\n" diff --git a/gfx/drivers/gl_shaders/modern_pipeline_xmb_ribbon_simple.glsl.vert.h b/gfx/drivers/gl_shaders/modern_pipeline_xmb_ribbon_simple.glsl.vert.h index b57c396586..56eb24a16e 100644 --- a/gfx/drivers/gl_shaders/modern_pipeline_xmb_ribbon_simple.glsl.vert.h +++ b/gfx/drivers/gl_shaders/modern_pipeline_xmb_ribbon_simple.glsl.vert.h @@ -1,29 +1,33 @@ -static const char *stock_vertex_xmb_simple_modern = - "#define COMPAT_VARYING out\n" - "#define COMPAT_ATTRIBUTE in\n" - "COMPAT_ATTRIBUTE vec3 VertexCoord;\n" - "uniform float time;\n" - "float iqhash( float n )\n" - "{\n" - " return fract(sin(n)*43758.5453);\n" - "}\n" - "float noise( vec3 x )\n" - "{\n" - " vec3 p = floor(x);\n" - " vec3 f = fract(x);\n" - " f = f*f*(3.0-2.0*f);\n" - " float n = p.x + p.y*57.0 + 113.0*p.z;\n" - " return mix(mix(mix( iqhash(n+0.0 ), iqhash(n+1.0 ),f.x),\n" - " mix( iqhash(n+57.0 ), iqhash(n+58.0 ),f.x),f.y),\n" - " mix(mix( iqhash(n+113.0), iqhash(n+114.0),f.x),\n" - " mix( iqhash(n+170.0), iqhash(n+171.0),f.x),f.y),f.z);\n" - "}\n" - "void main()\n" - "{\n" - " vec3 v = vec3(VertexCoord.x, 0.0, VertexCoord.y);\n" - " vec3 v2 = v;\n" - " v2.x = v2.x + time/2.0;\n" - " v2.z = v.z * 3.0;\n" - " v.y = -cos((v.x+v.z/3.0+time)*2.0)/10.0 - noise(v2.xyz)/4.0;\n" - " gl_Position = vec4(v, 1.0);\n" - "}\n"; +#include "shaders_common.h" + +static const char *stock_vertex_xmb_simple_modern = GLSL( + in vec3 VertexCoord; + uniform float time; + + float iqhash( float n ) + { + return fract(sin(n)*43758.5453); + } + + float noise( vec3 x ) + { + vec3 p = floor(x); + vec3 f = fract(x); + f = f*f*(3.0-2.0*f); + float n = p.x + p.y*57.0 + 113.0*p.z; + return mix(mix(mix( iqhash(n+0.0 ), iqhash(n+1.0 ),f.x), + mix( iqhash(n+57.0 ), iqhash(n+58.0 ),f.x),f.y), + mix(mix( iqhash(n+113.0), iqhash(n+114.0),f.x), + mix( iqhash(n+170.0), iqhash(n+171.0),f.x),f.y),f.z); + } + + void main() + { + vec3 v = vec3(VertexCoord.x, 0.0, VertexCoord.y); + vec3 v2 = v; + v2.x = v2.x + time/2.0; + v2.z = v.z * 3.0; + v.y = -cos((v.x+v.z/3.0+time)*2.0)/10.0 - noise(v2.xyz)/4.0; + gl_Position = vec4(v, 1.0); + } +); diff --git a/gfx/drivers/gl_shaders/opaque.cg.h b/gfx/drivers/gl_shaders/opaque.cg.h index d55a265ade..61ce53c422 100644 --- a/gfx/drivers/gl_shaders/opaque.cg.h +++ b/gfx/drivers/gl_shaders/opaque.cg.h @@ -1,29 +1,34 @@ -static const char *stock_cg_gl_program = - "struct input" - "{" - " float2 tex_coord;" - " float4 color;" - " float4 vertex_coord;" - " uniform float4x4 mvp_matrix;" - " uniform sampler2D texture;" - "};" - "struct vertex_data" - "{" - " float2 tex;" - " float4 color;" - "};" - "void main_vertex" - "(" - " out float4 oPosition : POSITION," - " input IN," - " out vertex_data vert" - ")" - "{" - " oPosition = mul(IN.mvp_matrix, IN.vertex_coord);" - " vert = vertex_data(IN.tex_coord, IN.color);" - "}" - "" - "float4 main_fragment(input IN, vertex_data vert, uniform sampler2D s0 : TEXUNIT0) : COLOR" - "{" - " return vert.color * tex2D(s0, vert.tex);" - "}"; +#include "shaders_common.h" + +static const char *stock_cg_gl_program = GLSL( + struct input + { + float2 tex_coord; + float4 color; + float4 vertex_coord; + uniform float4x4 mvp_matrix; + uniform sampler2D texture; + }; + + struct vertex_data + { + float2 tex; + float4 color; + }; + + void main_vertex + ( + out float4 oPosition : POSITION, + input IN, + out vertex_data vert + ) + { + oPosition = mul(IN.mvp_matrix, IN.vertex_coord); + vert = vertex_data(IN.tex_coord, IN.color); + } + + float4 main_fragment(input IN, vertex_data vert, uniform sampler2D s0 : TEXUNIT0) : COLOR + { + return vert.color * tex2D(s0, vert.tex) + } +); diff --git a/gfx/drivers/gl_shaders/pipeline_xmb_ribbon.glsl.frag.h b/gfx/drivers/gl_shaders/pipeline_xmb_ribbon.glsl.frag.h index 6bd4076ee8..5c4fdca337 100644 --- a/gfx/drivers/gl_shaders/pipeline_xmb_ribbon.glsl.frag.h +++ b/gfx/drivers/gl_shaders/pipeline_xmb_ribbon.glsl.frag.h @@ -1,16 +1,20 @@ -static const char *stock_fragment_xmb = - "#ifdef GL_ES\n" - "precision mediump float;\n" - "#endif\n" - "uniform float time;\n" - "varying vec3 fragVertexEc;\n" - "vec3 up = vec3(0, 0, 1);\n" - "void main()\n" - "{\n" - " vec3 X = dFdx(fragVertexEc);\n" - " vec3 Y = dFdy(fragVertexEc);\n" - " vec3 normal=normalize(cross(X,Y));\n" - " float c = (1.0 - dot(normal, up));\n" - " c = (1.0 - cos(c*c))/3.0;\n" - " gl_FragColor = vec4(1.0, 1.0, 1.0, c);\n" - "}\n"; +#include "shaders_common.h" + +static const char *stock_fragment_xmb = GLSL( + #ifdef GL_ES + precision mediump float; + #endif + uniform float time; + varying vec3 fragVertexEc; + vec3 up = vec3(0, 0, 1); + + void main() + { + vec3 X = dFdx(fragVertexEc); + vec3 Y = dFdy(fragVertexEc); + vec3 normal=normalize(cross(X,Y)); + float c = (1.0 - dot(normal, up)); + c = (1.0 - cos(c*c))/3.0; + gl_FragColor = vec4(1.0, 1.0, 1.0, c); + } +); diff --git a/gfx/drivers/gl_shaders/pipeline_xmb_ribbon_simple.glsl.frag.h b/gfx/drivers/gl_shaders/pipeline_xmb_ribbon_simple.glsl.frag.h index 4d09824da0..1550c5ad50 100644 --- a/gfx/drivers/gl_shaders/pipeline_xmb_ribbon_simple.glsl.frag.h +++ b/gfx/drivers/gl_shaders/pipeline_xmb_ribbon_simple.glsl.frag.h @@ -1,9 +1,13 @@ -static const char *stock_fragment_xmb_simple = - "#ifdef GL_ES\n" - "precision mediump float;\n" - "#endif\n" - "uniform float time;\n" - "void main()\n" - "{\n" - " gl_FragColor = vec4(1.0, 1.0, 1.0, 0.05);\n" - "}\n"; +#include "shaders_common.h" + +static const char *stock_fragment_xmb_simple = GLSL( + #ifdef GL_ES + precision mediump float; + #endif + uniform float time; + + void main() + { + gl_FragColor = vec4(1.0, 1.0, 1.0, 0.05); + } +); diff --git a/gfx/drivers/gl_shaders/shaders_common.h b/gfx/drivers/gl_shaders/shaders_common.h new file mode 100644 index 0000000000..21138948c2 --- /dev/null +++ b/gfx/drivers/gl_shaders/shaders_common.h @@ -0,0 +1,8 @@ +#ifndef _SHADERS_COMMON +#define _SHADERS_COMMON + +#define GLSL(src) "" #src + +#define GLSL_330_CORE(src) "#version 330 core\n" #src + +#endif