Have 100 cubes flying around in a circle with refraction.
This commit is contained in:
parent
1107c86036
commit
a199d41890
7 changed files with 29 additions and 15 deletions
|
|
@ -58,6 +58,10 @@
|
||||||
"window": {
|
"window": {
|
||||||
"directory": "assets",
|
"directory": "assets",
|
||||||
"model_path": "window.glb"
|
"model_path": "window.glb"
|
||||||
|
},
|
||||||
|
"human": {
|
||||||
|
"directory": "../assets",
|
||||||
|
"model_path": "human.glb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"things": [
|
"things": [
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
in vec3 Normal;
|
||||||
|
in vec3 FragPos;
|
||||||
in vec2 TexCoords;
|
in vec2 TexCoords;
|
||||||
|
|
||||||
uniform sampler2D texture1;
|
uniform vec3 cameraPos;
|
||||||
|
uniform samplerCube skybox;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = texture(texture1, TexCoords);
|
float ratio = 1.0/1.52;
|
||||||
|
vec3 I = normalize(FragPos - cameraPos);
|
||||||
|
vec3 R = refract(I, normalize(Normal), ratio);
|
||||||
|
FragColor = vec4(texture(skybox, R).rgb, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,7 @@ uniform vec3 offsets[10];
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// THIS WORKS
|
|
||||||
// vec3 in_offset = offsets[gl_InstanceID];
|
|
||||||
|
|
||||||
// THIS DOES NOT, see Scene::setup_instancing and Mesh::draw
|
|
||||||
vec3 in_offset = aOffset;
|
vec3 in_offset = aOffset;
|
||||||
// in_offset.x = gl_InstanceID;
|
|
||||||
|
|
||||||
vec4 offset = vec4(aPos + in_offset, 1.0);
|
vec4 offset = vec4(aPos + in_offset, 1.0);
|
||||||
gl_Position = projection * view * model * offset;
|
gl_Position = projection * view * model * offset;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define INSTANCE_COUNT 10
|
#define INSTANCE_COUNT 100
|
||||||
|
|
||||||
const unsigned int SCR_WIDTH = 1792;
|
const unsigned int SCR_WIDTH = 1792;
|
||||||
const unsigned int SCR_HEIGHT = 1008;
|
const unsigned int SCR_HEIGHT = 1008;
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,7 @@ int main() {
|
||||||
glfwSetWindowUserPointer(window, &scene);
|
glfwSetWindowUserPointer(window, &scene);
|
||||||
|
|
||||||
while(!glfwWindowShouldClose(window)) {
|
while(!glfwWindowShouldClose(window)) {
|
||||||
|
scene.time_warp();
|
||||||
update(window, scene);
|
update(window, scene);
|
||||||
render(window, scene);
|
render(window, scene);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,11 +84,14 @@ void Scene::spawn(const std::string& name, components::Position& position, compo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::setup_instancing() {
|
void Scene::time_warp() {
|
||||||
|
float time = glfwGetTime();
|
||||||
for(size_t i = 0; i < INSTANCE_COUNT; i++) {
|
for(size_t i = 0; i < INSTANCE_COUNT; i++) {
|
||||||
translations[i].x = (float)i;
|
auto& t = translations[i];
|
||||||
translations[i].z = (float)i;
|
float factor = (float)i / 3.0f;
|
||||||
translations[i].y = 0.0f;
|
t.y = cos((time + i)) * factor;
|
||||||
|
t.z = sin((time + i)) * factor;
|
||||||
|
t.x = sin((time + i)) * factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenBuffers(1, &instanceVBO);
|
glGenBuffers(1, &instanceVBO);
|
||||||
|
|
@ -104,12 +107,16 @@ void Scene::setup_instancing() {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glVertexAttribDivisor(3, 1);
|
glVertexAttribDivisor(3, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// this works
|
void Scene::setup_instancing() {
|
||||||
shader.use();
|
|
||||||
for(size_t i = 0; i < INSTANCE_COUNT; i++) {
|
for(size_t i = 0; i < INSTANCE_COUNT; i++) {
|
||||||
shader.setVec3(std::format("offsets[{}]", i), translations[i]);
|
translations[i].x = (float)i;
|
||||||
|
translations[i].z = (float)i;
|
||||||
|
translations[i].y = (float)i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_warp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::init_skybox() {
|
void Scene::init_skybox() {
|
||||||
|
|
|
||||||
|
|
@ -101,4 +101,5 @@ struct Scene {
|
||||||
void load_skybox_textures();
|
void load_skybox_textures();
|
||||||
void render_skybox(const glm::mat4& projection);
|
void render_skybox(const glm::mat4& projection);
|
||||||
void setup_instancing();
|
void setup_instancing();
|
||||||
|
void time_warp();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue