spooky light
This commit is contained in:
@@ -7,7 +7,7 @@ namespace shader {
|
||||
|
||||
class WorldShader : public ShaderProgram {
|
||||
private:
|
||||
unsigned int m_LocationProjection = 0, m_LocationView = 0;
|
||||
unsigned int m_LocationProjection = 0, m_LocationView = 0, m_LocationLight = 0;
|
||||
|
||||
protected:
|
||||
void GetAllUniformLocation() override;
|
||||
@@ -19,6 +19,7 @@ class WorldShader : public ShaderProgram {
|
||||
|
||||
void SetProjectionMatrix(const Mat4f& proj) const;
|
||||
void SetViewMatrix(const Mat4f& view) const;
|
||||
void SetLightPosition(const Vec3f& lightPos) const;
|
||||
};
|
||||
|
||||
} // namespace shader
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "client/render/MainRenderer.h"
|
||||
|
||||
#include "blitz/misc/Format.h"
|
||||
#include "blitz/misc/Log.h"
|
||||
#include "blitz/misc/Maths.h"
|
||||
#include "blitz/misc/Time.h"
|
||||
@@ -84,6 +85,12 @@ void MainRenderer::RenderPlayers() {
|
||||
}
|
||||
|
||||
void MainRenderer::RenderWorld() {
|
||||
// temporary code
|
||||
if (!m_Client->GetGame()->GetPlayers().empty()) {
|
||||
m_WorldShader->Start();
|
||||
m_WorldShader->SetLightPosition(m_Camera.GetPosition());
|
||||
}
|
||||
|
||||
for (auto& Vao : m_WorldModel.mVaos) {
|
||||
RenderWorld(*Vao.get());
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ layout(location = 2) in vec3 normal;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
|
||||
uniform vec3 lightPosition = vec3(0, 15, 0);
|
||||
uniform vec3 lightPosition;
|
||||
|
||||
out vec3 toLightVector;
|
||||
out vec3 toCameraVector;
|
||||
@@ -127,6 +127,11 @@ out vec4 out_color;
|
||||
|
||||
void main(void){
|
||||
|
||||
float lightDistance = length(toLightVector);
|
||||
|
||||
const vec3 attenuation = vec3(0.4, 0.1, 0.01);
|
||||
float attenuationFactor = attenuation.x + attenuation.y * lightDistance + attenuation.z * lightDistance * lightDistance;
|
||||
|
||||
vec3 unitNormal = normalize(surfaceNormal);
|
||||
vec3 unitLightVector = normalize(toLightVector);
|
||||
vec3 unitCamVector = normalize(toCameraVector);
|
||||
@@ -139,7 +144,7 @@ void main(void){
|
||||
float specularFactor = max(0.0, dot(reflectedLightDirection, unitCamVector));
|
||||
float specular = pow(specularFactor, shineDamper) * reflectivity;
|
||||
|
||||
float brightness = diffuse + specular;
|
||||
float brightness = (diffuse + specular) / attenuationFactor;
|
||||
|
||||
out_color = vec4(1.0, 1.0, 1.0, 1.0) * brightness * texture(textureSampler, pass_textureCoords);
|
||||
|
||||
@@ -155,6 +160,7 @@ void WorldShader::LoadShader() {
|
||||
|
||||
void WorldShader::GetAllUniformLocation() {
|
||||
m_LocationProjection = static_cast<unsigned int>(GetUniformLocation("projectionMatrix"));
|
||||
m_LocationLight = static_cast<unsigned int>(GetUniformLocation("lightPosition"));
|
||||
m_LocationView = static_cast<unsigned int>(GetUniformLocation("viewMatrix"));
|
||||
}
|
||||
|
||||
@@ -166,5 +172,9 @@ void WorldShader::SetViewMatrix(const Mat4f& view) const {
|
||||
LoadMat4(m_LocationView, view);
|
||||
}
|
||||
|
||||
void WorldShader::SetLightPosition(const Vec3f& lightPos) const {
|
||||
LoadVector(m_LocationLight, lightPos);
|
||||
}
|
||||
|
||||
} // namespace shader
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user