Cleanup shaders

This commit is contained in:
twinaphex 2016-05-28 18:18:23 +02:00
parent 2b5aae8a21
commit 653359911a
18 changed files with 322 additions and 250 deletions

View File

@ -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);
}
);

View File

@ -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;
}
);

View File

@ -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);
}
);

View File

@ -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;
}
);

View File

@ -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);
}
);

View File

@ -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;
}
);

View File

@ -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;
}
);

View File

@ -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);
}
);

View File

@ -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);
}
);

View File

@ -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;
}
);

View File

@ -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);
}
);

View File

@ -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;
}
);

View File

@ -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"

View File

@ -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);
}
);

View File

@ -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)
}
);

View File

@ -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);
}
);

View File

@ -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);
}
);

View File

@ -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