light working
This commit is contained in:
parent
d218d158f1
commit
d49d09a1e5
@ -54,11 +54,12 @@ namespace SE
|
||||
{
|
||||
std::vector<vec3> PositionData;
|
||||
std::vector<vec2> TexCoordData;
|
||||
std::vector<vec3> NormalData;
|
||||
|
||||
std::shared_ptr<VAOHolder> vao;
|
||||
std::shared_ptr<VBOHolder> positionVBO;
|
||||
std::shared_ptr<VBOHolder> texCoordVBO;
|
||||
|
||||
std::shared_ptr<VBOHolder> normalVBO;
|
||||
void RefreshVBO();
|
||||
};
|
||||
|
||||
|
@ -119,6 +119,7 @@ bool TLiteModel::LoadModel(const std::string& s)
|
||||
|
||||
vertexDataStruct.PositionData = res.VertexArr;
|
||||
vertexDataStruct.TexCoordData = res.TexCoordArr;
|
||||
vertexDataStruct.NormalData = res.NormalArr;
|
||||
|
||||
vertexDataStruct.RefreshVBO();
|
||||
/*
|
||||
@ -237,12 +238,17 @@ void TLiteModel::DrawVBO()
|
||||
|
||||
EnableVertexAttribArray("vPosition");
|
||||
EnableVertexAttribArray("vTexCoord");
|
||||
EnableVertexAttribArray("vNormal");
|
||||
|
||||
|
||||
//Renderer->DrawTriangleList(TriangleList);
|
||||
DrawVertexDataStruct(vertexDataStruct);
|
||||
|
||||
DisableVertexAttribArray("vPosition");
|
||||
DisableVertexAttribArray("vNormal");
|
||||
DisableVertexAttribArray("vTexCoord");
|
||||
DisableVertexAttribArray("vPosition");
|
||||
|
||||
|
||||
|
||||
RenderUniform1i(CONST_STRING_NORMALMAPEXISTS_UNIFORM, 1);
|
||||
|
||||
@ -267,6 +273,7 @@ void TLiteModel::RotateModel(const mat3& r)
|
||||
for (cardinal i = 0; i < TriangleCount * 3; i++)
|
||||
{
|
||||
vertexDataStruct.PositionData[i] = r * vertexDataStruct.PositionData[i];
|
||||
vertexDataStruct.NormalData[i] = r * vertexDataStruct.NormalData[i];
|
||||
//TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i];
|
||||
//TriangleList.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB][i];
|
||||
//TriangleList.Data.Vec3CoordArr[CONST_STRING_TANGENT_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_TANGENT_ATTRIB][i];
|
||||
|
@ -66,17 +66,37 @@ namespace SE
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, TexCoordData.size() * 8, &TexCoordData[0], GL_STATIC_DRAW);
|
||||
|
||||
if (NormalData.size() > 0)
|
||||
{
|
||||
if (!normalVBO)
|
||||
{
|
||||
normalVBO = std::make_shared<VBOHolder>();
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, normalVBO->getBuffer());
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, NormalData.size() * 12, &NormalData[0], GL_STATIC_DRAW);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DrawVertexDataStruct(const VertexDataStruct& vertexDataStruct)
|
||||
{
|
||||
static const std::string vTexCoord("vTexCoord");
|
||||
static const std::string vPosition("vPosition");
|
||||
static const std::string vNormal("vNormal");
|
||||
|
||||
//Check if main thread, check if data is not empty...
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexDataStruct.texCoordVBO->getBuffer());
|
||||
VertexAttribPointer2fv(vTexCoord, 0, NULL);
|
||||
|
||||
if (vertexDataStruct.normalVBO)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexDataStruct.normalVBO->getBuffer());
|
||||
VertexAttribPointer3fv(vNormal, 0, NULL);
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexDataStruct.positionVBO->getBuffer());
|
||||
VertexAttribPointer3fv(vPosition, 0, NULL);
|
||||
|
||||
|
@ -73,7 +73,7 @@ void TSimpleLandClass::CreateVBO()
|
||||
|
||||
vertexDataStruct.PositionData.clear();
|
||||
vertexDataStruct.TexCoordData.clear();
|
||||
|
||||
vertexDataStruct.NormalData.clear();
|
||||
for (i = 0; i < Height - 1; i++)
|
||||
{
|
||||
for (j = 0; j < Width - 1; j++)
|
||||
@ -98,6 +98,16 @@ void TSimpleLandClass::CreateVBO()
|
||||
vertexDataStruct.PositionData.push_back(VertexMatrix[k_up].pos);
|
||||
vertexDataStruct.PositionData.push_back(VertexMatrix[k_right].pos);
|
||||
|
||||
|
||||
vertexDataStruct.NormalData.push_back(VertexMatrix[k].norm);
|
||||
vertexDataStruct.NormalData.push_back(VertexMatrix[k_right].norm);
|
||||
vertexDataStruct.NormalData.push_back(VertexMatrix[k_up].norm);
|
||||
|
||||
|
||||
vertexDataStruct.NormalData.push_back(VertexMatrix[k_right_up].norm);
|
||||
vertexDataStruct.NormalData.push_back(VertexMatrix[k_up].norm);
|
||||
vertexDataStruct.NormalData.push_back(VertexMatrix[k_right].norm);
|
||||
|
||||
vertexDataStruct.TexCoordData.push_back({ tx0, ty0 });
|
||||
vertexDataStruct.TexCoordData.push_back({ tx1, ty0 });
|
||||
vertexDataStruct.TexCoordData.push_back({ tx0, ty1 });
|
||||
@ -361,7 +371,7 @@ bool TSimpleLandClass::LoadFromFile(const std::string& filename)
|
||||
|
||||
//Replace old matrices with new
|
||||
|
||||
TriangleMatrix.resize(2*(Width-1)*(Height-1));
|
||||
TriangleMatrix.resize(2*(Width)*(Height));
|
||||
VertexMatrix = tempVertexMatrix;
|
||||
|
||||
UpdateTriangleMatrix();
|
||||
@ -556,12 +566,15 @@ void TSimpleLandClass::DrawVBO()
|
||||
|
||||
EnableVertexAttribArray("vPosition");
|
||||
EnableVertexAttribArray("vTexCoord");
|
||||
EnableVertexAttribArray("vNormal");
|
||||
|
||||
//Renderer->DrawTriangleList(TriangleList);
|
||||
DrawVertexDataStruct(vertexDataStruct);
|
||||
|
||||
DisableVertexAttribArray("vPosition");
|
||||
DisableVertexAttribArray("vTexCoord");
|
||||
DisableVertexAttribArray("vNormal");
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@ -876,6 +889,25 @@ void TSimpleLandClass::RecalcNormalVectors()
|
||||
{
|
||||
int i,j,ifrom,ito,jfrom,jto;
|
||||
vec3 v1,v2;
|
||||
for (i = 1; i < Height-1; i++)
|
||||
{
|
||||
for (j = 1; j < Width-1; j++)
|
||||
{
|
||||
ifrom = i - 1;
|
||||
ito = i + 1;
|
||||
|
||||
jfrom = j - 1;
|
||||
jto = j + 1;
|
||||
|
||||
v1 = Normalize(VertexMatrix[j + ito * Width].pos - VertexMatrix[j + ifrom * Width].pos);
|
||||
|
||||
v2 = Normalize(VertexMatrix[jto + i * Width].pos - VertexMatrix[jfrom + i * Width].pos);
|
||||
|
||||
VertexMatrix[j+i*Width].norm = CrossProduct(v2, v1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
for (i=0;i<Height;i++)
|
||||
for (j=0;j<Width;j++)
|
||||
@ -894,7 +926,12 @@ void TSimpleLandClass::RecalcNormalVectors()
|
||||
VertexMatrix[j+i*Width].tangent = v2;
|
||||
VertexMatrix[j+i*Width].norm = CrossProduct(v2, v1);
|
||||
|
||||
}
|
||||
if (VertexMatrix[j + i * Width].norm.v[1] < fabs(VertexMatrix[j + i * Width].norm.v[2]))
|
||||
{
|
||||
std::cout << "Wait..." << std::endl;
|
||||
}
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user