generated from AfonsoCMSousa/CPP-Template
Fixed and added some minor color correction
This commit is contained in:
parent
0c861f6855
commit
9107273a0c
@ -68,10 +68,6 @@ else()
|
|||||||
target_link_options(${EXECUTABLE_NAME} PRIVATE -fsanitize=address,undefined)
|
target_link_options(${EXECUTABLE_NAME} PRIVATE -fsanitize=address,undefined)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# -----------------------
|
|
||||||
# External Dependencies
|
|
||||||
# -----------------------
|
|
||||||
|
|
||||||
# GLFW (if vendored in libraries/)
|
# GLFW (if vendored in libraries/)
|
||||||
if(EXISTS ${CMAKE_SOURCE_DIR}/libraries/glfw/CMakeLists.txt)
|
if(EXISTS ${CMAKE_SOURCE_DIR}/libraries/glfw/CMakeLists.txt)
|
||||||
add_subdirectory(${CMAKE_SOURCE_DIR}/libraries/glfw EXCLUDE_FROM_ALL)
|
add_subdirectory(${CMAKE_SOURCE_DIR}/libraries/glfw EXCLUDE_FROM_ALL)
|
||||||
|
|||||||
@ -76,25 +76,6 @@ vec2 morphingSeed(float t, float interval) {
|
|||||||
return mix(seedA, seedB, blend);
|
return mix(seedA, seedB, blend);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 morphingDirection(float t, float interval) {
|
|
||||||
float phase = floor(t / interval);
|
|
||||||
float blend = fract(t / interval);
|
|
||||||
|
|
||||||
// Generate 2 pseudo-random direction vectors
|
|
||||||
vec2 dirA = normalize(vec2(
|
|
||||||
sin(phase * 12.9898),
|
|
||||||
cos(phase * 78.233)
|
|
||||||
));
|
|
||||||
vec2 dirB = normalize(vec2(
|
|
||||||
sin((phase+1.0) * 93.9898),
|
|
||||||
cos((phase+1.0) * 47.233)
|
|
||||||
));
|
|
||||||
|
|
||||||
// Smooth interpolation between them
|
|
||||||
blend = smoothstep(0.0, 1.0, blend);
|
|
||||||
return normalize(mix(dirA, dirB, blend));
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec2 st = gl_FragCoord.xy / u_resolution.xy; // Normalize coordinates
|
vec2 st = gl_FragCoord.xy / u_resolution.xy; // Normalize coordinates
|
||||||
st.x *= u_resolution.x / u_resolution.y; // Correct aspect ratio
|
st.x *= u_resolution.x / u_resolution.y; // Correct aspect ratio
|
||||||
@ -104,7 +85,8 @@ void main() {
|
|||||||
st *= 2.05 * u_scale; // Zoom out
|
st *= 2.05 * u_scale; // Zoom out
|
||||||
vec2 seed = morphingSeed(u_time, 10.0); // 10 second interval
|
vec2 seed = morphingSeed(u_time, 10.0); // 10 second interval
|
||||||
|
|
||||||
vec2 pos = st + morphingDirection(u_time * 0.2, 15.0); // 15 second interval
|
vec2 pos = st; // 15 second interval
|
||||||
|
pos += vec2(0.3, 0.1) * u_time * 0.1;
|
||||||
|
|
||||||
float pre_noise = perlinNoise((pos) * 1.5); // N = [0..1]
|
float pre_noise = perlinNoise((pos) * 1.5); // N = [0..1]
|
||||||
// noise += 0.6 * perlinNoise(pos * 4.0);
|
// noise += 0.6 * perlinNoise(pos * 4.0);
|
||||||
@ -120,9 +102,9 @@ void main() {
|
|||||||
|
|
||||||
vec3 color;
|
vec3 color;
|
||||||
|
|
||||||
if (noise >= 0.9) {
|
if (noise >= 0.85) {
|
||||||
color = getPaletteColor(u_time * 0.1, noise);
|
color = getPaletteColor(u_time * 0.1, noise);
|
||||||
} else if (noise >= 0.76 ) {
|
} else if (noise >= 0.75 ) {
|
||||||
color = getPaletteColor((u_time * 0.1) + 1.0, noise);
|
color = getPaletteColor((u_time * 0.1) + 1.0, noise);
|
||||||
|
|
||||||
// Estimate gradient (2D normal)
|
// Estimate gradient (2D normal)
|
||||||
@ -145,7 +127,7 @@ void main() {
|
|||||||
float spec = pow(max(dot(normal, lightDir), 0.0), 32.0);
|
float spec = pow(max(dot(normal, lightDir), 0.0), 32.0);
|
||||||
|
|
||||||
// Combine Fresnel + spec
|
// Combine Fresnel + spec
|
||||||
float gloss = fresnel + 0.5 * spec;
|
float gloss = fresnel + 0.6 * spec;
|
||||||
|
|
||||||
// Stronger at edges (transition zone of blob)
|
// Stronger at edges (transition zone of blob)
|
||||||
float edge = smoothstep(0.8, 0.9, noise) * (1.0 - smoothstep(0.9, 1.0, noise));
|
float edge = smoothstep(0.8, 0.9, noise) * (1.0 - smoothstep(0.9, 1.0, noise));
|
||||||
@ -157,5 +139,7 @@ void main() {
|
|||||||
color = vec3(0.0);
|
color = vec3(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Denoise edges -> "Insane look-alike effect"
|
||||||
|
color += mix(color, vec3(0.0), smoothstep(0.0, 0.02, abs(noise - 0.9)));
|
||||||
FragColor = vec4(color, 1.0);
|
FragColor = vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,9 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
// glad and GLFW
|
// glad and GLFW
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
@ -7,11 +13,8 @@
|
|||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
// HPP files
|
||||||
#include <fstream>
|
#include "shader.h"
|
||||||
#include <sstream>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#define VERTEX_FILE "./shaders/vertex.glsl"
|
#define VERTEX_FILE "./shaders/vertex.glsl"
|
||||||
#define FRAGMENT_FILE "./shaders/fragment.glsl"
|
#define FRAGMENT_FILE "./shaders/fragment.glsl"
|
||||||
@ -20,85 +23,7 @@
|
|||||||
const float SCR_WIDTH = 1200.0f;
|
const float SCR_WIDTH = 1200.0f;
|
||||||
const float SCR_HEIGHT = 1200.0f;
|
const float SCR_HEIGHT = 1200.0f;
|
||||||
|
|
||||||
// Shader loader helper
|
int main(void) {
|
||||||
std::string loadShaderSource(const std::string& filepath) {
|
|
||||||
std::ifstream file(filepath);
|
|
||||||
if (!file.is_open()) {
|
|
||||||
std::cerr << "Failed to open shader file: " << filepath << std::endl;
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
std::stringstream buffer;
|
|
||||||
|
|
||||||
std::cout << "Loaded " << filepath << " successfully!\n";
|
|
||||||
|
|
||||||
buffer << file.rdbuf();
|
|
||||||
return buffer.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint compileShader(GLenum type, const std::string& source) {
|
|
||||||
GLuint shader = glCreateShader(type);
|
|
||||||
const char* src = source.c_str();
|
|
||||||
glShaderSource(shader, 1, &src, nullptr);
|
|
||||||
glCompileShader(shader);
|
|
||||||
|
|
||||||
int success;
|
|
||||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
|
||||||
if (!success) {
|
|
||||||
char infoLog[512];
|
|
||||||
glGetShaderInfoLog(shader, 512, nullptr, infoLog);
|
|
||||||
std::cerr << "Shader compilation failed:\n" << infoLog << std::endl;
|
|
||||||
exit(10);
|
|
||||||
}
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint createShaderProgram(const std::string& vertexPath, const std::string& fragmentPath) {
|
|
||||||
std::string vertexSrc = loadShaderSource(vertexPath);
|
|
||||||
std::string fragmentSrc = loadShaderSource(fragmentPath);
|
|
||||||
|
|
||||||
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexSrc);
|
|
||||||
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentSrc);
|
|
||||||
|
|
||||||
GLuint program = glCreateProgram();
|
|
||||||
glAttachShader(program, vertexShader);
|
|
||||||
glAttachShader(program, fragmentShader);
|
|
||||||
glLinkProgram(program);
|
|
||||||
|
|
||||||
int success;
|
|
||||||
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
|
||||||
if (!success) {
|
|
||||||
char infoLog[512];
|
|
||||||
glGetProgramInfoLog(program, 512, nullptr, infoLog);
|
|
||||||
std::cerr << "Shader linking failed:\n" << infoLog << std::endl;
|
|
||||||
exit(11);
|
|
||||||
}
|
|
||||||
|
|
||||||
glDeleteShader(vertexShader);
|
|
||||||
glDeleteShader(fragmentShader);
|
|
||||||
return program;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint createComputeProgram(const std::string& computePath) {
|
|
||||||
std::string computeSrc = loadShaderSource(computePath);
|
|
||||||
GLuint computeShader = compileShader(GL_COMPUTE_SHADER, computeSrc);
|
|
||||||
|
|
||||||
GLuint program = glCreateProgram();
|
|
||||||
glAttachShader(program, computeShader);
|
|
||||||
glLinkProgram(program);
|
|
||||||
|
|
||||||
int success;
|
|
||||||
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
|
||||||
if (!success) {
|
|
||||||
char infoLog[512];
|
|
||||||
glGetProgramInfoLog(program, 512, nullptr, infoLog);
|
|
||||||
std::cerr << "Compute shader linking failed:\n" << infoLog << std::endl;;
|
|
||||||
}
|
|
||||||
|
|
||||||
glDeleteShader(computeShader);
|
|
||||||
return program;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
// Initialize GLFW
|
// Initialize GLFW
|
||||||
if (!glfwInit()) return -1;
|
if (!glfwInit()) return -1;
|
||||||
|
|
||||||
@ -205,7 +130,6 @@ int main() {
|
|||||||
int frameCount = 0;
|
int frameCount = 0;
|
||||||
float mousePos[2] = {0.0f, 0.0f};
|
float mousePos[2] = {0.0f, 0.0f};
|
||||||
|
|
||||||
|
|
||||||
// FPS tracking
|
// FPS tracking
|
||||||
double lastTime = glfwGetTime(); // when we last printed FPS
|
double lastTime = glfwGetTime(); // when we last printed FPS
|
||||||
double fps = 0.0;
|
double fps = 0.0;
|
||||||
|
|||||||
@ -0,0 +1,80 @@
|
|||||||
|
#include "shader.h"
|
||||||
|
|
||||||
|
// Shader loader helper
|
||||||
|
std::string loadShaderSource(const std::string& filepath) {
|
||||||
|
std::ifstream file(filepath);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
std::cerr << "Failed to open shader file: " << filepath << std::endl;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::stringstream buffer;
|
||||||
|
|
||||||
|
std::cout << "Loaded " << filepath << " successfully!\n";
|
||||||
|
|
||||||
|
buffer << file.rdbuf();
|
||||||
|
return buffer.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint compileShader(GLenum type, const std::string& source) {
|
||||||
|
GLuint shader = glCreateShader(type);
|
||||||
|
const char* src = source.c_str();
|
||||||
|
glShaderSource(shader, 1, &src, nullptr);
|
||||||
|
glCompileShader(shader);
|
||||||
|
|
||||||
|
int success;
|
||||||
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||||
|
if (!success) {
|
||||||
|
char infoLog[512];
|
||||||
|
glGetShaderInfoLog(shader, 512, nullptr, infoLog);
|
||||||
|
std::cerr << "Shader compilation failed:\n" << infoLog << std::endl;
|
||||||
|
exit(10);
|
||||||
|
}
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint createShaderProgram(const std::string& vertexPath, const std::string& fragmentPath) {
|
||||||
|
std::string vertexSrc = loadShaderSource(vertexPath);
|
||||||
|
std::string fragmentSrc = loadShaderSource(fragmentPath);
|
||||||
|
|
||||||
|
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexSrc);
|
||||||
|
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentSrc);
|
||||||
|
|
||||||
|
GLuint program = glCreateProgram();
|
||||||
|
glAttachShader(program, vertexShader);
|
||||||
|
glAttachShader(program, fragmentShader);
|
||||||
|
glLinkProgram(program);
|
||||||
|
|
||||||
|
int success;
|
||||||
|
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
||||||
|
if (!success) {
|
||||||
|
char infoLog[512];
|
||||||
|
glGetProgramInfoLog(program, 512, nullptr, infoLog);
|
||||||
|
std::cerr << "Shader linking failed:\n" << infoLog << std::endl;
|
||||||
|
exit(11);
|
||||||
|
}
|
||||||
|
|
||||||
|
glDeleteShader(vertexShader);
|
||||||
|
glDeleteShader(fragmentShader);
|
||||||
|
return program;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GLuint createComputeProgram(const std::string& computePath) {
|
||||||
|
std::string computeSrc = loadShaderSource(computePath);
|
||||||
|
GLuint computeShader = compileShader(GL_COMPUTE_SHADER, computeSrc);
|
||||||
|
|
||||||
|
GLuint program = glCreateProgram();
|
||||||
|
glAttachShader(program, computeShader);
|
||||||
|
glLinkProgram(program);
|
||||||
|
|
||||||
|
int success;
|
||||||
|
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
||||||
|
if (!success) {
|
||||||
|
char infoLog[512];
|
||||||
|
glGetProgramInfoLog(program, 512, nullptr, infoLog);
|
||||||
|
std::cerr << "Compute shader linking failed:\n" << infoLog << std::endl;;
|
||||||
|
}
|
||||||
|
|
||||||
|
glDeleteShader(computeShader);
|
||||||
|
return program;
|
||||||
|
} */
|
||||||
|
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef SHADER_HPP
|
||||||
|
#define SHADER_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
// Shader loader helper
|
||||||
|
std::string loadShaderSource(const std::string& filepath);
|
||||||
|
|
||||||
|
// Compile a shader of given type from source code
|
||||||
|
GLuint compileShader(GLenum type, const std::string& source);
|
||||||
|
|
||||||
|
// Create a shader program from vertex and fragment shader file paths
|
||||||
|
GLuint createShaderProgram(const std::string& vertexPath, const std::string& fragmentPath);
|
||||||
|
|
||||||
|
// Create a compute shader program from compute shader file path
|
||||||
|
GLuint createComputeProgram(const std::string& computePath);
|
||||||
|
|
||||||
|
#endif // SHADER_HPP
|
||||||
Loading…
x
Reference in New Issue
Block a user