diff options
| -rw-r--r-- | assets/shaders/glsl100/fuck.fs | 101 | ||||
| -rw-r--r-- | assets/shaders/glsl100/postprocessing.fs | 1 | ||||
| -rw-r--r-- | assets/shaders/glsl330/fuck.fs | 101 | ||||
| -rw-r--r-- | src/assets.c | 3 | ||||
| -rw-r--r-- | src/assets.h | 7 | ||||
| -rw-r--r-- | src/game.c | 5 | ||||
| -rw-r--r-- | src/game.h | 1 |
7 files changed, 212 insertions, 7 deletions
diff --git a/assets/shaders/glsl100/fuck.fs b/assets/shaders/glsl100/fuck.fs new file mode 100644 index 0000000..076caff --- /dev/null +++ b/assets/shaders/glsl100/fuck.fs @@ -0,0 +1,101 @@ +#version 100 + +// This is a fuck shader. It is very fuck. + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +const float PI = 3.1415926535; +const float aperture = 290.0; +const float renderWidth = 16.0; +const float renderHeight = 12.0; +const float gamma = 0.6; +const float numColors = 3.0; + +vec3 offset = vec3(0.0, 1.3846153846, 3.2307692308); +vec3 weight = vec3(0.2270270270, 0.3162162162, 0.0702702703); + +void main() +{ + float apertureHalf = 0.5*aperture*(PI/180.0); + float maxFactor = sin(apertureHalf); + + vec2 uv = vec2(0); + vec2 xy = 2.0*fragTexCoord.xy - 1.0; + float d = length(xy); + + if (d < (2.0 - maxFactor)) + { + d = length(xy*maxFactor); + float z = sqrt(1.0 - d*d); + float r = atan(d, z)/PI; + float phi = atan(xy.y, xy.x); + + uv.x = r*cos(phi) + 0.5; + uv.y = r*sin(phi) + 0.5; + } + else + { + uv = fragTexCoord.xy; + } + + vec4 color = texture2D(texture0, uv); + + color += texture2D(texture0, fragTexCoord + 0.001); + color += texture2D(texture0, fragTexCoord + 0.003); + color += texture2D(texture0, fragTexCoord + 0.005); + color += texture2D(texture0, fragTexCoord + 0.007); + color += texture2D(texture0, fragTexCoord + 0.009); + color += texture2D(texture0, fragTexCoord + 0.011); + + color += texture2D(texture0, fragTexCoord - 0.001); + color += texture2D(texture0, fragTexCoord - 0.003); + color += texture2D(texture0, fragTexCoord - 0.005); + color += texture2D(texture0, fragTexCoord - 0.007); + color += texture2D(texture0, fragTexCoord - 0.009); + color += texture2D(texture0, fragTexCoord - 0.011); + + color.rgb = vec3((color.r + color.g + color.b)/3.0); + color = color/9.5; + + float x = 1.0/renderWidth; + float y = 1.0/renderHeight; + + vec4 horizEdge = vec4(0.0); + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + + vec4 vertEdge = vec4(0.0); + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + + vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); + + vec3 texelColor = ((color + texture2D(texture0, uv)) * weight.x).rgb + edge; + + texelColor += texture2D(texture0, fragTexCoord + vec2(offset.y)/renderWidth, 0.0).rgb*weight.y; + texelColor += texture2D(texture0, fragTexCoord - vec2(offset.y)/renderWidth, 0.0).rgb*weight.y; + + texelColor += texture2D(texture0, fragTexCoord + vec2(offset.z)/renderWidth, 0.0).rgb*weight.z; + texelColor += texture2D(texture0, fragTexCoord - vec2(offset.z)/renderWidth, 0.0).rgb*weight.z; + + texelColor = pow(texelColor, vec3(gamma, gamma, gamma)); + texelColor = texelColor*numColors; + texelColor = floor(texelColor); + texelColor = texelColor/numColors; + texelColor = pow(texelColor, vec3(1.0/gamma)); + + gl_FragColor = vec4(texelColor, 1.0); +} diff --git a/assets/shaders/glsl100/postprocessing.fs b/assets/shaders/glsl100/postprocessing.fs index 69b906b..0009fa3 100644 --- a/assets/shaders/glsl100/postprocessing.fs +++ b/assets/shaders/glsl100/postprocessing.fs @@ -3,7 +3,6 @@ precision mediump float; varying vec2 fragTexCoord; -varying vec4 fragColor; uniform sampler2D texture0; uniform vec4 colDiffuse; diff --git a/assets/shaders/glsl330/fuck.fs b/assets/shaders/glsl330/fuck.fs new file mode 100644 index 0000000..5a4f63c --- /dev/null +++ b/assets/shaders/glsl330/fuck.fs @@ -0,0 +1,101 @@ +#version 330 + +// This is a fuck shader. It is very fuck. + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +const float PI = 3.1415926535; +const float aperture = 290.0; +const float renderWidth = 16; +const float renderHeight = 12; +const float gamma = 0.6; +const float numColors = 3.0; + +float offset[3] = float[](0.0, 1.3846153846, 3.2307692308); +float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703); + +void main() +{ + float apertureHalf = 0.5*aperture*(PI/180.0); + float maxFactor = sin(apertureHalf); + + vec2 uv = vec2(0); + vec2 xy = 2.0*fragTexCoord.xy - 1.0; + float d = length(xy); + + if (d < (2.0 - maxFactor)) + { + d = length(xy*maxFactor); + float z = sqrt(1.0 - d*d); + float r = atan(d, z)/PI; + float phi = atan(xy.y, xy.x); + + uv.x = r*cos(phi) + 0.5; + uv.y = r*sin(phi) + 0.5; + } + else + { + uv = fragTexCoord.xy; + } + + vec4 color = texture(texture0, uv); + + color += texture(texture0, fragTexCoord + 0.001); + color += texture(texture0, fragTexCoord + 0.003); + color += texture(texture0, fragTexCoord + 0.005); + color += texture(texture0, fragTexCoord + 0.007); + color += texture(texture0, fragTexCoord + 0.009); + color += texture(texture0, fragTexCoord + 0.011); + + color += texture(texture0, fragTexCoord - 0.001); + color += texture(texture0, fragTexCoord - 0.003); + color += texture(texture0, fragTexCoord - 0.005); + color += texture(texture0, fragTexCoord - 0.007); + color += texture(texture0, fragTexCoord - 0.009); + color += texture(texture0, fragTexCoord - 0.011); + + color.rgb = vec3((color.r + color.g + color.b)/3.0); + color = color/9.5; + + float x = 1.0/renderWidth; + float y = 1.0/renderHeight; + + vec4 horizEdge = vec4(0.0); + horizEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; + horizEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; + horizEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; + horizEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; + horizEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; + horizEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + + vec4 vertEdge = vec4(0.0); + vertEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; + vertEdge -= texture(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; + vertEdge -= texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; + vertEdge += texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; + vertEdge += texture(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; + vertEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + + vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); + + vec3 texelColor = ((color + texture(texture0, uv)) * weight[0]).rgb + edge; + + for (int i = 1; i < 3; i++) + { + texelColor += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; + texelColor += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; + } + + texelColor = pow(texelColor, vec3(gamma, gamma, gamma)); + texelColor = texelColor*numColors; + texelColor = floor(texelColor); + texelColor = texelColor/numColors; + texelColor = pow(texelColor, vec3(1.0/gamma)); + + fragColor = vec4(texelColor, 1.0); +} diff --git a/src/assets.c b/src/assets.c index c306e2c..ecb5ca0 100644 --- a/src/assets.c +++ b/src/assets.c @@ -25,7 +25,8 @@ const char imageAssetPaths[IMAGE_ASSET_COUNT][FT_NAMEMAX] = { const char shaderAssetNames[SHADER_ASSET_COUNT][FT_NAMEMAX] = { "skybox", "instancing", - "postprocessing" + "postprocessing", + "fuck" }; const char modelAssetPaths[MODEL_ASSET_COUNT][FT_NAMEMAX] = { diff --git a/src/assets.h b/src/assets.h index 1ad82d1..9f0c1a7 100644 --- a/src/assets.h +++ b/src/assets.h @@ -6,7 +6,7 @@ #define TEXTURE_ASSET_COUNT 15 #define IMAGE_ASSET_COUNT 1 -#define SHADER_ASSET_COUNT 3 +#define SHADER_ASSET_COUNT 4 #define MODEL_ASSET_COUNT 4 extern const char textureAssetPaths[TEXTURE_ASSET_COUNT][FT_NAMEMAX]; @@ -14,7 +14,7 @@ extern const char imageAssetPaths[IMAGE_ASSET_COUNT][FT_NAMEMAX]; extern const char shaderAssetNames[SHADER_ASSET_COUNT][FT_NAMEMAX]; extern const char modelAssetPaths[MODEL_ASSET_COUNT][FT_NAMEMAX]; -typedef int8_t AssetId; +typedef int16_t AssetId; // Texture asset ids. enum { @@ -44,7 +44,8 @@ enum { enum { SKYBOX_SHADER, INSTANCING_SHADER, - POSTPROCESSING_SHADER + POSTPROCESSING_SHADER, + FUCK_SHADER }; // Model asset ids. @@ -61,6 +61,7 @@ void initGame(Game* game) game->screen.render = LoadRenderTexture(game->settings.screenWidth, game->settings.screenHeight); resetScreenScale(game); + game->screen.postprocesserShader = POSTPROCESSING_SHADER; // Assets. initAssets(&game->assets, &game->settings); @@ -94,7 +95,7 @@ void drawGameScreen(Game* game) if (game->screen.ultraWideMode) { - BeginShaderMode(game->assets.shaders[POSTPROCESSING_SHADER]); + BeginShaderMode(game->assets.shaders[FUCK_SHADER]); DrawTexturePro( texture, (Rectangle){0.0, 0.0, texture.width, -texture.height}, @@ -109,7 +110,7 @@ void drawGameScreen(Game* game) } else { - BeginShaderMode(game->assets.shaders[POSTPROCESSING_SHADER]); + BeginShaderMode(game->assets.shaders[game->screen.postprocesserShader]); DrawTexturePro( texture, (Rectangle){0.0, 0.0, texture.width, -texture.height}, @@ -29,6 +29,7 @@ struct Game { RenderTexture render; float scale; Rectangle destination; + AssetId postprocesserShader; bool ultraWideMode; } screen; }; |
