Ambient light can now be set; Code cleanup

This commit is contained in:
grayson committed 2021-11-15 14:05:44 -06:00
1 parent 231ac792d7
commit f884847513
14 files changed
+48 -13

No files matched your search

+2
View File
@@ -61,6 +61,7 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -92,6 +93,7 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -22,6 +22,7 @@ uniform Light light[12];
uniform int numberOfLights;
uniform bool isContinued;
uniform float farPlane;
uniform float ambientStrength;
uniform sampler2D gBPos;
uniform sampler2D gBNorm;
@@ -88,7 +89,6 @@ void main() {
float specPower = specTemp.r;
float matSpec = specTemp.g;
float ambientStrength = 0.1f;
vec3 ambient = ambientStrength * matDiff;
if (!isContinued)
color += ambient;
+10
View File
@@ -45,11 +45,21 @@ namespace nf {
SetClassLongPtr(m_window, GCLP_HCURSOR, (LONG_PTR)hCursor);
}
Renderer* Application::getRenderer() const {
if (!m_renderer)
Error("Application not running yet!");
return m_renderer;
}
AudioEngine* Application::getAudioEngine() const {
if(!m_audio)
Error("Application not running yet!");
return m_audio;
}
PhysicsEngine* Application::getPhysicsEngine() const {
if (!m_physics)
Error("Application not running yet!");
return m_physics;
}
+4
View File
@@ -54,6 +54,10 @@ namespace nf {
return camera;
}
void Gamestate::setAmbientLight(float strength) {
app->getRenderer()->setAmbient(strength);
}
void Gamestate::setGravity(const Vec3& gravity) {
app->getPhysicsEngine()->setGravity(gravity * 9.81f);
}
+1 -1
View File
@@ -37,7 +37,7 @@ namespace nf {
bool convex = false, triangle = false;
if (m_type == Entity::Type::STATIC || m_type == Entity::Type::DYNAMIC)
convex = true;
else if (m_type == Entity::Type::ENVIRONMENT)
else if (m_type == Entity::Type::MAP)
triangle = true;
m_model = new Model(model, convex, triangle);
model->alreadyLoaded = true;
+1 -4
View File
@@ -4,9 +4,6 @@
#include "Entity.h"
#include "Model.h"
//Remove this
#include "Input.h"
namespace nf {
class PhysicsErrorCallback : public PxErrorCallback {
virtual void reportError(PxErrorCode::Enum code, const char* message, const char* file, int line) {
@@ -234,7 +231,7 @@ namespace nf {
act->userData = entity;
m_scene->addActor(*act);
}
else if (type == Entity::Type::ENVIRONMENT) {
else if (type == Entity::Type::MAP) {
PxRigidStatic* act = PxCreateStatic(*m_phy, PxTransform(PxIdentity), PxTriangleMeshGeometry(triangleMesh), *mat);
act->userData = entity;
m_scene->addActor(*act);
+6
View File
@@ -290,6 +290,12 @@ namespace nf {
SwapBuffers(m_hdc);
}
void Renderer::setAmbient(float am) {
if (am < 0.0f)
Error("Cannot have a negative ambient light strength!");
m_lightingShader->setUniform("ambientStrength", am);
}
void Renderer::loadBaseAssets() {
m_baseAP.load("base.nfpack");
const char* gBufferVertex = m_baseAP.get("gBufferVertex.shader")->data;
+1
View File
@@ -24,6 +24,7 @@ namespace nf {
void setWindowIcon(HICON hIcon);
void setWindowCursor(HCURSOR hCursor);
Renderer* getRenderer() const;
AudioEngine* getAudioEngine() const;
PhysicsEngine* getPhysicsEngine() const;
void addState(Gamestate* state, const std::string& stateName);
+1 -1
View File
@@ -15,7 +15,7 @@ namespace nf {
enum class Type {
STATIC,
DYNAMIC,
ENVIRONMENT,
MAP,
DETAIL
};
+2
View File
@@ -29,6 +29,8 @@ namespace nf {
virtual void render(Renderer& renderer);
Camera* getCamera();
//Defaults to 0.1f
void setAmbientLight(float stength);
//In units of Earth gravity (9.81 m/s^2)
void setGravity(const Vec3& gravity);
void setGravity(float strength);
+4 -2
View File
@@ -1,6 +1,8 @@
//TODO: Rework this file to only contain functions the frontend will need to access
#pragma once
//TODO: Rework this file to only contain functions the frontend will need to access
//Maybe a implementation define here?
#include <chrono>
#include <unordered_map>
#include <array>
+1
View File
@@ -30,6 +30,7 @@ namespace nf {
void render(Cubemap& in);
void doFrame(Camera* camera, float dT);
void setAmbient(float am);
~Renderer();
private: