}
barrow.max_iterations *= 1;
+#ifdef ENABLE_BARROWGEN
generate_rd(8, barrow, grid, grid_size);
+#endif
start_render_loop();
return 0;
#include <raylib.h>
#include <raymath.h>
-#include <stdio.h>
-#include <string.h>
+
#include "structs.h"
+#include "external/rlights.h"
+Vector2 fscreen_dims;
Camera3D cam;
Image barrow_image;
-
Texture barrow_texture;
Texture albedo_texture;
-
Model barrow_model;
Mesh barrow_meshes[1U];
Material barrow_material;
Vector3 barrow_position;
Vector3 barrow_scale;
+Shader shader;
+int cam_position_shader_loc;
+int screen_dims_shader_loc;
+
Vector3 player_velocity;
Vector3 player_rotation;
void initialize_renderer()
{
+ fscreen_dims = (Vector2){.x=screen_dims.x, .y=screen_dims.y};
+
+ shader = LoadShader("./src/shaders/lighting.vs", "./src/shaders/lighting.fs");
+ shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
+ shader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(shader, "mvp");
+ cam_position_shader_loc = GetShaderLocation(shader, "cam_position");
+ screen_dims_shader_loc = GetShaderLocation(shader, "screen_dims");
+ while(!IsShaderReady(shader)){}
+
//barrow_position = (Vector3){-8.0f, 0.0f, -8.0f};
barrow_position = (Vector3){-8.0f, 0.0f, -8.0f};
barrow_image = LoadImage("./barrow.png");
barrow_model = LoadModelFromMesh(barrow_meshes[0]);
barrow_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = albedo_texture;
barrow_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = albedo_texture;
+ barrow_model.materials[0].shader = shader;
cam = (Camera3D){0};
cam.position = barrow_position;
- cam.position.y += 3.0f;
+ cam.position.y += 2.0f;
cam.position.x = barrow_scale.x/2 + barrow_position.x;
- cam.target = (Vector3){0.0f, cam.position.y * 0.66f, 0.0f};
+ cam.target = (Vector3){0.0f, cam.position.y * 0.1, 0.0f};
cam.up = (Vector3){0.0f, 1.0f, 0.0f};
cam.fovy = 75.0f;
cam.projection= CAMERA_PERSPECTIVE;
void start_render_loop()
{
- InitWindow(screen_dims.x, screen_dims.y, screen_title);
+ InitWindow(fscreen_dims.x, fscreen_dims.y, screen_title);
initialize_renderer();
Rectangle minimap_dest = {.width = 64.0f*img_export_scale.x, .height = 64.0f*img_export_scale.y, .x = 0.0f, .y = 0.0f};
while (!WindowShouldClose())
{
process_inputs();
+ SetShaderValue(shader, cam_position_shader_loc, &cam.position, SHADER_UNIFORM_VEC3);
+ SetShaderValue(shader, screen_dims_shader_loc, &fscreen_dims, SHADER_UNIFORM_VEC2);
UpdateCameraPro(&cam, player_velocity, player_rotation, 0.0f);
BeginDrawing();
ClearBackground(BLACK);
BeginMode3D(cam);
+ BeginShaderMode(shader);
DrawModel(barrow_model, barrow_position, 1.0f, DARKGRAY);
+ EndShaderMode();
EndMode3D();
DrawTexturePro(barrow_texture, minimap_src, minimap_dest, (Vector2){0.0f, 0.0f}, 0.0f, RAYWHITE);
UnloadImage(barrow_image);
UnloadTexture(barrow_texture);
+ UnloadShader(shader);
CloseWindow();
}
--- /dev/null
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+in vec4 vertexCoord;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+uniform vec3 cam_position;
+uniform vec2 screen_dims;
+
+// Output fragment color
+out vec4 finalColor;
+
+const vec3 v3_unit = vec3(1.0f, 1.0f, 1.0f);
+float lumWeight = 0.0f;
+
+// A single iteration of Bob Jenkins' One-At-A-Time hashing algorithm.
+uint hash( uint x ) {
+ x += ( x << 10u );
+ x ^= ( x >> 6u );
+ x += ( x << 3u );
+ x ^= ( x >> 11u );
+ x += ( x << 15u );
+ return x;
+}
+
+// Compound versions of the hashing algorithm I whipped together.
+uint hash( uvec2 v ) { return hash( v.x ^ hash(v.y) ); }
+uint hash( uvec3 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ); }
+uint hash( uvec4 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w) ); }
+
+// Construct a float with half-open range [0:1] using low 23 bits.
+// All zeroes yields 0.0, all ones yields the next smallest representable value below 1.0.
+float floatConstruct( uint m ) {
+ const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask
+ const uint ieeeOne = 0x3F800000u; // 1.0 in IEEE binary32
+
+ m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
+ m |= ieeeOne; // Add fractional part to 1.0
+
+ float f = uintBitsToFloat( m ); // Range [1:2]
+ return f - 1.0; // Range [0:1]
+}
+
+// Pseudo-random value in half-open range [0:1].
+float random( float x ) { return floatConstruct(hash(floatBitsToUint(x))); }
+float random( vec2 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
+float random( vec3 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
+float random( vec4 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
+
+float easeInOutQuart(float x)
+{
+ return x < 0.5 ? 8 * x * x * x * x : 1 - pow(-2 * x + 2, 4) / 2;
+}
+float easeOutQuint(float x)
+{
+ return 1.0f - pow(1.0 - x, 5);
+}
+
+float easeInExpo(float x)
+{
+ return (x == 0.0) ? 0.0 : pow(2, 10 * x - 10);
+}
+
+float easeInCirc(float x)
+{
+ return 1 - sqrt(1 - pow(x, 2));
+}
+
+float easeInQuart(float x)
+{
+ return x * x * x * x;
+}
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture(texture0, fragTexCoord);
+
+ // NOTE: Implement here your fragment shader code
+
+ const float max_dist = 6.0f;
+ const float max_lum = 0.7f;
+ float cam_dist_z = gl_FragCoord.z/gl_FragCoord.w;
+ float norm_dist_z = cam_dist_z/max_dist;
+
+ finalColor = texelColor*colDiffuse;
+
+ if(cam_dist_z < max_dist)
+ {
+ float norm_x_dist = abs(gl_FragCoord.x - (screen_dims.x/2))/(screen_dims.x/2);
+ lumWeight = min(max_lum, 1.0f - easeInQuart(norm_dist_z));
+ }
+
+ vec3 lumWeights = v3_unit * lumWeight;
+ float lum = dot(finalColor.rgb, lumWeights);
+ float rand = random(fragTexCoord);
+ lumWeights *= lum;
+ finalColor.rgb = mix(vec3(227/255, 60/255, 0/255), finalColor.rgb, lumWeights);
+ finalColor.a = 1.0f;
+}
--- /dev/null
+#version 330
+
+in vec3 vertexPosition;
+in vec2 vertexTexCoord;
+in vec3 vertexNormal;
+in vec4 vertexColor;
+
+// Input uniform values
+uniform vec3 cam_position;
+uniform mat4 mvp;
+uniform vec3 viewPos;
+uniform vec2 screen_dims;
+
+// Output vertex attributes (to fragment shader)
+out vec2 fragTexCoord;
+out vec4 fragColor;
+out vec4 vertexCoord;
+
+// A single iteration of Bob Jenkins' One-At-A-Time hashing algorithm.
+uint hash( uint x ) {
+ x += ( x << 10u );
+ x ^= ( x >> 6u );
+ x += ( x << 3u );
+ x ^= ( x >> 11u );
+ x += ( x << 15u );
+ return x;
+}
+
+// Compound versions of the hashing algorithm I whipped together.
+uint hash( uvec2 v ) { return hash( v.x ^ hash(v.y) ); }
+uint hash( uvec3 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ); }
+uint hash( uvec4 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w) ); }
+
+// Construct a float with half-open range [0:1] using low 23 bits.
+// All zeroes yields 0.0, all ones yields the next smallest representable value below 1.0.
+float floatConstruct( uint m ) {
+ const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask
+ const uint ieeeOne = 0x3F800000u; // 1.0 in IEEE binary32
+
+ m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
+ m |= ieeeOne; // Add fractional part to 1.0
+
+ float f = uintBitsToFloat( m ); // Range [1:2]
+ return f - 1.0; // Range [0:1]
+}
+
+// Pseudo-random value in half-open range [0:1].
+float random( float x ) { return floatConstruct(hash(floatBitsToUint(x))); }
+float random( vec2 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
+float random( vec3 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
+float random( vec4 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
+
+void main()
+{
+ fragTexCoord = vertexTexCoord;
+ fragColor = vertexColor;
+
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+ gl_Position.y = gl_Position.y + (random(vertexPosition)/(4.0));
+ vertexCoord = gl_Position;
+}
#include "platform.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
-#include "stb_image_write.h"
+#include "external/stb_image_write.h"
#define STB_IMAGE_RESIZE_IMPLEMENTATION
-#include "stb_image_resize2.h"
+#include "external/stb_image_resize2.h"
#define SHADOW 1
#if SHADOW