This commit is contained in:
huaqo-games
2025-10-26 21:24:31 +01:00
parent f7b84f9016
commit 66b961d7ab
22 changed files with 406 additions and 165 deletions
-11
View File
@@ -1,16 +1,5 @@
{
"configurations": [
{
"name": "macOS",
"includePath": [
"${workspaceFolder}/include",
"${workspaceFolder}/external/engine",
"${workspaceFolder}/external/raygui",
"${workspaceFolder}/external/rini",
"/opt/homebrew/Cellar/raylib/5.5/include"
],
"cStandard": "c99",
},
{
"name": "Windows",
"includePath": [
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
View File
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 395 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 KiB

+4 -3
View File
@@ -1,9 +1,10 @@
startView = 0 ; LOGO = 0, MENU = 1, GAMEPLAY = 2
startView = 1 ; LOGO = 0, MENU = 1, GAMEPLAY = 2, SETTINGS = 3
window_title = The Last Hive
window_title = The Last Pirate
window_width = 1280 ; in Pixel
window_height = 720 ; in Pixel
showFPS = 1 ; OFF = 0, ON = 1
showFPS = 0 ; OFF = 0, ON = 1
soundtrackOn = 1 ; OFF = 0, ON = 1
font_path = assets/SproutLandsUI/fonts/pixelFont-7-8x14-sproutLands.fnt
+1 -1
View File
@@ -17,7 +17,7 @@ PostProcessing CreatePostFX(const char* shaderPath){
return postFX;
}
postFX.strength = 0.3f;
postFX.strength = 0.0f;
postFX.resolutionLoc = GetShaderLocation(postFX.shader, "resolution");
postFX.strengthLoc = GetShaderLocation(postFX.shader, "strength");
Vector2 resolution = { (float)GetScreenWidth(), (float)GetScreenHeight() };
+85 -4
View File
@@ -1,37 +1,108 @@
#ifndef Floor_H
#define Floor_H
#include <raylib.h>
#include <sprite.h>
typedef struct
{
Sprite sprite;
Rectangle bounds;
Shader shader;
float time;
} Floor;
Floor CreateFloor(Texture2D texture, float textureWidth)
// ----------------------------------------------------
// Create floor (loads shader and sets defaults)
// ----------------------------------------------------
Floor CreateFloor()
{
return (Floor){
Texture2D base = LoadTexture("assets/ocean_base.png");
Texture2D caustic = LoadTexture("assets/CausticTexture.png");
Texture2D causticHighlight = LoadTexture("assets/CausticTextureHighlights.png");
Texture2D noise = LoadTexture("assets/noiseTexture.png");
Texture2D cloud = LoadTexture("assets/cloudnoise_1.png");
Texture2D voronoise = LoadTexture("assets/voronoise_3.png");
float textureWidth = 64.0f;
Floor floor = {
.sprite = {
.texture = texture,
.texture = base,
.frameSize = {textureWidth, textureWidth},
.sourceRec = {0.0f, 0.0f, textureWidth, textureWidth},
.destRec = {0.0f, 0.0f, textureWidth, textureWidth},
.origin = {textureWidth / 2, textureWidth / 2},
.rotation = 0.0f,
.color = WHITE},
.bounds = {0.0f, 0.0f, 0.0f, 0.0f}};
.bounds = {0},
.shader = LoadShader("shaders/water.vs", "shaders/water.fs"),
.time = 0.0f
};
float worldTileSize = 128.0f; // one tile covers 128x128 world units
float textureSize = 32.0f; // texture is 32x32 pixels
floor.sprite.frameSize = (Vector2){worldTileSize, worldTileSize};
floor.sprite.sourceRec = (Rectangle){0, 0, textureSize, textureSize};
floor.sprite.destRec = (Rectangle){0, 0, worldTileSize, worldTileSize};
floor.sprite.origin = (Vector2){0, 0};
// Optional: load your extra water textures here and bind them
// Example:
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticTexture"), caustic);
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticHighlightTexture"), causticHighlight);
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticNoiseTexture"), noise);
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticFadeNoiseTexture"), cloud);
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "specularNoiseTexture"), voronoise);
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "specularMovementLeftNoiseTexture"), voronoise);
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "specularMovementRightNoiseTexture"), cloud);
// Texture2D caustic = LoadTexture("resources/caustic.png");
// SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticTexture"), caustic);
// Setup aspect ratio and pixelization uniforms once
float aspect = (float)GetScreenHeight() / (float)GetScreenWidth();
float pixelization = 2048.0f;
int aspectLoc = GetShaderLocation(floor.shader, "aspectRatio");
int pixelLoc = GetShaderLocation(floor.shader, "pixelization");
SetShaderValue(floor.shader, aspectLoc, &aspect, SHADER_UNIFORM_FLOAT);
SetShaderValue(floor.shader, pixelLoc, &pixelization, SHADER_UNIFORM_FLOAT);
floor.sprite.texture = base;
return floor;
}
// ----------------------------------------------------
// Update visible area (same logic as before)
// ----------------------------------------------------
void UpdateFloor(Floor *floor, const Camera2D *camera)
{
floor->bounds.x = (int)((camera->target.x - (GetScreenWidth() / 2.0f / camera->zoom)) / floor->sprite.frameSize.x) - 1;
floor->bounds.width = (int)((camera->target.x + (GetScreenWidth() / 2.0f / camera->zoom)) / floor->sprite.frameSize.x) + 1;
floor->bounds.y = (int)((camera->target.y - (GetScreenHeight() / 2.0f / camera->zoom)) / floor->sprite.frameSize.y) - 1;
floor->bounds.height = (int)((camera->target.y + (GetScreenHeight() / 2.0f / camera->zoom)) / floor->sprite.frameSize.y) + 1;
// Update time uniform
floor->time += GetFrameTime();
int timeLoc = GetShaderLocation(floor->shader, "time");
SetShaderValue(floor->shader, timeLoc, &floor->time, SHADER_UNIFORM_FLOAT);
}
// ----------------------------------------------------
// Render floor tiles using the shader
// ----------------------------------------------------
void RenderFloor(Floor *floor)
{
BeginShaderMode(floor->shader);
for (int y = (int)floor->bounds.y; y <= (int)floor->bounds.height; y++)
{
for (int x = (int)floor->bounds.x; x <= (int)floor->bounds.width; x++)
@@ -41,6 +112,16 @@ void RenderFloor(Floor *floor)
RenderSprite(&floor->sprite);
}
}
EndShaderMode();
}
// ----------------------------------------------------
// Cleanup
// ----------------------------------------------------
void UnloadFloor(Floor *floor)
{
UnloadShader(floor->shader);
}
#endif // Floor_H
+15 -35
View File
@@ -1,21 +1,16 @@
#ifndef GAME_H
#define GAME_H
#include <object.h>
#include <camera.h>
#include <input.h>
#include "floor.h"
#include "player.h"
#include "gameassets.h"
#include <postfx.h>
#include <soundtrack.h>
#include <asset.h>
#include <array.h>
#include <stdlib.h>
#include "gameassets.h"
#include "floor.h"
#include "player.h"
#include "bee.h"
#include "hive.h"
#include "flowers.h"
typedef struct
{
@@ -25,10 +20,7 @@ typedef struct
Soundtrack soundtracks[SOUNDTRACK_COUNT];
RenderTexture2D target;
Floor floor;
Object hive;
Array* flowers;
Player player;
Bee bee1;
Camera2D camera;
Mouse mouse;
Image image;
@@ -57,22 +49,13 @@ void InitGame(GameState *g, Window *window)
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
}
// Target texture
g->target = LoadRenderTexture(window->width, window->height);
// Static Entities
g->flowers = CreateFlowers(g->textures[FLOWER], g->assets.textureAssets[FLOWER].frameWidth, g->assets.textureAssets[FLOWER].rotation, 50.0f);
g->floor = CreateFloor(g->textures[GRASS], g->assets.textureAssets[GRASS].frameWidth);
g->hive = CreateHive(g->textures[HIVE], g->assets.textureAssets[HIVE].frameWidth);
// Animated Entities
g->player = CreatePlayer(IDLE_DOWN, HOE, g->textures[PLAYER], g->assets.textureAssets[PLAYER].frameWidth, 4, 2, g->hive.position, g->assets.textureAssets[PLAYER].rotation, 50.0f);
// g->bee1 = CreateBee(FLYING, g->textures[BEE], g->assets.textureAssets[BEE].frameWidth, 4, 10, g->hive.position, 10.0f, &g->flowers, &g->hive);
// I/O
g->player = CreatePlayer();
g->floor = CreateFloor();
g->camera = CreateCamera(window->width, window->height, g->player.physics.position, 10.0f);
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &g->textures[CURSOR]);
Texture2D mouseTexture = LoadTexture("assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png");
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture);
}
void UpdateGame(GameState *g, State *state, Flags *flags)
@@ -85,14 +68,17 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
{
SetTargetFPS(0);
}
if (IsKeyPressed(KEY_ESCAPE))
{
state->currentView = MENU;
}
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))
{
state->running = false;
}
for (int i = 0; i < SHADER_COUNT; i++)
{
UpdatePostFX(&g->postFX[i]);
@@ -105,18 +91,13 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
UpdateMouse(&g->mouse, &g->camera);
UpdateCamera2D(&g->camera, &g->player.physics.position, &g->mouse);
UpdateFloor(&g->floor, &g->camera);
UpdatePlayer(&g->player, g->flowers);
UpdateArray(g->flowers, UpdateFlower);
// UpdateBee(&g->bee1, &g->flowers, &g->hive);
UpdatePlayer(&g->player);
}
void RenderComponents(GameState *g)
{
RenderFloor(&g->floor);
RenderSprite(&g->hive.sprite);
RenderArray(g->flowers, RenderFlower);
RenderSprite(&g->player.sprite);
RenderSprite(&g->bee1.sprite);
RenderPlayer(&g->player);
}
void RenderGame(GameState *g, const State *appState, Flags *flags)
@@ -128,13 +109,13 @@ void RenderGame(GameState *g, const State *appState, Flags *flags)
EndMode2D();
DrawTextureRec(g->mouse.cursorTexture, (Rectangle){0, 0, g->mouse.cursorTexture.width, g->mouse.cursorTexture.height}, (Vector2){g->mouse.screenPosition.x, g->mouse.screenPosition.y}, WHITE);
EndTextureMode();
BeginDrawing();
ClearBackground(BLACK);
for (int i = 0; i < SHADER_COUNT; i++)
{
RenderPostFX(&g->postFX[i], &g->target);
}
DrawText(TextFormat("Flower Seeds: %d", g->player.inventar.flowerSeedCount), 10, 10, 50, WHITE);
if (flags->showFPS)
{
@@ -162,7 +143,6 @@ void CleanupGame(GameState *g)
UnloadMusicStream(g->soundtracks[i].music);
}
UnloadRenderTexture(g->target);
FreeArray(&g->flowers);
}
#endif // GAME_H
+2 -2
View File
@@ -18,7 +18,7 @@ typedef enum
} TextureID;
const TextureAsset texAssets[TEX_COUNT] = {
{"assets/SproutLandsBasic/Characters/character.png", 48.0f, 48.0f, 0.0f},
{"assets/ship.png", 32.0f, 32.0f, 0.0f},
{"assets/SproutLandsBasic/Characters/BasicCharakterActions.png", 48.0f, 48.0f, 0.0f},
{"assets/SproutLandsBasic/Objects/tools.png", 48.0f, 16.0f, 0.0f},
{"assets/carrot_and_tomato.png", 32.0f, 32.0f, 0.0f},
@@ -47,7 +47,7 @@ typedef enum
} SoundtrackID;
const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = {
{"assets/beez.mp3"}};
{"assets/sea.mp3"}};
////////////////////////////////////////////////////////////////////////////
+19
View File
@@ -0,0 +1,19 @@
#ifndef GAMEUI
#define GAMEUI
#include "flags.h"
void RenderGameUI(bool showFPS){
BeginDrawing();
ClearBackground(BLACK);
if (showFPS)
{
DrawFPS(10, 10);
}
EndDrawing();
}
#endif //GAMEUI
+106 -103
View File
@@ -5,145 +5,148 @@
#include <animation.h>
#include <physics.h>
#include <input.h>
#include <array.h>
#include <asset.h>
#include "flowers.h"
#include "inventar.h"
typedef enum
{
IDLE,
WALKING,
USING_TOOL
} PlayerState;
START_SHIP,
PLAYER_TEX_COUNT
} playerTextureID;
typedef enum
{
NO_TOOL,
HOE,
AXT,
CAN
} SelectedTool;
const TextureAsset textureAssets[PLAYER_TEX_COUNT] = {
{"assets/start_ship.png", 16.0f, 16.0f, 0.0f}
};
typedef enum {
ANCHOR,
SLOW_AHEAD,
FAST_AHEAD,
SPEED_COUNT
} playerSpeedID;
float playerSpeeds[SPEED_COUNT] = {
0.0f,
5.0f,
10.0f
};
typedef enum
{
IDLE_DOWN,
IDLE_UP,
IDLE_LEFT,
IDLE_RIGHT,
WALKING_DOWN,
WALKING_UP,
WALKING_LEFT,
WALKING_RIGHT,
HOE_DOWN,
HOE_UP,
HOE_RIGHT,
HOE_LEFT,
AXT_DOWN,
AXT_UP,
AXT_RIGHT,
AXT_LEFT,
CAN_DOWN,
CAN_UP,
CAN_RIGHT,
CAN_LEFT,
} PlayerAnimationState;
typedef struct
{
SelectedTool selectedTool;
Sprite sprite;
Animation animation;
Physics physics;
Inventar inventar;
float rotation;
} Player;
Player CreatePlayer(PlayerAnimationState animState, SelectedTool selectedTool, Texture2D texture, float frameWidth, int maxFrame, int framesSpeed, Vector2 startPosition, float rotation, float speed)
Player CreatePlayer(void)
{
return (Player){
.selectedTool = selectedTool,
.sprite = {
TextureAsset startShipAsset = textureAssets[START_SHIP];
Texture2D texture = LoadTexture(startShipAsset.path);
float frameWidth = startShipAsset.frameWidth;
float rotation = startShipAsset.rotation;
Sprite playerSprite = {
.texture = texture,
.frameSize = {frameWidth, frameWidth},
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
.destRec = {0.0f, 0.0f, frameWidth, frameWidth},
.origin = {frameWidth / 2, frameWidth / 2},
.rotation = rotation,
.color = WHITE},
.animation = {.state = animState, .currentFrame = 0, .maxFrame = maxFrame, .framesCounter = 0, .framesSpeed = framesSpeed, .animTimer = 0.0f},
.physics = {.position = startPosition, .direction = (Vector2){0.0f, 0.0f}, .speed = speed},
.inventar = {.flowerSeedCount = 6}};
.color = WHITE
};
Animation playerAnimation = {
.state = 1,
.currentFrame = 0,
.maxFrame = 3,
.framesCounter = 0,
.framesSpeed = 0.0f,
.animTimer = 0.0f
};
Physics playerPhysics = {
.position = (Vector2){0.0f,0.0f},
.direction = (Vector2){0.0f, 0.0f},
.speed = playerSpeeds[ANCHOR]
};
return (Player){
.sprite = playerSprite,
.animation = playerAnimation,
.physics = playerPhysics,
.rotation = rotation
};
}
void UpdatePlayerAnimationState(int *state, SelectedTool *selectedTool, Vector2 *dir)
void UpdatePlayer(Player *player)
{
if (IsKeyPressed(KEY_ZERO))
{
*selectedTool = NO_TOOL;
}
if (IsKeyPressed(KEY_ONE))
{
*selectedTool = HOE;
}
if (IsKeyPressed(KEY_TWO))
{
*selectedTool = AXT;
if(IsKeyPressed(KEY_W) || IsKeyPressed(KEY_UP)){
if(player->physics.speed < playerSpeeds[FAST_AHEAD]){
if(player->physics.speed < playerSpeeds[SLOW_AHEAD]){
player->physics.speed = playerSpeeds[SLOW_AHEAD];
player->sprite.sourceRec.x = 16.0f * 1;
}
if (IsKeyPressed(KEY_THREE))
{
*selectedTool = CAN;
else {
player->physics.speed = playerSpeeds[FAST_AHEAD];
player->sprite.sourceRec.x = 16.0f * 2;
}
if (dir->x == 0 && dir->y == 0)
{
switch (*state)
{
case WALKING_DOWN:
*state = IDLE_DOWN;
break;
case WALKING_UP:
*state = IDLE_UP;
break;
case WALKING_LEFT:
*state = IDLE_LEFT;
break;
case WALKING_RIGHT:
*state = IDLE_RIGHT;
break;
default:
break;
}
}
else
{
if (dir->y == 1)
*state = WALKING_DOWN;
else if (dir->y == -1)
*state = WALKING_UP;
else if (dir->x == -1)
*state = WALKING_LEFT;
else if (dir->x == 1)
*state = WALKING_RIGHT;
}
}
void UpdatePlayer(Player *player, Array* flowers)
{
if (IsKeyPressed(KEY_SPACE) && player->inventar.flowerSeedCount > 0)
{
AddFlower(flowers, player->sprite.destRec);
player->inventar.flowerSeedCount--;
if(IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)){
if(player->physics.speed > playerSpeeds[ANCHOR]){
if(player->physics.speed > playerSpeeds[SLOW_AHEAD]){
player->physics.speed = playerSpeeds[SLOW_AHEAD];
player->sprite.sourceRec.x = 16.0f * 1;
}
Vector2 dir = GetDirectionVector();
UpdatePlayerAnimationState(&player->animation.state, &player->selectedTool, &dir);
else {
player->physics.speed = playerSpeeds[ANCHOR];
player->sprite.sourceRec.x = 16.0f * 0;
}
}
}
float rotationSpeed = 100.0f;
if (player->physics.speed > playerSpeeds[ANCHOR]){
if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) {
player->rotation -= rotationSpeed * GetFrameTime();
}
if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) {
player->rotation += rotationSpeed * GetFrameTime();
}
}
player->sprite.rotation = player->rotation;
float rad = (player->rotation - 90.0f) * (PI / 180.0f);
Vector2 dir = { cosf(rad), sinf(rad) };
UpdatePhysics(&player->physics, dir);
UpdateSpriteDestRec(&player->sprite, &player->physics.position);
UpdateAnimation(&player->animation, GetFrameTime());
UpdateSpriteSourceRec(&player->sprite, &(Vector2){player->sprite.frameSize.x * player->animation.currentFrame, player->sprite.frameSize.y * player->animation.state});
//UpdateAnimation(&player->animation, GetFrameTime());
//UpdateSpriteSourceRec(&player->sprite, &(Vector2){player->sprite.frameSize.x * player->animation.currentFrame, player->sprite.frameSize.y * player->animation.state});
}
void RenderPlayer(Player *player){
RenderSprite(&player->sprite);
}
#endif // PLAYER_H
View File
+14
View File
@@ -0,0 +1,14 @@
✅ Notes for using in Raylib
Vertex shader: You can use the default Raylib one (default.vs).
Time uniform: Update each frame in C:
float t = GetTime();
SetShaderValue(shader, GetShaderLocation(shader, "time"), &t, SHADER_UNIFORM_FLOAT);
Other textures: Bind them using SetShaderTexture(shader, loc, texture).
If you want, I can also write a full Raylib C snippet showing exactly how to load this shader and set all the textures and uniforms.
Do you want me to do that?
+137
View File
@@ -0,0 +1,137 @@
#version 330
// -----------------------------
// Inputs
in vec2 fragTexCoord;
in vec4 fragColor;
// -----------------------------
// Outputs
out vec4 finalColor;
// -----------------------------
// Uniforms
uniform sampler2D texture0; // main texture
uniform sampler2D waterDepthGradient;
uniform sampler2D causticTexture;
uniform sampler2D causticHighlightTexture;
uniform sampler2D causticNoiseTexture;
uniform sampler2D causticFadeNoiseTexture;
uniform sampler2D specularNoiseTexture;
uniform sampler2D specularMovementLeftNoiseTexture;
uniform sampler2D specularMovementRightNoiseTexture;
uniform sampler2D foamTexture;
uniform float aspectRatio = 1.0;
uniform float pixelization = 2048.0;
uniform vec4 causticColor = vec4(0.455, 0.773, 0.765, 1.0);
uniform vec4 causticHighlightColor = vec4(0.741, 0.894, 0.898, 1.0);
uniform float causticScale = 12.0;
uniform float causticSpeed = 0.005;
uniform float causticMovementAmount = 0.15;
uniform float causticFaderMultiplier = 1.45;
uniform vec4 specularColor = vec4(1.0, 1.0, 1.0, 1.0);
uniform float specularThreshold = 0.35;
uniform float specularSpeed = 0.025;
uniform float specularScale = 15.0;
uniform vec4 foamColor = vec4(1.0, 1.0, 1.0, 1.0);
uniform float foamIntensity = 0.2;
uniform float foamScale = 15.0;
uniform vec4 outlineColor = vec4(0.675, 0.86, 1.0, 1.0);
uniform float generalTransparency = 1.0;
uniform float time;
// -----------------------------
// Helper functions
vec2 blendSubtract_vec2(vec2 base, vec2 blend, float opacity)
{
vec2 result = base - blend;
return mix(base, result, opacity);
}
float blendSubtract_float(float base, float blend, float opacity)
{
float result = base - blend;
return mix(base, result, opacity);
}
float blendOverlay_float(float base, float blend, float opacity)
{
float result1 = 1.0 - 2.0 * (1.0 - base) * (1.0 - blend);
float result2 = 2.0 * base * blend;
float zeroOrOne = step(0.5, base);
float res = result2 * zeroOrOne + (1.0 - zeroOrOne) * result1;
return mix(base, res, opacity);
}
vec2 pixelizeCoordinates(vec2 coordinates)
{
return floor(coordinates * pixelization) / pixelization;
}
vec2 applyAspectRatio(vec2 coordinates)
{
return vec2(coordinates.x, coordinates.y * aspectRatio);
}
// -----------------------------
// Shader layers
vec4 caustics(vec2 pixelizedCoordinates)
{
vec4 causticNoise = texture(causticNoiseTexture, time * causticSpeed + pixelizedCoordinates);
vec2 noiseCoordinates = blendSubtract_vec2(pixelizedCoordinates * causticScale, causticNoise.rg, causticMovementAmount);
vec4 causticHighlight = texture(causticHighlightTexture, noiseCoordinates) * causticHighlightColor;
vec4 caustic = texture(causticTexture, noiseCoordinates) * causticColor;
vec4 interpolatedCaustics = mix(caustic, causticHighlight, causticHighlight.a);
float fadeNoise = texture(causticFadeNoiseTexture, noiseCoordinates).r * causticFaderMultiplier;
return vec4(interpolatedCaustics.rgb, clamp(interpolatedCaustics.a - fadeNoise, 0.0, 1.0));
}
vec4 specular(vec2 pixelizedCoordinates)
{
vec2 scaledCoordinates = pixelizedCoordinates * specularScale;
float specularNoise = texture(specularNoiseTexture, scaledCoordinates).r;
float leftScrollingNoise = texture(specularMovementLeftNoiseTexture, scaledCoordinates + vec2(time * specularSpeed, 0.0)).r;
float rightScrollingNoise = texture(specularMovementRightNoiseTexture, scaledCoordinates + vec2(time * specularSpeed * -1.0, 0.0)).r;
float combined = blendSubtract_float(blendOverlay_float(leftScrollingNoise, rightScrollingNoise, 1.0), specularNoise, 1.0);
return step(specularThreshold, combined) * specularColor;
}
vec4 foam(vec2 pixelizedCoordinates, vec4 mainTexColor)
{
vec4 colorizedFoam = texture(foamTexture, pixelizedCoordinates * foamScale) * foamColor;
float intensity = clamp(mainTexColor.g * mainTexColor.a - foamIntensity, 0.0, 1.0);
return vec4(colorizedFoam.rgb, colorizedFoam.a * intensity);
}
// -----------------------------
// Main fragment
void main()
{
vec2 pixelizedCoordinates = pixelizeCoordinates(applyAspectRatio(fragTexCoord));
vec4 mainTex = texture(texture0, fragTexCoord);
vec4 depthBasedWaterColor = texture(waterDepthGradient, vec2(1.0 - mainTex.b, 1.0));
vec4 finalCaustics = caustics(pixelizedCoordinates);
vec4 finalSpecular = specular(pixelizedCoordinates);
vec4 finalFoam = foam(pixelizedCoordinates, mainTex);
vec4 waterWithCausticLayer = mix(depthBasedWaterColor, finalCaustics, finalCaustics.a);
vec4 waterWithCausticAndSpecularLayer = mix(waterWithCausticLayer, finalSpecular, ceil(finalCaustics.a) * finalSpecular.a);
vec4 waterWithCausticAndSpecularAndFoamLayer = mix(waterWithCausticAndSpecularLayer, finalFoam, finalFoam.a);
float outline = mainTex.a * mainTex.r;
vec4 finalOutlineColor = outline * outlineColor;
vec4 finalRGBColor = mix(waterWithCausticAndSpecularAndFoamLayer, finalOutlineColor, outline);
finalColor = vec4(finalRGBColor.rgb, mainTex.b * generalTransparency);
}
+17
View File
@@ -0,0 +1,17 @@
#version 330
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec4 vertexColor;
out vec2 fragTexCoord;
out vec4 fragColor;
uniform mat4 mvp;
void main()
{
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
gl_Position = mvp * vec4(vertexPosition, 1.0);
}