just pushing what I have
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m20s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m20s
This commit is contained in:
@@ -22,7 +22,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME J3ML
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.4.zip
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/3.4.2.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
|
@@ -64,8 +64,7 @@ namespace JGL::J2D {
|
||||
|
||||
/// Provide a list of lights to be used in 2D space. Typically directly after J2D::Begin();
|
||||
/// 8 lights maximum for now. Some kind of light sorting will eventually be needed per j2d element.
|
||||
void LightArray(Light*, size_t size);
|
||||
void LightArray(std::vector<Light> lights);
|
||||
void LightArray(LightBase*, size_t light_count);
|
||||
|
||||
/// Plots a single pixel on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
@@ -360,6 +359,13 @@ namespace JGL::J2D {
|
||||
|
||||
/// Drawing functions for primitive 3D Shapes.
|
||||
namespace JGL::J3D {
|
||||
/// A light for this 3D render that should never be culled out. up-to 8.
|
||||
/// The more you put here, The less we will solve for if you're also using LightArray.
|
||||
/// @note More than 8 lights will cause an error to be printed.
|
||||
void RequiredLight(const LightBase* light);
|
||||
|
||||
/// When each 3D object is drawn, We'll do our best to determine which lights would effect it the most and use those ones.
|
||||
void LightArray(const LightBase** lights, const size_t& light_count);
|
||||
|
||||
/// Helper function to conveniently change the Field-Of-View.
|
||||
void ChangeFOV(float fov);
|
||||
@@ -614,7 +620,7 @@ namespace JGL::J3D {
|
||||
/// @param position The center-position of the oriented bounding box.
|
||||
/// @param radii The radii along x,y,z axes to size the bounding box.
|
||||
/// @param orientation The rotation in 3D space of the OBB.
|
||||
void FillOBB(const Color4& color, const Vector3& position, const Vector3& radii, const EulerAngle& orientation);
|
||||
void FillOBB(const Color4& color, const Vector3& position, const Vector3& radii, const EulerAngleXYZ& orientation);
|
||||
|
||||
/// Draws a solid oriented bounding box in 3D space.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
@@ -646,7 +652,7 @@ namespace JGL::J3D {
|
||||
/// @param font The font object to use when drawing.
|
||||
/// @param angle The orientation in 3D space.
|
||||
/// @param draw_back_face
|
||||
void DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font, const EulerAngle& angle = {0, 0, 0}, bool draw_back_face = false);
|
||||
void DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font, const EulerAngleXYZ& angle = {0, 0, 0}, bool draw_back_face = false);
|
||||
|
||||
/// Draws a string of text in 3D space that is always facing the exact direction of the camera projection.
|
||||
void DrawBillboardString();
|
||||
|
@@ -1,30 +1,50 @@
|
||||
#pragma once
|
||||
#include <J3ML/LinearAlgebra/Vector4.hpp>
|
||||
#include <J3ML/LinearAlgebra/Vector3.hpp>
|
||||
#include <J3ML/LinearAlgebra/DirectionVector.hpp>
|
||||
#include <J3ML/Geometry/Frustum.hpp>
|
||||
#include <Color4.hpp>
|
||||
|
||||
namespace JGL {
|
||||
class Light;
|
||||
class OmnidirectionalLight2D;
|
||||
class PointLight2D;
|
||||
class LightBase;
|
||||
class PointLight;
|
||||
class SpotLight;
|
||||
}
|
||||
|
||||
class JGL::Light {
|
||||
private:
|
||||
/// W in position seems to determine whether or not the light is omni-directional. 1 = omni 0 = point.
|
||||
/// Position is un-normalized screen space. For ex 500, 500, 1 for a light coming from where you're sitting.
|
||||
class JGL::LightBase {
|
||||
protected:
|
||||
Vector4 position = {0, 0, 0, 1};
|
||||
Color4 ambient = {0, 0, 0, 0};
|
||||
Color4 diffuse = {0, 0, 0, 0};
|
||||
Color4 specular = {0, 0, 0, 0};
|
||||
|
||||
float constant_attenuation;
|
||||
float linear_attenuation;
|
||||
float quadratic_attenuation;
|
||||
public:
|
||||
Light(const Vector3& position, const Color4& ambient, const Color4& diffuse, const Color4& specular);
|
||||
Vector3 GetNormalizedSceenSpaceCoordinates() const;
|
||||
virtual ~LightBase() = default;
|
||||
};
|
||||
|
||||
class JGL::OmnidirectionalLight2D {
|
||||
private:
|
||||
/// Omni-directional lights.
|
||||
class JGL::PointLight : public LightBase {
|
||||
public:
|
||||
OmnidirectionalLight2D(const Vector3& position, const Color4& ambient, const Color4& diffuse, const Color4& specular);
|
||||
|
||||
PointLight(const Vector3& position, const Color4& ambient, const Color4& diffuse, const Color4& specular, float constant_attenuation = 1, float linear_attenuation = 0, float quadratic_attenuation = 0);
|
||||
};
|
||||
|
||||
/// Lights which only effect things in a given cone.
|
||||
class JGL::SpotLight : public LightBase {
|
||||
protected:
|
||||
Matrix3x3 orientation;
|
||||
float exponent;
|
||||
float cut;
|
||||
public:
|
||||
/// Create a spotlight in 3D space.
|
||||
/// @param position The position of the light in 3D space.
|
||||
/// @param ro_mat Orientation of the light in 3D space.
|
||||
/// @param cone_size_degrees The size of the cone.
|
||||
/// @param exponent How focused the beam should be, Higher is more focused, Lower is less.
|
||||
/// @param ambient How much this light should effect the ambient light of the scene.
|
||||
/// @param diffuse
|
||||
/// @param specular How much this light should effect specular highlights of objects being influenced by it.
|
||||
SpotLight(const Vector3& position, const Matrix3x3& ro_mat, float cone_size_degrees, float exponent, const Color4& ambient, const Color4& diffuse, const Color4& specular, float constant_attenuation = 1, float linear_attenuation = 0, float quadratic_attenuation = 0);
|
||||
};
|
18
include/JGL/types/ShadowMap.h
Normal file
18
include/JGL/types/ShadowMap.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <JGL/types/RenderTarget.h>
|
||||
#include <JGL/types/Light.h>
|
||||
|
||||
namespace JGL {
|
||||
class ShadowMap;
|
||||
}
|
||||
|
||||
/// You render your scene with all the static objects from the perspective of each static light to a ShadowMap.
|
||||
/// Then, for shadow casters which move. Or lights that move. You only redraw that object from the perspective of each light.
|
||||
/// Some of the approaches I saw for this were disgusting - Redacted.
|
||||
|
||||
class JGL::ShadowMap {
|
||||
private:
|
||||
RenderTarget shadow_map;
|
||||
private:
|
||||
void Create(const LightBase* Light);
|
||||
};
|
8
main.cpp
8
main.cpp
@@ -124,7 +124,7 @@ public:
|
||||
//Texture::MultiplyByAlphaMask(*image, *image_mask);
|
||||
}
|
||||
|
||||
Vector3 textAngle = {0,0,0};
|
||||
EulerAngleXYZ textAngle = {0,0,0};
|
||||
float fov = 90;
|
||||
float sprite_radians = 0;
|
||||
bool fov_increasing = true;
|
||||
@@ -147,7 +147,7 @@ public:
|
||||
//J3D::ChangeFOV(fov);
|
||||
|
||||
sprite_radians += 0.005;
|
||||
textAngle.y += (1);
|
||||
textAngle.yaw += 1;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
@@ -245,7 +245,7 @@ public:
|
||||
if (isKeyDown(Keys::LeftShift))
|
||||
camera->position.y -= 1.f * elapsed;
|
||||
|
||||
/* This is wrong of course. Just for testing purposes.
|
||||
//This is wrong of course. Just for testing purposes.
|
||||
if (isKeyDown(Keys::W))
|
||||
camera->position.z += 1.f * elapsed;
|
||||
if (isKeyDown(Keys::S))
|
||||
@@ -254,7 +254,7 @@ public:
|
||||
camera->position.x += 1.f * elapsed;
|
||||
if (isKeyDown(Keys::D))
|
||||
camera->position.x -= 1.f * elapsed;
|
||||
*/
|
||||
|
||||
|
||||
auto mouse = GetMouseCoordinates();
|
||||
a.Update(mouse);
|
||||
|
42
src/JGL.cpp
42
src/JGL.cpp
@@ -32,6 +32,9 @@ bool wasBlendEnabled = false;
|
||||
bool wasColorArrayEnabled = false;
|
||||
GLint activeTextureUnit = 0;
|
||||
|
||||
std::array<const JGL::LightBase*, 8> J3D_Empty_Light_Array{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
|
||||
std::array<const JGL::LightBase*, 8> J3D_Required_Lights{};
|
||||
std::vector<const JGL::LightBase*> J3D_Light_Array{};
|
||||
float j3d_far_plane = 0;
|
||||
float j3d_fov = 0;
|
||||
Vector2 wS;
|
||||
@@ -1161,6 +1164,13 @@ namespace JGL {
|
||||
|
||||
#pragma endregion
|
||||
|
||||
// TODO We're going to need two-pass rendering for occlusion queries and for determining what lights to use for what object.
|
||||
// We'll do a pre-render pass where we render a *very* simple scene where each object is replaced by an AABB.
|
||||
// Then, For each object we get a result on whether it was actually visible or not.
|
||||
// For lights, We can get the closest point on the AABB to each light and see how much it would influence that point.
|
||||
// Finally, we decide what lights to have enabled for the objects which were not occluded based on influence and distance from the camera.
|
||||
// For objects that are *extremely* big, Like base level geometry, I'll have to use its collision map for this to look right. - Redacted.
|
||||
|
||||
#pragma region J3D
|
||||
std::array<GLfloat, 16> OpenGLPerspectiveProjectionRH(float fovY, float aspect, float z_near, float z_far) {
|
||||
std::array<GLfloat, 16> result{};
|
||||
@@ -1181,6 +1191,17 @@ namespace JGL {
|
||||
j3d_far_plane = far_plane;
|
||||
}
|
||||
|
||||
void J3D::RequiredLight(const JGL::LightBase* light) {
|
||||
for (auto* i : J3D_Required_Lights)
|
||||
if (i == nullptr)
|
||||
i = light;
|
||||
}
|
||||
|
||||
void J3D::LightArray(const JGL::LightBase** lights, const size_t& light_count) {
|
||||
for (size_t i = 0; i < light_count; i++)
|
||||
J3D_Light_Array.push_back(lights[i]);
|
||||
}
|
||||
|
||||
void J3D::Begin() {
|
||||
|
||||
auto aspect = (float) wS.x / (float) wS.y;
|
||||
@@ -1224,6 +1245,12 @@ namespace JGL {
|
||||
else
|
||||
wasBlendEnabled = true;
|
||||
|
||||
// Reset the lights.
|
||||
J3D_Required_Lights = J3D_Empty_Light_Array;
|
||||
J3D_Light_Array = {};
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
if (!inJ2D)
|
||||
inJ3D = true;
|
||||
else
|
||||
@@ -1249,6 +1276,21 @@ namespace JGL {
|
||||
if (wasTextureCoordArrayEnabled)
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
if (glIsEnabled(GL_LIGHTING)) {
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_LIGHT0);
|
||||
glDisable(GL_LIGHT1);
|
||||
glDisable(GL_LIGHT2);
|
||||
glDisable(GL_LIGHT3);
|
||||
glDisable(GL_LIGHT4);
|
||||
glDisable(GL_LIGHT5);
|
||||
glDisable(GL_LIGHT6);
|
||||
glDisable(GL_LIGHT7);
|
||||
}
|
||||
|
||||
J3D_Required_Lights = J3D_Empty_Light_Array;
|
||||
J3D_Light_Array = {};
|
||||
|
||||
//Put the draw color back how it was before.
|
||||
glColor4fv(oldColor);
|
||||
inJ3D = false;
|
||||
|
@@ -162,7 +162,7 @@ namespace JGL {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void J3D::DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font, const EulerAngle& angle, bool draw_back_face) {
|
||||
void J3D::DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font, const EulerAngleXYZ& angle, bool draw_back_face) {
|
||||
// TODO: Determine the proper scale factor mathematically
|
||||
// This number was arrived at holistically.
|
||||
scale = scale * 0.002f;
|
||||
|
@@ -1,19 +1,26 @@
|
||||
#include <JGL/types/Light.h>
|
||||
#include <glad/glad.h>
|
||||
|
||||
JGL::Light::Light(const Vector3& position, const Color4& ambient, const Color4& diffuse, const Color4& specular) {
|
||||
JGL::PointLight::PointLight(const Vector3& position, const Color4& ambient, const Color4& diffuse, const Color4& specular, float constant_attenuation, float linear_attenuation, float quadratic_attenuation) {
|
||||
this->position = Vector4(position, 1.0f);
|
||||
this->ambient = ambient;
|
||||
this->diffuse = diffuse;
|
||||
this->specular = specular;
|
||||
this->constant_attenuation = constant_attenuation;
|
||||
this->linear_attenuation = linear_attenuation;
|
||||
this->quadratic_attenuation = quadratic_attenuation;
|
||||
}
|
||||
|
||||
Vector3 JGL::Light::GetNormalizedSceenSpaceCoordinates() const {
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
|
||||
float normalized_x = 2.0f * (position.x - viewport[0]) / viewport[2] - 1.0f;
|
||||
float normalized_y = 2.0f * (position.y - viewport[1]) / viewport[3] - 1.0f;
|
||||
|
||||
return {normalized_x, normalized_y, position.z};
|
||||
JGL::SpotLight::SpotLight(const Vector3& position, const Matrix3x3& ro_mat, float cone_size_degrees, float exponent, const Color4& ambient, const Color4& diffuse, const Color4& specular,
|
||||
float constant_attenuation, float linear_attenuation, float quadratic_attenuation) {
|
||||
this->position = Vector4(position, 1);
|
||||
//TODO RotationMatrix to "Normalized direction vector."
|
||||
orientation = ro_mat;
|
||||
this->cut = cone_size_degrees;
|
||||
this->exponent = exponent;
|
||||
this->ambient = ambient;
|
||||
this->diffuse = diffuse;
|
||||
this->specular = specular;
|
||||
this->constant_attenuation = constant_attenuation;
|
||||
this->linear_attenuation = linear_attenuation;
|
||||
this->quadratic_attenuation = quadratic_attenuation;
|
||||
}
|
||||
|
Reference in New Issue
Block a user