Created
December 31, 2019 15:43
-
-
Save jam1garner/4f4be82fc53077428a9a7a6959be4c62 to your computer and use it in GitHub Desktop.
Rivals of Aether shColorReplaceBlendExt shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LOWPREC lowp | |
#define MATRIX_VIEW 0 | |
#define MATRIX_PROJECTION 1 | |
#define MATRIX_WORLD 2 | |
#define MATRIX_WORLD_VIEW 3 | |
#define MATRIX_WORLD_VIEW_PROJECTION 4 | |
#define MATRICES_MAX 5 | |
uniform mat4 gm_Matrices[MATRICES_MAX]; | |
uniform bool gm_LightingEnabled; | |
uniform bool gm_VS_FogEnabled; | |
uniform float gm_FogStart; | |
uniform float gm_RcpFogRange; | |
#define MAX_VS_LIGHTS 8 | |
#define MIRROR_WIN32_LIGHTING_EQUATION | |
//#define MAX_VS_LIGHTS 8 | |
uniform vec4 gm_AmbientColour; // rgb=colour, a=1 | |
uniform vec4 gm_Lights_Direction[MAX_VS_LIGHTS]; // normalised direction | |
uniform vec4 gm_Lights_PosRange[MAX_VS_LIGHTS]; // X,Y,Z position, W range | |
uniform vec4 gm_Lights_Colour[MAX_VS_LIGHTS]; // rgb=colour, a=1 | |
float CalcFogFactor(vec4 pos) | |
{ | |
if (gm_VS_FogEnabled) | |
{ | |
vec4 viewpos = gm_Matrices[MATRIX_WORLD_VIEW] * pos; | |
float fogfactor = ((viewpos.z - gm_FogStart) * gm_RcpFogRange); | |
return fogfactor; | |
} | |
else | |
{ | |
return 0.0; | |
} | |
} | |
vec4 DoDirLight(vec3 ws_normal, vec4 dir, vec4 diffusecol) | |
{ | |
float dotresult = dot(ws_normal, dir.xyz); | |
dotresult = max(0.0, dotresult); | |
return dotresult * diffusecol; | |
} | |
vec4 DoPointLight(vec3 ws_pos, vec3 ws_normal, vec4 posrange, vec4 diffusecol) | |
{ | |
vec3 diffvec = ws_pos - posrange.xyz; | |
float veclen = length(diffvec); | |
diffvec /= veclen; // normalise | |
#ifdef MIRROR_WIN32_LIGHTING_EQUATION | |
// This is based on the Win32 D3D and OpenGL falloff model, where: | |
// Attenuation = 1.0f / (factor0 + (d * factor1) + (d*d * factor2)) | |
// For some reason, factor0 is set to 0.0f while factor1 is set to 1.0f/lightrange (on both D3D and OpenGL) | |
// This'll result in no visible falloff as 1.0f / (d / lightrange) will always be larger than 1.0f (if the vertex is within range) | |
float atten = 1.0 / (veclen / posrange.w); | |
if (veclen > posrange.w) | |
{ | |
atten = 0.0; | |
} | |
#else | |
float atten = clamp( (1.0 - (veclen / posrange.w)), 0.0, 1.0); // storing 1.0f/range instead would save a rcp | |
#endif | |
float dotresult = dot(ws_normal, diffvec); | |
dotresult = max(0.0, dotresult); | |
return dotresult * atten * diffusecol; | |
} | |
vec4 DoLighting(vec4 vertexcolour, vec4 objectspacepos, vec3 objectspacenormal) | |
{ | |
if (gm_LightingEnabled) | |
{ | |
// Normally we'd have the light positions\\directions back-transformed from world to object space | |
// But to keep things simple for the moment we'll just transform the normal to world space | |
vec4 objectspacenormal4 = vec4(objectspacenormal, 0.0); | |
vec3 ws_normal; | |
ws_normal = (gm_Matrices[MATRIX_WORLD_VIEW] * objectspacenormal4).xyz; | |
ws_normal = -normalize(ws_normal); | |
vec3 ws_pos; | |
ws_pos = (gm_Matrices[MATRIX_WORLD] * objectspacepos).xyz; | |
// Accumulate lighting from different light types | |
vec4 accumcol = vec4(0.0, 0.0, 0.0, 0.0); | |
for(int i = 0; i < MAX_VS_LIGHTS; i++) | |
{ | |
accumcol += DoDirLight(ws_normal, gm_Lights_Direction[i], gm_Lights_Colour[i]); | |
} | |
for(int i = 0; i < MAX_VS_LIGHTS; i++) | |
{ | |
accumcol += DoPointLight(ws_pos, ws_normal, gm_Lights_PosRange[i], gm_Lights_Colour[i]); | |
} | |
accumcol *= vertexcolour; | |
accumcol += gm_AmbientColour; | |
accumcol = min(vec4(1.0, 1.0, 1.0, 1.0), accumcol); | |
accumcol.a = vertexcolour.a; | |
return accumcol; | |
} | |
else | |
{ | |
return vertexcolour; | |
} | |
} | |
#define _YY_GLSLES_ 1 | |
// | |
// Simple passthrough vertex shader | |
// | |
attribute vec3 in_Position; // (x,y,z) | |
attribute vec4 in_Colour; // (r,g,b,a) | |
attribute vec2 in_TextureCoord; // (u,v) | |
//attribute vec3 in_Normal; // (x,y,z) unused in this shader. | |
varying vec2 v_vTexcoord; | |
varying vec4 v_vColour; | |
varying vec3 v_vPosition; | |
void main() | |
{ | |
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); | |
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; | |
v_vColour = in_Colour; | |
v_vTexcoord = in_TextureCoord; | |
v_vPosition = in_Position; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precision mediump float; | |
#define LOWPREC lowp | |
// Uniforms look like they're shared between vertex and fragment shaders in GLSL, so we have to be careful to avoid name clashes | |
uniform sampler2D gm_BaseTexture; | |
uniform bool gm_PS_FogEnabled; | |
uniform vec4 gm_FogColour; | |
uniform bool gm_AlphaTestEnabled; | |
uniform float gm_AlphaRefValue; | |
void DoAlphaTest(vec4 SrcColour) | |
{ | |
if (gm_AlphaTestEnabled) | |
{ | |
if (SrcColour.a <= gm_AlphaRefValue) | |
{ | |
discard; | |
} | |
} | |
} | |
void DoFog(inout vec4 SrcColour, float fogval) | |
{ | |
if (gm_PS_FogEnabled) | |
{ | |
SrcColour = mix(SrcColour, gm_FogColour, clamp(fogval, 0.0, 1.0)); | |
} | |
} | |
#define _YY_GLSLES_ 1 | |
precision highp float; | |
// | |
// shColorReplaceBlendExt | |
// | |
// Replaces multiple colors with others. Can replace | |
// similar colors while preserving shading. | |
// | |
// colorIn color to replace (vec4) | |
// colorOut replacement color (vec4) | |
// colorTolerance HSVA tolerances (vec4) | |
// blend 1.0 preserves shading of original, | |
// 0.0 replaces color as-is (float) | |
// | |
// GMLscripts.com | |
// | |
varying vec2 v_vTexcoord; | |
varying vec4 v_vColour; | |
varying vec3 v_vPosition; | |
const int maxcolors = 9; | |
uniform vec4 colorIn[maxcolors]; | |
uniform vec4 colorOut[maxcolors]; | |
uniform vec4 colorTolerance[maxcolors]; | |
uniform vec4 blend[maxcolors]; | |
uniform float effectY; | |
uniform float playerX; | |
uniform float playerY; | |
uniform int special; | |
uniform float time; | |
// 1 - American Wrastor | |
// 2 - Genesis Forsburn (moved to separate shader) | |
// 3 - Excaliburn | |
// 4 - Champ Kragg | |
// 5 - Pool Party Ranno | |
vec3 rgb_to_hsv(vec3 col) | |
{ | |
float H = 0.0; | |
float S = 0.0; | |
float V = 0.0; | |
float M = max(col.r, max(col.g, col.b)); | |
float m = min(col.r, min(col.g, col.b)); | |
V = M; | |
float C = M - m; | |
if (C > 0.0) | |
{ | |
if (M == col.r) H = mod( (col.g - col.b) / C, 6.0); | |
if (M == col.g) H = (col.b - col.r) / C + 2.0; | |
if (M == col.b) H = (col.r - col.g) / C + 4.0; | |
H /= 6.0; | |
S = C / V; | |
} | |
return vec3(H, S, V); | |
} | |
vec3 hsv_to_rgb(vec3 col) | |
{ | |
float H = col.r; | |
float S = col.g; | |
float V = col.b; | |
float C = V * S; | |
H *= 6.0; | |
float X = C * (1.0 - abs( mod(H, 2.0) - 1.0 )); | |
float m = V - C; | |
C += m; | |
X += m; | |
if (H < 1.0) return vec3(C, X, m); | |
if (H < 2.0) return vec3(X, C, m); | |
if (H < 3.0) return vec3(m, C, X); | |
if (H < 4.0) return vec3(m, X, C); | |
if (H < 5.0) return vec3(X, m, C); | |
else return vec3(C, m, X); | |
} | |
void main() | |
{ | |
vec4 colorPixel = texture2D( gm_BaseTexture, v_vTexcoord ); | |
vec4 colorResult = colorPixel; | |
vec4 colorHSV = vec4( rgb_to_hsv( colorPixel.rgb ), colorPixel.a); | |
for (int i=0; i< maxcolors; i+=1) | |
{ | |
vec4 colorInHSV = vec4( rgb_to_hsv( colorIn[i].rgb ), colorIn[i].a); | |
vec4 colorDelta = colorHSV - colorInHSV; | |
if (abs(colorDelta.r)>0.5) colorDelta.r -= sign(colorDelta.r); | |
if ( all( lessThanEqual( abs(colorDelta), colorTolerance[i] ) ) ) | |
{ | |
vec4 tColorOut = colorOut[i]; | |
if (special == 7){ //SnS Orcane | |
if (i < 3){ | |
//float t_y = floor((playerY - v_vPosition.y) * 0.5) * 2.0; | |
//float t_x = floor((playerX - v_vPosition.x) * 0.5) * 2.0; | |
float t_y = floor((v_vPosition.y) * 0.5) * 2.0; | |
float t_x = floor((playerX - v_vPosition.x) * 0.5) * 2.0; | |
if (t_y > effectY + 4.0*sin((t_x - floor(time*0.5))*0.2)){ | |
tColorOut.r = 1.0; | |
tColorOut.g = 181.0/255.0; | |
tColorOut.b = 65.0/255.0; | |
} | |
} | |
} else if (special == 9){ //Dreamscape Fors | |
if (i == 5){ | |
float fade = clamp((playerY - v_vPosition.y)/effectY, 0.0, 1.0); //0 at bottom, 1 at top | |
float denom = .00392; // 1.0 / 255.0 | |
float r1 = 150.0*denom; | |
float g1 = 14.0*denom; | |
float b1 = 166.0*denom; | |
float r2 = 24.0*denom; | |
float g2 = 4.0*denom; | |
float b2 = 76.0*denom; | |
float t_x = floor((playerX - v_vPosition.x) * 0.5); | |
float t_y = floor((playerY - v_vPosition.y) * 0.5); | |
float modx1 = mod(t_x - floor(time*0.01),8.0); | |
float mody1 = mod(t_y - floor(time*0.01),8.0); | |
float isStar1 = float(((modx1 == 0.0 && mody1 == 0.0) || (modx1 == 4.0 && mody1 == 4.0)) && playerX != -800.0); | |
float shine_value1 = 0.5 + 0.5 * sin(t_y + floor(time*0.04)) * cos(t_x + floor(time*0.02)); | |
float modx2 = mod(t_x + floor(time*0.01),5.0); | |
float mody2 = mod(t_y + floor(time*0.01),5.0); | |
float isStar2 = float(((modx2 == 1.0 && mody2 == 2.0) || (modx2 == 3.0 && mody2 == 0.0)) && playerX != -800.0); | |
float shine_value2 = 0.5 + 0.5 * cos(t_y - floor(time*0.03)) * sin(t_x - floor(time*0.06)); | |
tColorOut.r = mix((r2-r1)*fade + r1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
tColorOut.g = mix((g2-g1)*fade + g1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
tColorOut.b = mix((b2-b1)*fade + b1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
} | |
} else if (special == 10){ //Dreamscape Fors (results screen version) | |
if (i == 5){ | |
float fade = 1.0 - clamp((v_vPosition.y - (playerY+240.0))/280.0, 0.0, 1.0); //0 at bottom, 1 at top | |
float denom = .00392; // 1.0 / 255.0 | |
float r1 = 150.0*denom; | |
float g1 = 14.0*denom; | |
float b1 = 166.0*denom; | |
float r2 = 24.0*denom; | |
float g2 = 4.0*denom; | |
float b2 = 76.0*denom; | |
float temp_time = 137.0; //random number | |
float t_x = floor((playerX - v_vPosition.x) * 0.5); | |
float t_y = floor((playerY - v_vPosition.y) * 0.5); | |
float modx1 = mod(t_x,32.0); | |
float mody1 = mod(t_y,32.0); | |
float isStar1 = float((modx1 == 0.0 && mody1 == 0.0) || (modx1 == 16.0 && mody1 == 16.0)); | |
float shine_value1 = 0.5 + 0.5 * sin(t_y + floor(temp_time*0.04)) * cos(t_x + floor(temp_time*0.02)); | |
float modx2 = mod(t_x,20.0); | |
float mody2 = mod(t_y,20.0); | |
float isStar2 = float((modx2 == 4.0 && mody2 == 8.0) || (modx2 == 12.0 && mody2 == 0.0)); | |
float shine_value2 = 0.5 + 0.5 * cos(t_y - floor(temp_time*0.03)) * sin(t_x - floor(temp_time*0.06)); | |
tColorOut.r = mix((r2-r1)*fade + r1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
tColorOut.g = mix((g2-g1)*fade + g1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
tColorOut.b = mix((b2-b1)*fade + b1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
} | |
} else if (special == 8) { //summit kragg | |
if (i == 0){ | |
if (v_vPosition.y < effectY){ | |
//replace with snow texture | |
tColorOut.r = 0.81960;//0.73725;//v_vTexcoord.x; | |
tColorOut.g = 0.83529;//0.76078;//v_vTexcoord.y; | |
tColorOut.b = 0.86667;//0.80784; | |
} else if (v_vPosition.y < effectY + 8.0){ | |
float t_y = floor((playerY - v_vPosition.y) * 0.5) * 2.0; | |
float t_a = (t_y - effectY)*0.125; | |
float t_dither = (t_a * 4.0) + 1.0; //1 at top 4 at bottom | |
float t_x = floor((playerX - v_vPosition.x) * 0.5) + mod(t_dither, 2.0); | |
t_y = floor(v_vPosition.y * 0.5) * 2.0; | |
t_a = (t_y - effectY)*0.125; | |
if (mod(t_x, 2.0) < 1.0){ | |
tColorOut.r = mix(0.81960,colorOut[i].r,t_a); | |
tColorOut.g = mix(0.83529,colorOut[i].g,t_a); | |
tColorOut.b = mix(0.86667,colorOut[i].b,t_a); | |
} | |
} | |
} | |
} | |
//American Wrastor | |
float t_x = floor((playerX - v_vPosition.x) * 0.5); | |
float t_y = floor((playerY - v_vPosition.y) * 0.5); | |
float modx = mod(t_x,4.0); | |
float mody = mod(t_y,4.0); | |
float isStar = float(special == 1 && i == 1 && ((modx == 0.0 && mody == 0.0) || (modx == 2.0 && mody == 2.0))); | |
tColorOut.r = mix(tColorOut.r, 1.0, isStar * 0.5); | |
tColorOut.g = mix(tColorOut.g, 1.0, isStar * 0.5); | |
tColorOut.b = mix(tColorOut.b, 1.0, isStar * 0.5); | |
//Excaliburn | |
//bool isGolden = ((tColorOut.r == 228.0/255.0 && tColorOut.g == 228.0/255.0 && tColorOut.b == 240.0/255.0) || (tColorOut.r == 121.0/255.0 && tColorOut.g == 122.0/255.0 && tColorOut.b == 195.0/255.0)); | |
float isScanline = float(((special == 3 && (i == 2 || i == 3)) || (special == 6)) && t_y > t_x * -0.3 + mod(time*2.0,200.0) - 100.0 && t_y < t_x * -0.3 + mod(time*2.0,200.0) - 96.0); | |
tColorOut.r = mix(tColorOut.r, 1.0, isScanline * 0.7); | |
tColorOut.g = mix(tColorOut.g, 1.0, isScanline * 0.7); | |
tColorOut.b = mix(tColorOut.b, 1.0, isScanline * 0.7); | |
//Champion Kragg | |
isScanline = float(special == 4 && i == 0 && ((mod(t_y,200.0) > mod(t_x + time*2.0,200.0) && mod(t_y,200.0) < mod(t_x + time*2.0 + 6.0,200.0)))); | |
tColorOut.r = mix(tColorOut.r, 1.0, isScanline * 0.7); | |
tColorOut.g = mix(tColorOut.g, 1.0, isScanline * 0.7); | |
tColorOut.b = mix(tColorOut.b, 1.0, isScanline * 0.7); | |
//Pool Party Ranno | |
mody = mod(t_y,6.0); | |
bool inFlowerPos1 = (modx == 1.0 && (mody == 0.0 || mody == 2.0)) || (mody == 1.0 && (modx == 0.0 || modx == 2.0)); | |
bool inFlowerPos2 = (modx == 3.0 && (mody == 3.0 || mody == 5.0)) || (mody == 4.0 && (modx == 0.0 || modx == 2.0)); | |
bool inFlowerPos = (inFlowerPos1 || inFlowerPos2); | |
float isFlower = float(special == 5 && i == 2 && inFlowerPos); | |
tColorOut.r = mix(tColorOut.r, 1.0, isFlower * 0.8); | |
tColorOut.g = mix(tColorOut.g, 1.0, isFlower * 0.8); | |
tColorOut.b = mix(tColorOut.b, 1.0, isFlower * 0.8); | |
vec4 colorOutHSV = vec4( rgb_to_hsv( tColorOut.rgb ), tColorOut.a); | |
colorResult = mix( tColorOut, | |
vec4 ( hsv_to_rgb( vec3( mod( colorOutHSV.r + colorDelta.r, 1.0 ), | |
clamp( colorOutHSV.g + colorDelta.g, 0.0, 1.0 ), | |
clamp( colorOutHSV.b + colorDelta.b, 0.0, 1.0 ) ) ), | |
clamp( tColorOut.a + colorDelta.a, 0.0, 1.0) ), | |
blend[i].x ); | |
} | |
} | |
//Genesis Forsburn | |
/*if (special == 2){ | |
for (float xOffset = -0.01; xOffset <= 0.01; xOffset += 0.005){ | |
for (float yOffset = -0.01; yOffset <= 0.01; yOffset += 0.005){ | |
vec4 colorPixel2 = texture2D( gm_BaseTexture, v_vTexcoord + vec2(xOffset, yOffset) ); | |
vec4 colorHSV2 = vec4( rgb_to_hsv( colorPixel2.rgb ), colorPixel2.a); | |
vec4 colorInHSV2 = vec4( rgb_to_hsv( colorIn[2].rgb ), colorIn[2].a); | |
vec4 colorInHSV3 = vec4( rgb_to_hsv( colorIn[3].rgb ), colorIn[3].a); | |
vec4 colorInHSV4 = vec4( rgb_to_hsv( colorIn[4].rgb ), colorIn[4].a); | |
vec4 colorDelta2 = colorHSV2 - colorInHSV2; | |
vec4 colorDelta3 = colorHSV2 - colorInHSV3; | |
vec4 colorDelta4 = colorHSV2 - colorInHSV4; | |
if (abs(colorDelta2.r)>0.5) colorDelta2.r -= sign(colorDelta2.r); | |
if (abs(colorDelta3.r)>0.5) colorDelta3.r -= sign(colorDelta3.r); | |
if (abs(colorDelta4.r)>0.5) colorDelta4.r -= sign(colorDelta4.r); | |
if ( all( lessThanEqual( abs(colorDelta2), colorTolerance[2] ) ) | |
|| all( lessThanEqual( abs(colorDelta3), colorTolerance[3] ) ) | |
|| all( lessThanEqual( abs(colorDelta4), colorTolerance[4] ) )) { | |
colorResult.r += 0.1; | |
if (colorResult.a == 0.0){ | |
colorResult.g = 0.0; | |
colorResult.b = 0.0; | |
} | |
colorResult.a = clamp(colorResult.a + 0.1, 0.1, 1.0); | |
} | |
} | |
} | |
}*/ | |
gl_FragColor = v_vColour * colorResult; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 120 | |
#define LOWPREC | |
#define lowp | |
#define mediump | |
#define highp | |
#define precision | |
#define MATRIX_VIEW 0 | |
#define MATRIX_PROJECTION 1 | |
#define MATRIX_WORLD 2 | |
#define MATRIX_WORLD_VIEW 3 | |
#define MATRIX_WORLD_VIEW_PROJECTION 4 | |
#define MATRICES_MAX 5 | |
uniform mat4 gm_Matrices[MATRICES_MAX]; | |
uniform bool gm_LightingEnabled; | |
uniform bool gm_VS_FogEnabled; | |
uniform float gm_FogStart; | |
uniform float gm_RcpFogRange; | |
#define MAX_VS_LIGHTS 8 | |
#define MIRROR_WIN32_LIGHTING_EQUATION | |
//#define MAX_VS_LIGHTS 8 | |
uniform vec4 gm_AmbientColour; // rgb=colour, a=1 | |
uniform vec4 gm_Lights_Direction[MAX_VS_LIGHTS]; // normalised direction | |
uniform vec4 gm_Lights_PosRange[MAX_VS_LIGHTS]; // X,Y,Z position, W range | |
uniform vec4 gm_Lights_Colour[MAX_VS_LIGHTS]; // rgb=colour, a=1 | |
float CalcFogFactor(vec4 pos) | |
{ | |
if (gm_VS_FogEnabled) | |
{ | |
vec4 viewpos = gm_Matrices[MATRIX_WORLD_VIEW] * pos; | |
float fogfactor = ((viewpos.z - gm_FogStart) * gm_RcpFogRange); | |
return fogfactor; | |
} | |
else | |
{ | |
return 0.0; | |
} | |
} | |
vec4 DoDirLight(vec3 ws_normal, vec4 dir, vec4 diffusecol) | |
{ | |
float dotresult = dot(ws_normal, dir.xyz); | |
dotresult = max(0.0, dotresult); | |
return dotresult * diffusecol; | |
} | |
vec4 DoPointLight(vec3 ws_pos, vec3 ws_normal, vec4 posrange, vec4 diffusecol) | |
{ | |
vec3 diffvec = ws_pos - posrange.xyz; | |
float veclen = length(diffvec); | |
diffvec /= veclen; // normalise | |
#ifdef MIRROR_WIN32_LIGHTING_EQUATION | |
// This is based on the Win32 D3D and OpenGL falloff model, where: | |
// Attenuation = 1.0f / (factor0 + (d * factor1) + (d*d * factor2)) | |
// For some reason, factor0 is set to 0.0f while factor1 is set to 1.0f/lightrange (on both D3D and OpenGL) | |
// This'll result in no visible falloff as 1.0f / (d / lightrange) will always be larger than 1.0f (if the vertex is within range) | |
float atten = 1.0 / (veclen / posrange.w); | |
if (veclen > posrange.w) | |
{ | |
atten = 0.0; | |
} | |
#else | |
float atten = clamp( (1.0 - (veclen / posrange.w)), 0.0, 1.0); // storing 1.0f/range instead would save a rcp | |
#endif | |
float dotresult = dot(ws_normal, diffvec); | |
dotresult = max(0.0, dotresult); | |
return dotresult * atten * diffusecol; | |
} | |
vec4 DoLighting(vec4 vertexcolour, vec4 objectspacepos, vec3 objectspacenormal) | |
{ | |
if (gm_LightingEnabled) | |
{ | |
// Normally we'd have the light positions\\directions back-transformed from world to object space | |
// But to keep things simple for the moment we'll just transform the normal to world space | |
vec4 objectspacenormal4 = vec4(objectspacenormal, 0.0); | |
vec3 ws_normal; | |
ws_normal = (gm_Matrices[MATRIX_WORLD_VIEW] * objectspacenormal4).xyz; | |
ws_normal = -normalize(ws_normal); | |
vec3 ws_pos; | |
ws_pos = (gm_Matrices[MATRIX_WORLD] * objectspacepos).xyz; | |
// Accumulate lighting from different light types | |
vec4 accumcol = vec4(0.0, 0.0, 0.0, 0.0); | |
for(int i = 0; i < MAX_VS_LIGHTS; i++) | |
{ | |
accumcol += DoDirLight(ws_normal, gm_Lights_Direction[i], gm_Lights_Colour[i]); | |
} | |
for(int i = 0; i < MAX_VS_LIGHTS; i++) | |
{ | |
accumcol += DoPointLight(ws_pos, ws_normal, gm_Lights_PosRange[i], gm_Lights_Colour[i]); | |
} | |
accumcol *= vertexcolour; | |
accumcol += gm_AmbientColour; | |
accumcol = min(vec4(1.0, 1.0, 1.0, 1.0), accumcol); | |
accumcol.a = vertexcolour.a; | |
return accumcol; | |
} | |
else | |
{ | |
return vertexcolour; | |
} | |
} | |
#define _YY_GLSL_ 1 | |
// | |
// Simple passthrough vertex shader | |
// | |
attribute vec3 in_Position; // (x,y,z) | |
attribute vec4 in_Colour; // (r,g,b,a) | |
attribute vec2 in_TextureCoord; // (u,v) | |
//attribute vec3 in_Normal; // (x,y,z) unused in this shader. | |
varying vec2 v_vTexcoord; | |
varying vec4 v_vColour; | |
varying vec3 v_vPosition; | |
void main() | |
{ | |
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); | |
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; | |
v_vColour = in_Colour; | |
v_vTexcoord = in_TextureCoord; | |
v_vPosition = in_Position; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 120 | |
#define LOWPREC | |
#define lowp | |
#define mediump | |
#define highp | |
#define precision | |
// Uniforms look like they're shared between vertex and fragment shaders in GLSL, so we have to be careful to avoid name clashes | |
uniform sampler2D gm_BaseTexture; | |
uniform bool gm_PS_FogEnabled; | |
uniform vec4 gm_FogColour; | |
uniform bool gm_AlphaTestEnabled; | |
uniform float gm_AlphaRefValue; | |
void DoAlphaTest(vec4 SrcColour) | |
{ | |
if (gm_AlphaTestEnabled) | |
{ | |
if (SrcColour.a <= gm_AlphaRefValue) | |
{ | |
discard; | |
} | |
} | |
} | |
void DoFog(inout vec4 SrcColour, float fogval) | |
{ | |
if (gm_PS_FogEnabled) | |
{ | |
SrcColour = mix(SrcColour, gm_FogColour, clamp(fogval, 0.0, 1.0)); | |
} | |
} | |
#define _YY_GLSL_ 1 | |
precision highp float; | |
// | |
// shColorReplaceBlendExt | |
// | |
// Replaces multiple colors with others. Can replace | |
// similar colors while preserving shading. | |
// | |
// colorIn color to replace (vec4) | |
// colorOut replacement color (vec4) | |
// colorTolerance HSVA tolerances (vec4) | |
// blend 1.0 preserves shading of original, | |
// 0.0 replaces color as-is (float) | |
// | |
// GMLscripts.com | |
// | |
varying vec2 v_vTexcoord; | |
varying vec4 v_vColour; | |
varying vec3 v_vPosition; | |
const int maxcolors = 9; | |
uniform vec4 colorIn[maxcolors]; | |
uniform vec4 colorOut[maxcolors]; | |
uniform vec4 colorTolerance[maxcolors]; | |
uniform vec4 blend[maxcolors]; | |
uniform float effectY; | |
uniform float playerX; | |
uniform float playerY; | |
uniform int special; | |
uniform float time; | |
// 1 - American Wrastor | |
// 2 - Genesis Forsburn (moved to separate shader) | |
// 3 - Excaliburn | |
// 4 - Champ Kragg | |
// 5 - Pool Party Ranno | |
vec3 rgb_to_hsv(vec3 col) | |
{ | |
float H = 0.0; | |
float S = 0.0; | |
float V = 0.0; | |
float M = max(col.r, max(col.g, col.b)); | |
float m = min(col.r, min(col.g, col.b)); | |
V = M; | |
float C = M - m; | |
if (C > 0.0) | |
{ | |
if (M == col.r) H = mod( (col.g - col.b) / C, 6.0); | |
if (M == col.g) H = (col.b - col.r) / C + 2.0; | |
if (M == col.b) H = (col.r - col.g) / C + 4.0; | |
H /= 6.0; | |
S = C / V; | |
} | |
return vec3(H, S, V); | |
} | |
vec3 hsv_to_rgb(vec3 col) | |
{ | |
float H = col.r; | |
float S = col.g; | |
float V = col.b; | |
float C = V * S; | |
H *= 6.0; | |
float X = C * (1.0 - abs( mod(H, 2.0) - 1.0 )); | |
float m = V - C; | |
C += m; | |
X += m; | |
if (H < 1.0) return vec3(C, X, m); | |
if (H < 2.0) return vec3(X, C, m); | |
if (H < 3.0) return vec3(m, C, X); | |
if (H < 4.0) return vec3(m, X, C); | |
if (H < 5.0) return vec3(X, m, C); | |
else return vec3(C, m, X); | |
} | |
void main() | |
{ | |
vec4 colorPixel = texture2D( gm_BaseTexture, v_vTexcoord ); | |
vec4 colorResult = colorPixel; | |
vec4 colorHSV = vec4( rgb_to_hsv( colorPixel.rgb ), colorPixel.a); | |
for (int i=0; i< maxcolors; i+=1) | |
{ | |
vec4 colorInHSV = vec4( rgb_to_hsv( colorIn[i].rgb ), colorIn[i].a); | |
vec4 colorDelta = colorHSV - colorInHSV; | |
if (abs(colorDelta.r)>0.5) colorDelta.r -= sign(colorDelta.r); | |
if ( all( lessThanEqual( abs(colorDelta), colorTolerance[i] ) ) ) | |
{ | |
vec4 tColorOut = colorOut[i]; | |
if (special == 7){ //SnS Orcane | |
if (i < 3){ | |
//float t_y = floor((playerY - v_vPosition.y) * 0.5) * 2.0; | |
//float t_x = floor((playerX - v_vPosition.x) * 0.5) * 2.0; | |
float t_y = floor((v_vPosition.y) * 0.5) * 2.0; | |
float t_x = floor((playerX - v_vPosition.x) * 0.5) * 2.0; | |
if (t_y > effectY + 4.0*sin((t_x - floor(time*0.5))*0.2)){ | |
tColorOut.r = 1.0; | |
tColorOut.g = 181.0/255.0; | |
tColorOut.b = 65.0/255.0; | |
} | |
} | |
} else if (special == 9){ //Dreamscape Fors | |
if (i == 5){ | |
float fade = clamp((playerY - v_vPosition.y)/effectY, 0.0, 1.0); //0 at bottom, 1 at top | |
float denom = .00392; // 1.0 / 255.0 | |
float r1 = 150.0*denom; | |
float g1 = 14.0*denom; | |
float b1 = 166.0*denom; | |
float r2 = 24.0*denom; | |
float g2 = 4.0*denom; | |
float b2 = 76.0*denom; | |
float t_x = floor((playerX - v_vPosition.x) * 0.5); | |
float t_y = floor((playerY - v_vPosition.y) * 0.5); | |
float modx1 = mod(t_x - floor(time*0.01),8.0); | |
float mody1 = mod(t_y - floor(time*0.01),8.0); | |
float isStar1 = float(((modx1 == 0.0 && mody1 == 0.0) || (modx1 == 4.0 && mody1 == 4.0)) && playerX != -800.0); | |
float shine_value1 = 0.5 + 0.5 * sin(t_y + floor(time*0.04)) * cos(t_x + floor(time*0.02)); | |
float modx2 = mod(t_x + floor(time*0.01),5.0); | |
float mody2 = mod(t_y + floor(time*0.01),5.0); | |
float isStar2 = float(((modx2 == 1.0 && mody2 == 2.0) || (modx2 == 3.0 && mody2 == 0.0)) && playerX != -800.0); | |
float shine_value2 = 0.5 + 0.5 * cos(t_y - floor(time*0.03)) * sin(t_x - floor(time*0.06)); | |
tColorOut.r = mix((r2-r1)*fade + r1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
tColorOut.g = mix((g2-g1)*fade + g1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
tColorOut.b = mix((b2-b1)*fade + b1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
} | |
} else if (special == 10){ //Dreamscape Fors (results screen version) | |
if (i == 5){ | |
float fade = 1.0 - clamp((v_vPosition.y - (playerY+240.0))/280.0, 0.0, 1.0); //0 at bottom, 1 at top | |
float denom = .00392; // 1.0 / 255.0 | |
float r1 = 150.0*denom; | |
float g1 = 14.0*denom; | |
float b1 = 166.0*denom; | |
float r2 = 24.0*denom; | |
float g2 = 4.0*denom; | |
float b2 = 76.0*denom; | |
float temp_time = 137.0; //random number | |
float t_x = floor((playerX - v_vPosition.x) * 0.5); | |
float t_y = floor((playerY - v_vPosition.y) * 0.5); | |
float modx1 = mod(t_x,32.0); | |
float mody1 = mod(t_y,32.0); | |
float isStar1 = float((modx1 == 0.0 && mody1 == 0.0) || (modx1 == 16.0 && mody1 == 16.0)); | |
float shine_value1 = 0.5 + 0.5 * sin(t_y + floor(temp_time*0.04)) * cos(t_x + floor(temp_time*0.02)); | |
float modx2 = mod(t_x,20.0); | |
float mody2 = mod(t_y,20.0); | |
float isStar2 = float((modx2 == 4.0 && mody2 == 8.0) || (modx2 == 12.0 && mody2 == 0.0)); | |
float shine_value2 = 0.5 + 0.5 * cos(t_y - floor(temp_time*0.03)) * sin(t_x - floor(temp_time*0.06)); | |
tColorOut.r = mix((r2-r1)*fade + r1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
tColorOut.g = mix((g2-g1)*fade + g1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
tColorOut.b = mix((b2-b1)*fade + b1, 1.0, isStar1 * shine_value1 + isStar2 * shine_value2); | |
} | |
} else if (special == 8) { //summit kragg | |
if (i == 0){ | |
if (v_vPosition.y < effectY){ | |
//replace with snow texture | |
tColorOut.r = 0.81960;//0.73725;//v_vTexcoord.x; | |
tColorOut.g = 0.83529;//0.76078;//v_vTexcoord.y; | |
tColorOut.b = 0.86667;//0.80784; | |
} else if (v_vPosition.y < effectY + 8.0){ | |
float t_y = floor((playerY - v_vPosition.y) * 0.5) * 2.0; | |
float t_a = (t_y - effectY)*0.125; | |
float t_dither = (t_a * 4.0) + 1.0; //1 at top 4 at bottom | |
float t_x = floor((playerX - v_vPosition.x) * 0.5) + mod(t_dither, 2.0); | |
t_y = floor(v_vPosition.y * 0.5) * 2.0; | |
t_a = (t_y - effectY)*0.125; | |
if (mod(t_x, 2.0) < 1.0){ | |
tColorOut.r = mix(0.81960,colorOut[i].r,t_a); | |
tColorOut.g = mix(0.83529,colorOut[i].g,t_a); | |
tColorOut.b = mix(0.86667,colorOut[i].b,t_a); | |
} | |
} | |
} | |
} | |
//American Wrastor | |
float t_x = floor((playerX - v_vPosition.x) * 0.5); | |
float t_y = floor((playerY - v_vPosition.y) * 0.5); | |
float modx = mod(t_x,4.0); | |
float mody = mod(t_y,4.0); | |
float isStar = float(special == 1 && i == 1 && ((modx == 0.0 && mody == 0.0) || (modx == 2.0 && mody == 2.0))); | |
tColorOut.r = mix(tColorOut.r, 1.0, isStar * 0.5); | |
tColorOut.g = mix(tColorOut.g, 1.0, isStar * 0.5); | |
tColorOut.b = mix(tColorOut.b, 1.0, isStar * 0.5); | |
//Excaliburn | |
//bool isGolden = ((tColorOut.r == 228.0/255.0 && tColorOut.g == 228.0/255.0 && tColorOut.b == 240.0/255.0) || (tColorOut.r == 121.0/255.0 && tColorOut.g == 122.0/255.0 && tColorOut.b == 195.0/255.0)); | |
float isScanline = float(((special == 3 && (i == 2 || i == 3)) || (special == 6)) && t_y > t_x * -0.3 + mod(time*2.0,200.0) - 100.0 && t_y < t_x * -0.3 + mod(time*2.0,200.0) - 96.0); | |
tColorOut.r = mix(tColorOut.r, 1.0, isScanline * 0.7); | |
tColorOut.g = mix(tColorOut.g, 1.0, isScanline * 0.7); | |
tColorOut.b = mix(tColorOut.b, 1.0, isScanline * 0.7); | |
//Champion Kragg | |
isScanline = float(special == 4 && i == 0 && ((mod(t_y,200.0) > mod(t_x + time*2.0,200.0) && mod(t_y,200.0) < mod(t_x + time*2.0 + 6.0,200.0)))); | |
tColorOut.r = mix(tColorOut.r, 1.0, isScanline * 0.7); | |
tColorOut.g = mix(tColorOut.g, 1.0, isScanline * 0.7); | |
tColorOut.b = mix(tColorOut.b, 1.0, isScanline * 0.7); | |
//Pool Party Ranno | |
mody = mod(t_y,6.0); | |
bool inFlowerPos1 = (modx == 1.0 && (mody == 0.0 || mody == 2.0)) || (mody == 1.0 && (modx == 0.0 || modx == 2.0)); | |
bool inFlowerPos2 = (modx == 3.0 && (mody == 3.0 || mody == 5.0)) || (mody == 4.0 && (modx == 0.0 || modx == 2.0)); | |
bool inFlowerPos = (inFlowerPos1 || inFlowerPos2); | |
float isFlower = float(special == 5 && i == 2 && inFlowerPos); | |
tColorOut.r = mix(tColorOut.r, 1.0, isFlower * 0.8); | |
tColorOut.g = mix(tColorOut.g, 1.0, isFlower * 0.8); | |
tColorOut.b = mix(tColorOut.b, 1.0, isFlower * 0.8); | |
vec4 colorOutHSV = vec4( rgb_to_hsv( tColorOut.rgb ), tColorOut.a); | |
colorResult = mix( tColorOut, | |
vec4 ( hsv_to_rgb( vec3( mod( colorOutHSV.r + colorDelta.r, 1.0 ), | |
clamp( colorOutHSV.g + colorDelta.g, 0.0, 1.0 ), | |
clamp( colorOutHSV.b + colorDelta.b, 0.0, 1.0 ) ) ), | |
clamp( tColorOut.a + colorDelta.a, 0.0, 1.0) ), | |
blend[i].x ); | |
} | |
} | |
//Genesis Forsburn | |
/*if (special == 2){ | |
for (float xOffset = -0.01; xOffset <= 0.01; xOffset += 0.005){ | |
for (float yOffset = -0.01; yOffset <= 0.01; yOffset += 0.005){ | |
vec4 colorPixel2 = texture2D( gm_BaseTexture, v_vTexcoord + vec2(xOffset, yOffset) ); | |
vec4 colorHSV2 = vec4( rgb_to_hsv( colorPixel2.rgb ), colorPixel2.a); | |
vec4 colorInHSV2 = vec4( rgb_to_hsv( colorIn[2].rgb ), colorIn[2].a); | |
vec4 colorInHSV3 = vec4( rgb_to_hsv( colorIn[3].rgb ), colorIn[3].a); | |
vec4 colorInHSV4 = vec4( rgb_to_hsv( colorIn[4].rgb ), colorIn[4].a); | |
vec4 colorDelta2 = colorHSV2 - colorInHSV2; | |
vec4 colorDelta3 = colorHSV2 - colorInHSV3; | |
vec4 colorDelta4 = colorHSV2 - colorInHSV4; | |
if (abs(colorDelta2.r)>0.5) colorDelta2.r -= sign(colorDelta2.r); | |
if (abs(colorDelta3.r)>0.5) colorDelta3.r -= sign(colorDelta3.r); | |
if (abs(colorDelta4.r)>0.5) colorDelta4.r -= sign(colorDelta4.r); | |
if ( all( lessThanEqual( abs(colorDelta2), colorTolerance[2] ) ) | |
|| all( lessThanEqual( abs(colorDelta3), colorTolerance[3] ) ) | |
|| all( lessThanEqual( abs(colorDelta4), colorTolerance[4] ) )) { | |
colorResult.r += 0.1; | |
if (colorResult.a == 0.0){ | |
colorResult.g = 0.0; | |
colorResult.b = 0.0; | |
} | |
colorResult.a = clamp(colorResult.a + 0.1, 0.1, 1.0); | |
} | |
} | |
} | |
}*/ | |
gl_FragColor = v_vColour * colorResult; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MATRIX_VIEW 0 | |
#define MATRIX_PROJECTION 1 | |
#define MATRIX_WORLD 2 | |
#define MATRIX_WORLD_VIEW 3 | |
#define MATRIX_WORLD_VIEW_PROJECTION 4 | |
#define MATRICES_MAX 5 | |
float4x4 gm_Matrices[MATRICES_MAX] : register(c0); | |
bool gm_LightingEnabled; | |
bool gm_VS_FogEnabled; | |
float gm_FogStart; | |
float gm_RcpFogRange; | |
#define MAX_VS_LIGHTS 8 | |
float4 gm_AmbientColour; // rgb=colour, a=1 | |
float3 gm_Lights_Direction[MAX_VS_LIGHTS]; // normalised direction | |
float4 gm_Lights_PosRange[MAX_VS_LIGHTS]; // X,Y,Z position, W range | |
float4 gm_Lights_Colour[MAX_VS_LIGHTS]; // rgb=colour, a=1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GameMaker reserved and common types/inputs | |
sampler2D gm_BaseTexture : register(S0); | |
bool gm_PS_FogEnabled; | |
float4 gm_FogColour; | |
bool gm_AlphaTestEnabled; | |
float4 gm_AlphaRefValue; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment