mirror of
https://github.com/Ed94/DuctTaped_GL.git
synced 2024-12-22 15:04:47 -08:00
Had to recure the shader glue. Old shader glue isn't good. Its still bad need to recure the glue for phong again...
This commit is contained in:
parent
ea17618c98
commit
599f444661
32
AGoodCube.obj
Normal file
32
AGoodCube.obj
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
mtllib cube.mtl
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# cube Mesh
|
||||||
|
#
|
||||||
|
g cube Mesh
|
||||||
|
|
||||||
|
v 0.022541 0.000000 0.000000
|
||||||
|
v 1.022541 1.000000 0.000000
|
||||||
|
v 1.022541 0.000000 0.000000
|
||||||
|
v 0.022541 1.000000 0.000000
|
||||||
|
v 0.022541 1.000000 1.000000
|
||||||
|
v 0.022541 0.000000 1.000000
|
||||||
|
v 1.022541 1.000000 1.000000
|
||||||
|
v 1.022541 0.000000 1.000000
|
||||||
|
f 1 2 3
|
||||||
|
f 1 4 2
|
||||||
|
f 1 5 4
|
||||||
|
f 1 6 5
|
||||||
|
f 4 7 2
|
||||||
|
f 4 5 7
|
||||||
|
f 3 2 7
|
||||||
|
f 3 7 8
|
||||||
|
f 1 3 8
|
||||||
|
f 1 8 6
|
||||||
|
f 6 8 7
|
||||||
|
f 6 7 5
|
106
DGL_Model.hpp
106
DGL_Model.hpp
@ -24,6 +24,8 @@ namespace DGL
|
|||||||
using VertexList = std ::vector < Vector3>;
|
using VertexList = std ::vector < Vector3>;
|
||||||
using UVList = std ::vector < Vector2>;
|
using UVList = std ::vector < Vector2>;
|
||||||
using VecInt = Generic::Vector3< gUInt >;
|
using VecInt = Generic::Vector3< gUInt >;
|
||||||
|
using VIndexList = std ::vector < gInt >;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -65,28 +67,10 @@ namespace DGL
|
|||||||
|
|
||||||
struct Face
|
struct Face
|
||||||
{
|
{
|
||||||
VecInt Vertexes, UVs, Normals;
|
VecInt Vertexes, Normals;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FaceVertexIndex
|
using FaceList = std::vector<Face>;
|
||||||
{
|
|
||||||
gUInt Vertex, UV, Normal;
|
|
||||||
|
|
||||||
FaceVertexIndex() : Vertex(0), UV(0), Normal(0) {};
|
|
||||||
|
|
||||||
FaceVertexIndex(gUInt _vertex, gUInt _uv, gUInt _norm) : Vertex(_vertex), UV(_uv), Normal(_norm) {};
|
|
||||||
};
|
|
||||||
|
|
||||||
using VertexIndexList = Generic::Vector3<FaceVertexIndex>;
|
|
||||||
|
|
||||||
|
|
||||||
// A face primitive is a triangle.
|
|
||||||
//struct Face
|
|
||||||
//{
|
|
||||||
// //FaceVertexIndex Indicies[3];
|
|
||||||
|
|
||||||
// gInt Vertex[3], Normal[3], UV[3];
|
|
||||||
//};
|
|
||||||
|
|
||||||
struct FaceGenerator
|
struct FaceGenerator
|
||||||
{
|
{
|
||||||
@ -119,42 +103,22 @@ namespace DGL
|
|||||||
|
|
||||||
if (uvIndexes.size() > 0)
|
if (uvIndexes.size() > 0)
|
||||||
{
|
{
|
||||||
generated.UVs[index] = uvIndexes[index];
|
//generated.UVs[index] = uvIndexes[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (normals.size() > 0)
|
if (normals.size() > 0)
|
||||||
{
|
{
|
||||||
generated.Normals[index] = normals[index];
|
generated.Normals[index] = normals[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*generated.Vertex[index] = vertIndexes[index];
|
|
||||||
|
|
||||||
if (uvIndexes.size() > 0)
|
|
||||||
{
|
|
||||||
generated.UV[index] = uvIndexes[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (normals.size() > 0)
|
|
||||||
{
|
|
||||||
generated.Normal[index] = normals[index];
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return generated;
|
return generated;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Model
|
struct Model
|
||||||
{
|
{
|
||||||
using FaceList = std::vector< Face>;
|
|
||||||
using VIndexList = std::vector< gInt>;
|
|
||||||
|
|
||||||
struct VN
|
struct VN
|
||||||
{
|
{
|
||||||
Vector3 Vertex, Normal;
|
Vector3 Vertex, Normal;
|
||||||
@ -328,6 +292,49 @@ namespace DGL
|
|||||||
fileBuffer.close();
|
fileBuffer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
sfn RoundOff(Type _value, gInt _numDigitsToKeep) -> Type
|
||||||
|
{
|
||||||
|
uInt64 Rounder = pow(10, _numDigitsToKeep);
|
||||||
|
|
||||||
|
return round(_value * Rounder) / Rounder;
|
||||||
|
}
|
||||||
|
|
||||||
|
sfn GenerateNormals()
|
||||||
|
{
|
||||||
|
for (int index = 0; index < Faces.size(); index++)
|
||||||
|
{
|
||||||
|
int vertexIndex1 = Faces[index].Vertexes[0],
|
||||||
|
vertexIndex2 = Faces[index].Vertexes[1],
|
||||||
|
vertexIndex3 = Faces[index].Vertexes[2];
|
||||||
|
|
||||||
|
Vector3 edge1 = Verticies[vertexIndex2] - Verticies[vertexIndex1],
|
||||||
|
edge2 = Verticies[vertexIndex3] - Verticies[vertexIndex2],
|
||||||
|
|
||||||
|
normal = GetDirection(GetCrossNormal(edge1, edge2));
|
||||||
|
|
||||||
|
|
||||||
|
normal[0] = RoundOff(normal[0], 7);
|
||||||
|
normal[1] = RoundOff(normal[1], 7);
|
||||||
|
normal[2] = RoundOff(normal[2], 7);
|
||||||
|
|
||||||
|
bool normalExists = false;
|
||||||
|
|
||||||
|
for (int normIndex = 0; normIndex < VertNormals.size(); normIndex++)
|
||||||
|
{
|
||||||
|
if (normal == VertNormals[normIndex])
|
||||||
|
{
|
||||||
|
normalExists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!normalExists)
|
||||||
|
{
|
||||||
|
VertNormals.push_back(normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Hardcoded to only do the verticies and normals for now...
|
// Hardcoded to only do the verticies and normals for now...
|
||||||
sfn Buffer()
|
sfn Buffer()
|
||||||
{
|
{
|
||||||
@ -336,27 +343,34 @@ namespace DGL
|
|||||||
GenerateBuffers (Address(NBO), 1);
|
GenerateBuffers (Address(NBO), 1);
|
||||||
GenerateBuffers (Address(EBO), 1);
|
GenerateBuffers (Address(EBO), 1);
|
||||||
|
|
||||||
|
|
||||||
|
if (VertNormals.size() == 0)
|
||||||
|
{
|
||||||
|
GenerateNormals();
|
||||||
|
}
|
||||||
|
|
||||||
BindVertexArray(VAO);
|
BindVertexArray(VAO);
|
||||||
|
|
||||||
BindBuffer(EBufferTarget::VertexAttributes, VBO);
|
BindBuffer(EBufferTarget::VertexAttributes, VBO);
|
||||||
|
|
||||||
BufferData(Address(Verticies[0]), Verticies.size() * sizeof(Vector3), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
|
BufferData(Address(Verticies[0]), Verticies.size() * sizeof(Vector3), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
|
||||||
|
|
||||||
EnableVertexAttributeArray(0);
|
|
||||||
|
|
||||||
FormatVertexAttributes<Vector3>(0, EDataType::Float, ZeroOffset(), 3, EBool::False);
|
FormatVertexAttributes<Vector3>(0, EDataType::Float, ZeroOffset(), 3, EBool::False);
|
||||||
|
|
||||||
|
EnableVertexAttributeArray(0);
|
||||||
|
|
||||||
if (VertNormals.size() != 0)
|
if (VertNormals.size() != 0)
|
||||||
{
|
{
|
||||||
BindBuffer(EBufferTarget::VertexAttributes, NBO);
|
BindBuffer(EBufferTarget::VertexAttributes, NBO);
|
||||||
|
|
||||||
BufferData(Address(VertNormals[0]), VertNormals.size() * sizeof(Vector3), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
|
BufferData(Address(VertNormals[0]), VertNormals.size() * sizeof(Vector3), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
|
||||||
|
|
||||||
EnableVertexAttributeArray(1);
|
|
||||||
|
|
||||||
FormatVertexAttributes<Vector3>(1, EDataType::Float, ZeroOffset(), 3, EBool::False);
|
FormatVertexAttributes<Vector3>(1, EDataType::Float, ZeroOffset(), 3, EBool::False);
|
||||||
|
|
||||||
|
EnableVertexAttributeArray(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BindBuffer(EBufferTarget::VertexIndices, EBO);
|
BindBuffer(EBufferTarget::VertexIndices, EBO);
|
||||||
|
|
||||||
BufferData(Address(Faces[0]), Faces.size() * sizeof(Face), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
|
BufferData(Address(Faces[0]), Faces.size() * sizeof(Face), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
|
||||||
|
@ -460,7 +460,7 @@ namespace DGL
|
|||||||
ViewPositionID = GetUniformVariable(ShaderID, "ViewPosition" );
|
ViewPositionID = GetUniformVariable(ShaderID, "ViewPosition" );
|
||||||
}
|
}
|
||||||
|
|
||||||
sfn SetupRender
|
sfn Use
|
||||||
(
|
(
|
||||||
Ref(CoordSpace) _projection ,
|
Ref(CoordSpace) _projection ,
|
||||||
Ref(CoordSpace) _viewport ,
|
Ref(CoordSpace) _viewport ,
|
||||||
@ -471,7 +471,7 @@ namespace DGL
|
|||||||
Ref(Vector3 ) _viewPosition
|
Ref(Vector3 ) _viewPosition
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CoordSpace inverseTransform = Inverse(_objectTransform);
|
CoordSpace inverseTransform = Inverse(_viewport * _objectTransform);
|
||||||
|
|
||||||
UseProgramShader(ShaderID);
|
UseProgramShader(ShaderID);
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ namespace DGL
|
|||||||
LookAtPosition,
|
LookAtPosition,
|
||||||
UpDirection,
|
UpDirection,
|
||||||
FrontDirection
|
FrontDirection
|
||||||
);
|
);
|
||||||
|
|
||||||
CoordSpace WorldSpace(Matrix4x4(1.0f));
|
CoordSpace WorldSpace(Matrix4x4(1.0f));
|
||||||
|
|
||||||
|
@ -99,13 +99,7 @@ namespace Execution
|
|||||||
|
|
||||||
ActionQueue ActionsToComplete; // Actions queue to run during the physics process of the cycle.
|
ActionQueue ActionsToComplete; // Actions queue to run during the physics process of the cycle.
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
sfn RoundOff(Type _value, gInt _numDigitsToKeep) -> Type
|
|
||||||
{
|
|
||||||
uInt64 Rounder = pow(10, _numDigitsToKeep);
|
|
||||||
|
|
||||||
return round(_value * Rounder) / Rounder;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Functionality
|
// Functionality
|
||||||
|
@ -3,45 +3,50 @@
|
|||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
|
||||||
in vec3 FragPosition;
|
in vec3 FragPosition ;
|
||||||
in vec3 Normal ;
|
in vec3 Normal ;
|
||||||
|
in vec3 LightViewPosition;
|
||||||
|
in vec3 LightRawPos;
|
||||||
|
|
||||||
|
|
||||||
uniform vec3 ObjectColor;
|
uniform vec3 ObjectColor;
|
||||||
|
uniform vec3 LightColor ;
|
||||||
|
|
||||||
uniform vec3 LightPosition;
|
|
||||||
uniform vec3 LightColor ;
|
|
||||||
|
|
||||||
uniform vec3 ViewPosition;
|
uniform vec3 ViewPosition;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float AmbientStrength = 0.1;
|
// Ambient
|
||||||
float SpecularStrength = 0.5;
|
|
||||||
|
|
||||||
vec3 ambient = AmbientStrength * LightColor ;
|
float ambientStrength = 0.1;
|
||||||
|
|
||||||
vec3 Direction = normalize(Normal );
|
vec3 ambient = ambientStrength * LightColor ;
|
||||||
vec3 LightDirection = normalize(LightPosition - FragPosition);
|
|
||||||
|
|
||||||
float DiffuseStrength = max(dot(Normal, LightDirection), 0.0);
|
// Diffuse
|
||||||
|
|
||||||
vec3 diffuse = DiffuseStrength * LightColor ;
|
vec3 direction = normalize(Normal );
|
||||||
|
vec3 lightDirection = normalize(LightViewPosition - FragPosition);
|
||||||
|
|
||||||
vec3 ViewDirection = normalize(ViewPosition - FragPosition);
|
float diffuseStrength = max(dot(direction, lightDirection), 0.0);
|
||||||
|
vec3 diffuse = diffuseStrength * LightColor ;
|
||||||
vec3 ReflectionDirection = reflect(-LightDirection, Normal);
|
|
||||||
|
|
||||||
float Spec = pow(max(dot(ViewDirection, ReflectionDirection), 0.0), 32);
|
|
||||||
|
|
||||||
vec3 specular = SpecularStrength * Spec * LightColor;
|
// Specular
|
||||||
|
|
||||||
vec3 result = (ambient + diffuse + specular) * ObjectColor;
|
float specularStrength = 0.5;
|
||||||
|
|
||||||
|
vec3 viewDirection = normalize(ViewPosition - FragPosition);
|
||||||
|
// vec3 ViewDirection = normalize(-FragPosition);
|
||||||
|
|
||||||
|
vec3 reflectionDirection = reflect(-lightDirection, direction);
|
||||||
|
|
||||||
|
float spec = pow(max(dot(viewDirection, reflectionDirection), 0.0), 32);
|
||||||
|
|
||||||
|
vec3 specular = specularStrength * spec * LightColor;
|
||||||
|
|
||||||
|
// Combining
|
||||||
|
|
||||||
|
vec3 result = (ambient + diffuse) * ObjectColor;
|
||||||
|
|
||||||
FragColor = vec4(result, 1.0);
|
FragColor = vec4(result, 1.0);
|
||||||
|
|
||||||
}
|
}
|
@ -3,23 +3,30 @@
|
|||||||
layout (location = 0) in vec3 VertPosition;
|
layout (location = 0) in vec3 VertPosition;
|
||||||
layout (location = 1) in vec3 VertNormal ;
|
layout (location = 1) in vec3 VertNormal ;
|
||||||
|
|
||||||
out vec3 FragPosition;
|
out vec3 FragPosition ;
|
||||||
out vec3 Normal ;
|
out vec3 Normal ;
|
||||||
|
out vec3 LightViewPosition;
|
||||||
uniform mat4 ModelSpace ;
|
out vec3 LightRawPos;
|
||||||
uniform mat4 Viewport ;
|
|
||||||
uniform mat4 Projection ;
|
|
||||||
|
|
||||||
uniform mat4 InverseModelSpace;
|
uniform mat4 InverseModelSpace;
|
||||||
|
|
||||||
|
uniform mat4 ModelSpace;
|
||||||
|
uniform mat4 Viewport ;
|
||||||
|
uniform mat4 Projection;
|
||||||
|
|
||||||
|
uniform vec3 LightPosition;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragPosition = vec3(ModelSpace * vec4(VertPosition, 1.0));
|
gl_Position = Projection * Viewport * ModelSpace * vec4(VertPosition, 1.0);
|
||||||
|
|
||||||
|
FragPosition = vec3(Viewport * ModelSpace * vec4(VertPosition, 1.0));
|
||||||
|
|
||||||
Normal = mat3(transpose(InverseModelSpace)) * VertNormal;
|
Normal = mat3(transpose(InverseModelSpace)) * VertNormal;
|
||||||
// Normal = VertNormal;
|
|
||||||
|
|
||||||
gl_Position = Projection * Viewport * ModelSpace * vec4(FragPosition, 1.0);
|
LightViewPosition = vec3(Viewport * vec4(LightPosition, 1.0));
|
||||||
|
|
||||||
|
LightRawPos = LightPosition;
|
||||||
}
|
}
|
26
Testing.hpp
26
Testing.hpp
@ -336,23 +336,9 @@ sfn RAW_MakeCube()
|
|||||||
DGL::BufferData<CubeElements>(Address(DefaultCubeElements), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
|
DGL::BufferData<CubeElements>(Address(DefaultCubeElements), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DGL::FormatVertexAttributes<Vertex3>(0, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
|
DGL::FormatVertexAttributes<Vertex3>(0, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
|
||||||
|
|
||||||
DGL::EnableVertexAttributeArray(0);
|
DGL::EnableVertexAttributeArray(0);
|
||||||
|
|
||||||
//DGL::FormatVertexAttributes<VertPhong>(1, EDataType::Float, Offset(Vertex3::ValueCount()), Vertex3::ValueCount(), EBool::False);
|
|
||||||
|
|
||||||
//DGL::EnableVertexAttributeArray(1);
|
|
||||||
|
|
||||||
/*glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
|
||||||
glEnableVertexAttribArray(0);*/
|
|
||||||
|
|
||||||
/*glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(3 * sizeof(float)));
|
|
||||||
glEnableVertexAttribArray(1);*/
|
|
||||||
|
|
||||||
|
|
||||||
//DGL::BindBuffer(EBufferTarget::VertexAttributes, 0); // Dunno. Prob unbinding...
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sfn RAW_RenderCube()
|
sfn RAW_RenderCube()
|
||||||
@ -407,9 +393,9 @@ sfn RAW_LightRotate(gFloat _delta)
|
|||||||
|
|
||||||
if (test)
|
if (test)
|
||||||
{
|
{
|
||||||
LightPosition.x += 0.001f + _delta;
|
LightPosition.x += 0.021f + _delta;
|
||||||
|
|
||||||
if (LightPosition.x > 4)
|
if (LightPosition.x > 10)
|
||||||
{
|
{
|
||||||
test = false;
|
test = false;
|
||||||
}
|
}
|
||||||
@ -419,9 +405,9 @@ sfn RAW_LightRotate(gFloat _delta)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LightPosition.x -= 0.001f + _delta;
|
LightPosition.x -= 0.021f + _delta;
|
||||||
|
|
||||||
if (LightPosition.x < -4)
|
if (LightPosition.x < -10)
|
||||||
{
|
{
|
||||||
test = true;
|
test = true;
|
||||||
}
|
}
|
||||||
@ -495,7 +481,7 @@ sfn RAW_RenderLitCube(CoordSpace _projection, CoordSpace _viewport)
|
|||||||
|
|
||||||
namespace ProperCube
|
namespace ProperCube
|
||||||
{
|
{
|
||||||
Model model("Cube.obj");
|
Model model("torus.obj");
|
||||||
|
|
||||||
Vector3 position = Vector3(0.0f);
|
Vector3 position = Vector3(0.0f);
|
||||||
|
|
||||||
@ -514,7 +500,7 @@ namespace ProperCube
|
|||||||
|
|
||||||
Vector3 lightColor = LightColor.Vector();
|
Vector3 lightColor = LightColor.Vector();
|
||||||
|
|
||||||
DGL::PhongShader::SetupRender
|
DGL::PhongShader::Use
|
||||||
(
|
(
|
||||||
_projection ,
|
_projection ,
|
||||||
_viewport ,
|
_viewport ,
|
||||||
|
37502
bunny.nf25k.obj
Normal file
37502
bunny.nf25k.obj
Normal file
File diff suppressed because it is too large
Load Diff
32
cubeNoNormals.obj
Normal file
32
cubeNoNormals.obj
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
mtllib cube.mtl
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# cube Mesh
|
||||||
|
#
|
||||||
|
g cube Mesh
|
||||||
|
|
||||||
|
v 0.022541 0.000000 0.000000
|
||||||
|
v 1.022541 1.000000 0.000000
|
||||||
|
v 1.022541 0.000000 0.000000
|
||||||
|
v 0.022541 1.000000 0.000000
|
||||||
|
v 0.022541 1.000000 1.000000
|
||||||
|
v 0.022541 0.000000 1.000000
|
||||||
|
v 1.022541 1.000000 1.000000
|
||||||
|
v 1.022541 0.000000 1.000000
|
||||||
|
f 1 2 3
|
||||||
|
f 1 4 2
|
||||||
|
f 1 5 4
|
||||||
|
f 1 6 5
|
||||||
|
f 4 7 2
|
||||||
|
f 4 5 7
|
||||||
|
f 3 2 7
|
||||||
|
f 3 7 8
|
||||||
|
f 1 3 8
|
||||||
|
f 1 8 6
|
||||||
|
f 6 8 7
|
||||||
|
f 6 7 5
|
30002
gargoyle.obj
Normal file
30002
gargoyle.obj
Normal file
File diff suppressed because it is too large
Load Diff
19896
topology.obj
Normal file
19896
topology.obj
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user