Start work on lighting
This commit is contained in:
parent
43996eb2e6
commit
8fb29d389a
21
core/Light.cpp
Normal file
21
core/Light.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include "Light.h"
|
||||||
|
|
||||||
|
Name Light::GetType() const {return "Light";}
|
||||||
|
|
||||||
|
Name DirectionalLight::GetType() const {return "DirectionalLight";}
|
||||||
|
|
||||||
|
DirectionalLight::DirectionalLight() {
|
||||||
|
this->direction = Vector3(0.0f);
|
||||||
|
this->color = Vector3(0.0f);
|
||||||
|
this->ambient = 0.0f;
|
||||||
|
this->diffuse = 0.0f;
|
||||||
|
this->specular = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectionalLight::DirectionalLight(Vector3 direction, Vector3 color, cfloat ambient, cfloat diffuse, cfloat specular) {
|
||||||
|
this->direction = direction;
|
||||||
|
this->color = color;
|
||||||
|
this->ambient = ambient;
|
||||||
|
this->diffuse = diffuse;
|
||||||
|
this->specular = specular;
|
||||||
|
}
|
22
core/Light.h
Normal file
22
core/Light.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef LIGHT_H
|
||||||
|
#define LIGHT_H
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
#include "Spatial.h"
|
||||||
|
|
||||||
|
class Light : public Spatial {
|
||||||
|
public:
|
||||||
|
Vector3 color;
|
||||||
|
cfloat ambient, diffuse, specular;
|
||||||
|
virtual Name GetType() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DirectionalLight : public Light {
|
||||||
|
public:
|
||||||
|
Vector3 direction;
|
||||||
|
DirectionalLight();
|
||||||
|
DirectionalLight(Vector3 direction, Vector3 color, cfloat ambient, cfloat diffuse, cfloat specular);
|
||||||
|
virtual Name GetType() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* LIGHT_H */
|
@ -42,4 +42,5 @@ Material::Material() {
|
|||||||
usesColor = false;
|
usesColor = false;
|
||||||
usesTex = false;
|
usesTex = false;
|
||||||
alphaScissor = 0.0f;
|
alphaScissor = 0.0f;
|
||||||
|
unshaded = false;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ struct Material {
|
|||||||
Texture tex;
|
Texture tex;
|
||||||
bool usesTex;
|
bool usesTex;
|
||||||
cfloat alphaScissor;
|
cfloat alphaScissor;
|
||||||
|
bool unshaded;
|
||||||
Material();
|
Material();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,10 +24,12 @@ void SubMesh::SetupSubMesh() {
|
|||||||
// Vertex positions
|
// Vertex positions
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) 0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) 0);
|
||||||
// Vertex UV
|
// Vertex normal
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(3 * sizeof(float)));
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) (3 * sizeof(float)));
|
||||||
// TODO normals
|
// Vertex UV
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) (6 * sizeof(float)));
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
@ -36,11 +38,14 @@ void SubMesh::Draw(Shader *shader) {
|
|||||||
shader->UpdateColor(material.usesColor, material.color);
|
shader->UpdateColor(material.usesColor, material.color);
|
||||||
shader->UpdateTex(material.usesTex, material.tex);
|
shader->UpdateTex(material.usesTex, material.tex);
|
||||||
shader->UpdateAlphaScissor(material.alphaScissor);
|
shader->UpdateAlphaScissor(material.alphaScissor);
|
||||||
|
shader->UpdateUnshaded(material.unshaded);
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glDrawElements(GL_TRIANGLES, indices.size() * 3, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, indices.size() * 3, GL_UNSIGNED_INT, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Name Mesh::GetType() const {return "Mesh";}
|
||||||
|
|
||||||
Mesh::Mesh() {}
|
Mesh::Mesh() {}
|
||||||
|
|
||||||
Mesh::~Mesh() {
|
Mesh::~Mesh() {
|
||||||
@ -94,8 +99,11 @@ SubMesh *Mesh::aiMesh2SubMesh(aiMesh *aimesh){
|
|||||||
SubMesh *sub = new SubMesh();
|
SubMesh *sub = new SubMesh();
|
||||||
for (int i = 0; i < aimesh->mNumVertices; i++) {
|
for (int i = 0; i < aimesh->mNumVertices; i++) {
|
||||||
aiVector3D aiPosition = aimesh->mVertices[i];
|
aiVector3D aiPosition = aimesh->mVertices[i];
|
||||||
|
aiVector3D aiNormal = aimesh->mNormals[i];
|
||||||
aiVector3D aiUV = aimesh->mTextureCoords[0][i]; // TODO get ALL texture coords
|
aiVector3D aiUV = aimesh->mTextureCoords[0][i]; // TODO get ALL texture coords
|
||||||
Vertex vertex(aiPosition.x, aiPosition.y, aiPosition.z, aiUV.x, aiUV.y);
|
Vertex vertex(aiPosition.x, aiPosition.y, aiPosition.z,
|
||||||
|
aiNormal.x, aiNormal.y, aiNormal.z,
|
||||||
|
aiUV.x, aiUV.y);
|
||||||
sub->vertices.push_back(vertex);
|
sub->vertices.push_back(vertex);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < aimesh->mNumFaces; i++) {
|
for (int i = 0; i < aimesh->mNumFaces; i++) {
|
||||||
|
@ -43,6 +43,7 @@ public:
|
|||||||
static Mesh *FromFile(const char *filename);
|
static Mesh *FromFile(const char *filename);
|
||||||
virtual bool IsDrawable() const {return true;}
|
virtual bool IsDrawable() const {return true;}
|
||||||
virtual void Draw(Shader *shader);
|
virtual void Draw(Shader *shader);
|
||||||
|
virtual Name GetType() const;
|
||||||
protected:
|
protected:
|
||||||
SubMeshList submeshes;
|
SubMeshList submeshes;
|
||||||
virtual void SetupMesh();
|
virtual void SetupMesh();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
|
|
||||||
|
Name Node::GetType() const {return "Node";}
|
||||||
|
|
||||||
Node *Node::root = {new Node()};
|
Node *Node::root = {new Node()};
|
||||||
Node *Node::GetRoot() {
|
Node *Node::GetRoot() {
|
||||||
return root;
|
return root;
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
class Node; // Forwards declare
|
class Node; // Forwards declare
|
||||||
class NodeList : public std::vector<Node*> {
|
class NodeList : public std::vector<Node*> {
|
||||||
public:
|
public:
|
||||||
@ -16,6 +18,7 @@ public:
|
|||||||
virtual bool IsDrawable() const;
|
virtual bool IsDrawable() const;
|
||||||
virtual void Draw(){};
|
virtual void Draw(){};
|
||||||
virtual bool IsTransformable() const;
|
virtual bool IsTransformable() const;
|
||||||
|
virtual Name GetType() const;
|
||||||
private:
|
private:
|
||||||
static Node *root;
|
static Node *root;
|
||||||
};
|
};
|
||||||
|
@ -23,9 +23,12 @@ Screen::Screen() {
|
|||||||
// Vertex positions
|
// Vertex positions
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) 0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) 0);
|
||||||
//Vertex UV
|
// Vertex Normals
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) (3 * sizeof(float)));
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) (3 * sizeof(float)));
|
||||||
|
//Vertex UV
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) (6 * sizeof(float)));
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
@ -72,6 +72,18 @@ void Shader::UpdateTex(bool usesTex, Texture tex) {
|
|||||||
void Shader::UpdateAlphaScissor(cfloat alphaScissor) {
|
void Shader::UpdateAlphaScissor(cfloat alphaScissor) {
|
||||||
glUniform1f(glGetUniformLocation(id, "material.alphaScissor"), alphaScissor);
|
glUniform1f(glGetUniformLocation(id, "material.alphaScissor"), alphaScissor);
|
||||||
}
|
}
|
||||||
|
void Shader::UpdateUnshaded(bool unshaded) {
|
||||||
|
glUniform1i(glGetUniformLocation(id, "material.unshaded"), (int) unshaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::UpdateDirectionalLight(DirectionalLight directionalLight) {
|
||||||
|
glUniform3fv(glGetUniformLocation(id, "directionalLight.direction"), 1, glm::value_ptr(directionalLight.direction));
|
||||||
|
glUniform3fv(glGetUniformLocation(id, "directionalLight.color"), 1, glm::value_ptr(directionalLight.color));
|
||||||
|
|
||||||
|
glUniform1f(glGetUniformLocation(id, "directionalLight.ambient"), directionalLight.ambient);
|
||||||
|
glUniform1f(glGetUniformLocation(id, "directionalLight.diffuse"), directionalLight.diffuse);
|
||||||
|
glUniform1f(glGetUniformLocation(id, "directionalLight.specular"), directionalLight.specular);
|
||||||
|
}
|
||||||
|
|
||||||
Name Shader::GetName() const {
|
Name Shader::GetName() const {
|
||||||
return "Unnamed Shader";
|
return "Unnamed Shader";
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
|
#include "Light.h"
|
||||||
|
|
||||||
class Shader {
|
class Shader {
|
||||||
public:
|
public:
|
||||||
@ -20,6 +21,9 @@ public:
|
|||||||
void UpdateTex(bool usesTex);
|
void UpdateTex(bool usesTex);
|
||||||
void UpdateTex(bool usesTex, Texture tex);
|
void UpdateTex(bool usesTex, Texture tex);
|
||||||
void UpdateAlphaScissor(cfloat alphaScissor);
|
void UpdateAlphaScissor(cfloat alphaScissor);
|
||||||
|
void UpdateUnshaded(bool unshaded);
|
||||||
|
|
||||||
|
void UpdateDirectionalLight(DirectionalLight directionalLight);
|
||||||
|
|
||||||
virtual Name GetName() const;
|
virtual Name GetName() const;
|
||||||
};
|
};
|
||||||
|
3
core/Spatial.cpp
Normal file
3
core/Spatial.cpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include "Spatial.h"
|
||||||
|
|
||||||
|
Name Spatial::GetType() const {return "Spatial";}
|
@ -8,6 +8,7 @@ class Spatial : public Node {
|
|||||||
public:
|
public:
|
||||||
Transform transform;
|
Transform transform;
|
||||||
virtual bool IsTransformable() const { return true;}
|
virtual bool IsTransformable() const { return true;}
|
||||||
|
virtual Name GetType() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SPATIAL_H */
|
#endif /* SPATIAL_H */
|
||||||
|
18
core/Util.h
18
core/Util.h
@ -5,10 +5,28 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
#include "Node.h"
|
||||||
|
|
||||||
namespace Util {
|
namespace Util {
|
||||||
void Die(const char *msg);
|
void Die(const char *msg);
|
||||||
void Die(const char * msg, const char * more);
|
void Die(const char * msg, const char * more);
|
||||||
void Die(std::string msg);
|
void Die(std::string msg);
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
T* FindNodeByType(Node *&root, const Name &type) {
|
||||||
|
if (root->GetType() == type) {
|
||||||
|
return dynamic_cast<T*>(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Node *child : root->children) {
|
||||||
|
T* res = FindNodeByType<T>(child, type);
|
||||||
|
if (res) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* UTIL_H */
|
#endif /* UTIL_H */
|
||||||
|
@ -4,6 +4,9 @@ Vertex::Vertex() {
|
|||||||
x = 0.0f;
|
x = 0.0f;
|
||||||
y = 0.0f;
|
y = 0.0f;
|
||||||
z = 0.0f;
|
z = 0.0f;
|
||||||
|
nx = 0.0f;
|
||||||
|
ny = 0.0f;
|
||||||
|
nz = 0.0f;
|
||||||
u = 0.0f;
|
u = 0.0f;
|
||||||
v = 0.0f;
|
v = 0.0f;
|
||||||
}
|
}
|
||||||
@ -12,6 +15,9 @@ Vertex::Vertex(cfloat x, cfloat y, cfloat z) {
|
|||||||
this->x = x;
|
this->x = x;
|
||||||
this->y = y;
|
this->y = y;
|
||||||
this->z = z;
|
this->z = z;
|
||||||
|
this->nz = 0.0f;
|
||||||
|
this->ny = 0.0f;
|
||||||
|
this->nz = 0.0f;
|
||||||
this->u = 0.0f;
|
this->u = 0.0f;
|
||||||
this->v = 0.0f;
|
this->v = 0.0f;
|
||||||
}
|
}
|
||||||
@ -20,6 +26,22 @@ Vertex::Vertex(cfloat x, cfloat y, cfloat z, cfloat u, cfloat v) {
|
|||||||
this->x = x;
|
this->x = x;
|
||||||
this->y = y;
|
this->y = y;
|
||||||
this->z = z;
|
this->z = z;
|
||||||
|
this->nx = 0.0f;
|
||||||
|
this->ny = 0.0f;
|
||||||
|
this->nz = 0.0f;
|
||||||
|
this->u = u;
|
||||||
|
this->v = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex::Vertex(cfloat x, cfloat y, cfloat z,
|
||||||
|
cfloat nx, float ny, cfloat nz,
|
||||||
|
cfloat u, cfloat v) {
|
||||||
|
this->x = x;
|
||||||
|
this->y = y;
|
||||||
|
this->z = z;
|
||||||
|
this->nx = nx;
|
||||||
|
this->ny = ny;
|
||||||
|
this->nz = nz;
|
||||||
this->u = u;
|
this->u = u;
|
||||||
this->v = v;
|
this->v = v;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,11 @@ struct Vertex {
|
|||||||
Vertex();
|
Vertex();
|
||||||
Vertex(cfloat x, cfloat y, cfloat z);
|
Vertex(cfloat x, cfloat y, cfloat z);
|
||||||
Vertex(cfloat x, cfloat y, cfloat z, cfloat u, cfloat v);
|
Vertex(cfloat x, cfloat y, cfloat z, cfloat u, cfloat v);
|
||||||
|
Vertex(cfloat x, cfloat y, cfloat z,
|
||||||
|
cfloat nx, float ny, cfloat nz,
|
||||||
|
cfloat u, cfloat v);
|
||||||
cfloat x, y, z;
|
cfloat x, y, z;
|
||||||
|
cfloat nx, ny, nz;
|
||||||
cfloat u, v;
|
cfloat u, v;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
#include "Util.h"
|
||||||
|
|
||||||
#include "Shaders/FlatShader.h"
|
#include "Shaders/FlatShader.h"
|
||||||
#include "Shaders/ScreenShader.h"
|
#include "Shaders/ScreenShader.h"
|
||||||
|
|
||||||
@ -17,6 +19,7 @@
|
|||||||
#include "Input.h"
|
#include "Input.h"
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
|
#include "Light.h"
|
||||||
#include "Scripting/Lua.h"
|
#include "Scripting/Lua.h"
|
||||||
|
|
||||||
// Thirdparty Includes
|
// Thirdparty Includes
|
||||||
@ -49,7 +52,6 @@ void render(Node *curr, Shader *shader, Matrix model) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
@ -113,6 +115,15 @@ int main() {
|
|||||||
view = glm::translate(view, -camera->transform.position);
|
view = glm::translate(view, -camera->transform.position);
|
||||||
shader->UpdateView(view);
|
shader->UpdateView(view);
|
||||||
|
|
||||||
|
// Find the lights
|
||||||
|
DirectionalLight *dirLight = Util::FindNodeByType<DirectionalLight>(root, "DirectionalLight");
|
||||||
|
if (dirLight) {
|
||||||
|
shader->UpdateDirectionalLight(*dirLight);
|
||||||
|
} else {
|
||||||
|
// No light in scene
|
||||||
|
shader->UpdateDirectionalLight(DirectionalLight());
|
||||||
|
}
|
||||||
|
|
||||||
// Render the scene tree
|
// Render the scene tree
|
||||||
render(root, shader, Matrix(1.0f));
|
render(root, shader, Matrix(1.0f));
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H
|
#define TYPES_H
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
@ -17,12 +17,21 @@ local SPEED = 30
|
|||||||
local RED = couch.Color(1.0, 0.0, 0.0)
|
local RED = couch.Color(1.0, 0.0, 0.0)
|
||||||
local BLUE = couch.Color(0.0, 0.0, 1.0)
|
local BLUE = couch.Color(0.0, 0.0, 1.0)
|
||||||
|
|
||||||
|
local light
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
local material
|
local material
|
||||||
|
|
||||||
camera = couch.Camera()
|
camera = couch.Camera()
|
||||||
camera:MakeCurrent()
|
camera:MakeCurrent()
|
||||||
camera.transform:Translate(0.0, 0.0, 10.0)
|
camera.transform:Translate(0.0, 0.0, 10.0)
|
||||||
|
|
||||||
|
light = couch.DirectionalLight.new()
|
||||||
|
light.direction = couch.Vector3(0.0, 0.0, -1.0)
|
||||||
|
light.color = couch.Vector3(1.0, 1.0, 1.0)
|
||||||
|
light.ambient = 0.4
|
||||||
|
light.diffuse = 1.0
|
||||||
|
couch.Node.GetRoot().children:Append(light)
|
||||||
|
|
||||||
ball = couch.Mesh.FromFile("cube.glb")
|
ball = couch.Mesh.FromFile("cube.glb")
|
||||||
material = couch.Material()
|
material = couch.Material()
|
||||||
@ -101,6 +110,12 @@ function onkey(key, code, action, mod)
|
|||||||
elseif (key == couch.KEY_D or key == couch.KEY_A) and action == couch.ACTION_RELEASE then
|
elseif (key == couch.KEY_D or key == couch.KEY_A) and action == couch.ACTION_RELEASE then
|
||||||
vx = 0.0
|
vx = 0.0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if key == couch.KEY_DOWN and action == couch.ACTION_PRESS then
|
||||||
|
light.ambient = light.ambient - 0.1
|
||||||
|
elseif key == couch.KEY_UP and action == couch.ACTION_PRESS then
|
||||||
|
light.ambient = light.ambient + 0.1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function onmousemotion(_, _, relx, rely)
|
function onmousemotion(_, _, relx, rely)
|
||||||
|
14
roadmap.md
14
roadmap.md
@ -48,7 +48,13 @@ swig files and customizing the interface by hand. I also want to add a whole mes
|
|||||||
so that I don't have to test for keypresses. Lastly, I want to test if a function exists before
|
so that I don't have to test for keypresses. Lastly, I want to test if a function exists before
|
||||||
calling it from the lua file, so stubs aren't necessary to prevent a crash
|
calling it from the lua file, so stubs aren't necessary to prevent a crash
|
||||||
|
|
||||||
- [ ] Combine files
|
- [X] Combine files
|
||||||
- [ ] Better interface
|
- [X] Better interface
|
||||||
- [ ] Constants for keys and the like
|
- [X] Constants for keys and the like
|
||||||
- [ ] No crash on calling non-existant scripting hooks
|
- [X] No crash on calling non-existant scripting hooks
|
||||||
|
|
||||||
|
## Lighting
|
||||||
|
|
||||||
|
I'm a bit happier with the system now, I think it's time I started the lighting.
|
||||||
|
We're going to use a pretty basic Phong lighting system, with
|
||||||
|
Flat and Garourd shaders available (This was all that was available on the PSX!)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
|
#include "Light.h"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%rename("%(strip:[script_])s") "";
|
%rename("%(strip:[script_])s") "";
|
||||||
@ -24,6 +25,7 @@ typedef float cfloat;
|
|||||||
class Vector3 {
|
class Vector3 {
|
||||||
public:
|
public:
|
||||||
Vector3();
|
Vector3();
|
||||||
|
Vector3(cfloat x, cfloat y, cfloat z);
|
||||||
cfloat x, y, z;
|
cfloat x, y, z;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -37,6 +39,13 @@ public:
|
|||||||
}
|
}
|
||||||
%ignore "Vector3";
|
%ignore "Vector3";
|
||||||
|
|
||||||
|
%extend DirectionalLight {
|
||||||
|
static DirectionalLight* script_new() {
|
||||||
|
return new DirectionalLight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
%include "types.h"
|
%include "types.h"
|
||||||
%include "constants.h"
|
%include "constants.h"
|
||||||
%include "Node.h"
|
%include "Node.h"
|
||||||
@ -45,4 +54,5 @@ public:
|
|||||||
%include "Transform.h"
|
%include "Transform.h"
|
||||||
%include "Material.h"
|
%include "Material.h"
|
||||||
%include "Camera.h"
|
%include "Camera.h"
|
||||||
|
%include "Light.h"
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
in vec3 UV;
|
in vec3 UV;
|
||||||
|
in vec3 NORMAL;
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
@ -10,9 +11,19 @@ struct Material {
|
|||||||
sampler2D tex;
|
sampler2D tex;
|
||||||
bool usesTex;
|
bool usesTex;
|
||||||
float alphaScissor;
|
float alphaScissor;
|
||||||
|
bool unshaded;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DirectionalLight {
|
||||||
|
vec3 direction;
|
||||||
|
vec3 color;
|
||||||
|
float ambient;
|
||||||
|
float diffuse;
|
||||||
|
float specular;
|
||||||
};
|
};
|
||||||
|
|
||||||
uniform Material material;
|
uniform Material material;
|
||||||
|
uniform DirectionalLight directionalLight;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
FragColor = vec4(0.0);
|
FragColor = vec4(0.0);
|
||||||
@ -25,4 +36,10 @@ void main() {
|
|||||||
if (FragColor.w < material.alphaScissor) {
|
if (FragColor.w < material.alphaScissor) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!material.unshaded) {
|
||||||
|
vec3 ambient = directionalLight.ambient * directionalLight.color;
|
||||||
|
vec3 diffuse = directionalLight.diffuse * reflect(directionalLight.direction, NORMAL) * directionalLight.color;
|
||||||
|
FragColor *= vec4(ambient, 1.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
layout (location = 0) in vec3 pos;
|
layout (location = 0) in vec3 pos;
|
||||||
layout (location = 1) in vec2 uv;
|
layout (location = 1) in vec3 normal;
|
||||||
|
layout (location = 2) in vec2 uv;
|
||||||
|
|
||||||
uniform mat4 MODEL;
|
uniform mat4 MODEL;
|
||||||
uniform mat4 VIEW;
|
uniform mat4 VIEW;
|
||||||
uniform mat4 PROJECTION;
|
uniform mat4 PROJECTION;
|
||||||
|
|
||||||
out vec3 UV;
|
out vec3 UV;
|
||||||
|
out vec3 NORMAL;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 vertex = PROJECTION * VIEW * MODEL * vec4(pos, 1.0);
|
vec4 vertex = PROJECTION * VIEW * MODEL * vec4(pos, 1.0);
|
||||||
gl_Position = vertex;
|
gl_Position = vertex;
|
||||||
UV = vec3(uv * vertex.z, vertex.z);
|
UV = vec3(uv * vertex.z, vertex.z);
|
||||||
|
NORMAL = normal;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
layout (location = 0) in vec3 pos;
|
layout (location = 0) in vec3 pos;
|
||||||
layout (location = 1) in vec2 uv;
|
layout (location = 1) in vec3 normal;
|
||||||
|
layout (location = 2) in vec2 uv;
|
||||||
|
|
||||||
out vec2 UV;
|
out vec2 UV;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user