-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from stupxd/main
SMODS.Shader - optional method for custom external vars
- Loading branch information
Showing
7 changed files
with
191 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
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
121 changes: 121 additions & 0 deletions
121
example_mods/Mods/EditionExamples/assets/shaders/gold.fs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#if defined(VERTEX) || __VERSION__ > 100 || defined(GL_FRAGMENT_PRECISION_HIGH) | ||
#define PRECISION highp | ||
#else | ||
#define PRECISION mediump | ||
#endif | ||
|
||
// | ||
// Shader made by: stupxd | ||
// You are free to use and modify this shader in your projects, | ||
// as long as you credit me for the original work. | ||
// | ||
|
||
extern PRECISION vec2 gold; | ||
|
||
extern PRECISION number dissolve; | ||
extern PRECISION number time; | ||
extern PRECISION vec4 texture_details; | ||
extern PRECISION vec2 image_details; | ||
extern bool shadow; | ||
extern PRECISION vec4 burn_colour_1; | ||
extern PRECISION vec4 burn_colour_2; | ||
|
||
// Custom extern from SMODS.Shader | ||
extern PRECISION float lines_offset; | ||
|
||
#define TWO_PI 6.28318530718 | ||
|
||
vec4 gold_color = vec4(231., 164., 25., 0.) / 255.; | ||
|
||
vec4 dissolve_mask(vec4 final_pixel, vec2 texture_coords, vec2 uv); | ||
|
||
bool line(vec2 uv, float offset, float width) { | ||
uv.x = uv.x * texture_details.z / texture_details.w; | ||
|
||
offset = offset + 0.35 * sin(gold.x + TWO_PI * lines_offset); | ||
width = width + 0.005 * sin(gold.x); | ||
|
||
float min_y = -uv.x + offset; | ||
float max_y = -uv.x + offset + width; | ||
|
||
return uv.y > min_y && uv.y < max_y; | ||
} | ||
|
||
vec4 effect( vec4 colour, Image texture, vec2 texture_coords, vec2 screen_coords ) | ||
{ | ||
vec2 uv = (((texture_coords)*(image_details)) - texture_details.xy*texture_details.zw)/texture_details.zw; | ||
vec4 pixel = Texel(texture, texture_coords); | ||
|
||
vec4 tex = vec4(1., 1., 1., 0.1); | ||
|
||
if ( | ||
lines_offset > 0 && (line(uv, 0.0, 0.07) || line(uv, 0.4, 0.1) || line(uv, 0.55, 0.1) || line(uv, 1.3, 0.05) || line(uv, 1.8, 0.1)) || | ||
(line(uv, -0.1, 0.13) || line(uv, 0.3, 0.05) || line(uv, 0.8, 0.1) || line(uv, 1.3, 0.11) || line(uv, 1.7, 0.07)) | ||
) { | ||
tex.a = tex.a * 2.; | ||
} else { | ||
tex.a = 0.05; | ||
} | ||
|
||
float avg = (pixel.r + pixel.g + pixel.b) / 3.; | ||
pixel = vec4(gold_color.rgb * avg + tex.rgb * tex.a, pixel.a); | ||
|
||
return dissolve_mask(pixel, texture_coords, uv); | ||
} | ||
|
||
vec4 dissolve_mask(vec4 final_pixel, vec2 texture_coords, vec2 uv) | ||
{ | ||
if (dissolve < 0.001) { | ||
return vec4(shadow ? vec3(0.,0.,0.) : final_pixel.xyz, shadow ? final_pixel.a*0.3: final_pixel.a); | ||
} | ||
|
||
float adjusted_dissolve = (dissolve*dissolve*(3.-2.*dissolve))*1.02 - 0.01; //Adjusting 0.0-1.0 to fall to -0.1 - 1.1 scale so the mask does not pause at extreme values | ||
|
||
float t = time * 10.0 + 2003.; | ||
vec2 floored_uv = (floor((uv*texture_details.ba)))/max(texture_details.b, texture_details.a); | ||
vec2 uv_scaled_centered = (floored_uv - 0.5) * 2.3 * max(texture_details.b, texture_details.a); | ||
|
||
vec2 field_part1 = uv_scaled_centered + 50.*vec2(sin(-t / 143.6340), cos(-t / 99.4324)); | ||
vec2 field_part2 = uv_scaled_centered + 50.*vec2(cos( t / 53.1532), cos( t / 61.4532)); | ||
vec2 field_part3 = uv_scaled_centered + 50.*vec2(sin(-t / 87.53218), sin(-t / 49.0000)); | ||
|
||
float field = (1.+ ( | ||
cos(length(field_part1) / 19.483) + sin(length(field_part2) / 33.155) * cos(field_part2.y / 15.73) + | ||
cos(length(field_part3) / 27.193) * sin(field_part3.x / 21.92) ))/2.; | ||
vec2 borders = vec2(0.2, 0.8); | ||
|
||
float res = (.5 + .5* cos( (adjusted_dissolve) / 82.612 + ( field + -.5 ) *3.14)) | ||
- (floored_uv.x > borders.y ? (floored_uv.x - borders.y)*(5. + 5.*dissolve) : 0.)*(dissolve) | ||
- (floored_uv.y > borders.y ? (floored_uv.y - borders.y)*(5. + 5.*dissolve) : 0.)*(dissolve) | ||
- (floored_uv.x < borders.x ? (borders.x - floored_uv.x)*(5. + 5.*dissolve) : 0.)*(dissolve) | ||
- (floored_uv.y < borders.x ? (borders.x - floored_uv.y)*(5. + 5.*dissolve) : 0.)*(dissolve); | ||
|
||
if (final_pixel.a > 0.01 && burn_colour_1.a > 0.01 && !shadow && res < adjusted_dissolve + 0.8*(0.5-abs(adjusted_dissolve-0.5)) && res > adjusted_dissolve) { | ||
if (!shadow && res < adjusted_dissolve + 0.5*(0.5-abs(adjusted_dissolve-0.5)) && res > adjusted_dissolve) { | ||
final_pixel.rgba = burn_colour_1.rgba; | ||
} else if (burn_colour_2.a > 0.01) { | ||
final_pixel.rgba = burn_colour_2.rgba; | ||
} | ||
} | ||
|
||
return vec4(shadow ? vec3(0.,0.,0.) : final_pixel.xyz, res > adjusted_dissolve ? (shadow ? final_pixel.a*0.3: final_pixel.a) : .0); | ||
} | ||
|
||
extern PRECISION vec2 mouse_screen_pos; | ||
extern PRECISION float hovering; | ||
extern PRECISION float screen_scale; | ||
|
||
#ifdef VERTEX | ||
vec4 position( mat4 transform_projection, vec4 vertex_position ) | ||
{ | ||
if (hovering <= 0.){ | ||
return transform_projection * vertex_position; | ||
} | ||
float mid_dist = length(vertex_position.xy - 0.5*love_ScreenSize.xy)/length(love_ScreenSize.xy); | ||
vec2 mouse_offset = (vertex_position.xy - mouse_screen_pos.xy)/screen_scale; | ||
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist)) | ||
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist); | ||
|
||
return transform_projection * vertex_position + vec4(0,0,0,scale); | ||
} | ||
#endif |
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