Splatmapping now working.

Rendering pipleline now support 3 different types of Material:
Basic: a material with a single color on every property (diffuse, specular, ect).
SingleTextures: a material with a single texture in all or any property. Have a single color on the rest.
SplatMapping: has a SplatMap and 0 to 5 different textures to every property. Properties with o texture uses a single color insted.

All materials with a texture has a UVRepeat, telling how many time to till in U and in V.

modelJobs now uses ShadeID, ModelID and TextureID for the Hash insted of only Texture

MayaExported exports 3 differnt types of material, the same as the piplen now supports.
This commit is contained in:
Teejoon
2016-02-07 13:39:13 +01:00
parent ceab837e27
commit 92ab22e779
20 changed files with 971 additions and 309 deletions
+1
View File
@@ -53,6 +53,7 @@ private:
ShaderProgram* m_ForwardPlusProgram; ShaderProgram* m_ForwardPlusProgram;
ShaderProgram* m_ExplosionEffectProgram; ShaderProgram* m_ExplosionEffectProgram;
ShaderProgram* m_ForwardPlusSplatMapProgram;
}; };
#endif #endif
@@ -15,7 +15,7 @@
struct ExplosionEffectJob : ModelJob struct ExplosionEffectJob : ModelJob
{ {
ExplosionEffectJob(ComponentWrapper explosionEffectComponent, ::Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialGroup matGroup, ComponentWrapper modelComponent, ::World* world, glm::vec4 fillColor, float fillPercentage) ExplosionEffectJob(ComponentWrapper explosionEffectComponent, ::Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matGroup, ComponentWrapper modelComponent, ::World* world, glm::vec4 fillColor, float fillPercentage)
: ModelJob(model, camera, matrix, matGroup, modelComponent, world, fillColor, fillPercentage) : ModelJob(model, camera, matrix, matGroup, modelComponent, world, fillColor, fillPercentage)
{ {
ExplosionOrigin = (glm::vec3)explosionEffectComponent["ExplosionOrigin"]; ExplosionOrigin = (glm::vec3)explosionEffectComponent["ExplosionOrigin"];
+1 -1
View File
@@ -14,7 +14,7 @@ private:
public: public:
~Model(); ~Model();
const std::vector<RawModel::MaterialGroup>& MaterialGroups() const { return m_RawModel->MaterialGroups; } const std::vector<RawModel::MaterialProperties>& MaterialGroups() const { return m_RawModel->m_Materials; }
const glm::mat4& Matrix() const { return m_RawModel->m_Matrix; } const glm::mat4& Matrix() const { return m_RawModel->m_Matrix; }
const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); } const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); }
unsigned int NumberOfVertices() const { return m_RawModel->NumVertices(); } unsigned int NumberOfVertices() const { return m_RawModel->NumVertices(); }
+94 -32
View File
@@ -14,39 +14,98 @@
#include "../Core/World.h" #include "../Core/World.h"
#include "../Core/Transform.h" #include "../Core/Transform.h"
#include "Skeleton.h" #include "Skeleton.h"
#include "ShaderProgram.h"
struct ModelJob : RenderJob struct ModelJob : RenderJob
{ {
ModelJob(Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialGroup matGroup, ComponentWrapper modelComponent, World* world, glm::vec4 fillColor, float fillPercentage) ModelJob(Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matProp, ComponentWrapper modelComponent, World* world, glm::vec4 fillColor, float fillPercentage)
: RenderJob() : RenderJob()
{ {
Model = model; Model = model;
TextureID = (matGroup.Texture) ? matGroup.Texture->ResourceID : 0; ModelID = model->ResourceID;
if (modelComponent["DiffuseTexture"]) { Type = matProp.type;
DiffuseTexture = matGroup.Texture.get(); ::RawModel::MaterialBasic* matGroup = matProp.material;
} else { switch(matProp.type){
DiffuseTexture = nullptr; case ::RawModel::MaterialType::Basic:
} if (Model->isSkined()) {
if (modelComponent["NormalMap"]) { ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusProgram")->ResourceID;
NormalTexture = matGroup.NormalMap.get(); }
} else { else {
NormalTexture = nullptr; //JOHAN TODO: Add Non-skined shader
} }
if (modelComponent["SpecularMap"]) { TextureID = 0;
SpecularTexture = matGroup.SpecularMap.get(); break;
} else { case ::RawModel::MaterialType::SingleTextures:
SpecularTexture = nullptr; {
} if (Model->isSkined()) {
if (modelComponent["GlowMap"]) { ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusProgram")->ResourceID;
IncandescenceTexture = matGroup.IncandescenceMap.get(); }
} else { else {
IncandescenceTexture = nullptr; //JOHAN TODO: Add Non-skined shader
} }
DiffuseColor = matGroup.DiffuseColor; ::RawModel::MaterialSingleTextures* singleTextures = static_cast<::RawModel::MaterialSingleTextures*>(matProp.material);
SpecularColor = matGroup.SpecularColor; TextureID = (singleTextures->ColorMap.Texture) ? singleTextures->ColorMap.Texture->ResourceID : 0;
IncandescenceColor = matGroup.IncandescenceColor; if (modelComponent["DiffuseTexture"]) {
StartIndex = matGroup.StartIndex; DiffuseTexture.push_back(singleTextures->ColorMap.Texture.get());
EndIndex = matGroup.EndIndex; }
if (modelComponent["NormalMap"]) {
NormalTexture.push_back(singleTextures->NormalMap.Texture.get());
}
if (modelComponent["SpecularMap"]) {
SpecularTexture.push_back(singleTextures->SpecularMap.Texture.get());
}
if (modelComponent["GlowMap"]) {
IncandescenceTexture.push_back(singleTextures->IncandescenceMap.Texture.get());
}
}
break;
case ::RawModel::MaterialType::SplatMapping:
{
if (Model->isSkined()) {
ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusSplatMapProgram")->ResourceID;
}
else {
//JOHAN TODO: Add Non-skinned shader
}
::RawModel::MaterialSplatMapping* SplatTextures = static_cast<::RawModel::MaterialSplatMapping*>(matProp.material);
SplatMap = SplatTextures->SplatMap.Texture.get();
TextureID = (SplatTextures->ColorMaps[0].Texture) ? SplatTextures->ColorMaps[0].Texture->ResourceID : 0;
if (modelComponent["DiffuseTexture"]) {
for (auto texture : SplatTextures->ColorMaps) {
DiffuseTexture.push_back(texture.Texture.get());
}
}
if (modelComponent["NormalMap"]) {
for (auto texture : SplatTextures->NormalMaps) {
NormalTexture.push_back(texture.Texture.get());
}
}
if (modelComponent["SpecularMap"]) {
for (auto texture : SplatTextures->SpecularMaps) {
SpecularTexture.push_back(texture.Texture.get());
}
}
if (modelComponent["GlowMap"]) {
for (auto texture : SplatTextures->IncandescenceMaps) {
IncandescenceTexture.push_back(texture.Texture.get());
}
}
}
break;
}
DiffuseColor = matGroup->DiffuseColor;
SpecularColor = matGroup->SpecularColor;
IncandescenceColor = matGroup->IncandescenceColor;
StartIndex = matGroup->StartIndex;
EndIndex = matGroup->EndIndex;
Matrix = matrix; Matrix = matrix;
Color = modelComponent["Color"]; Color = modelComponent["Color"];
Entity = modelComponent.EntityID; Entity = modelComponent.EntityID;
@@ -68,13 +127,16 @@ struct ModelJob : RenderJob
unsigned int TextureID; unsigned int TextureID;
unsigned int ShaderID; unsigned int ShaderID;
unsigned int ModelID;
::RawModel::MaterialType Type;
EntityID Entity; EntityID Entity;
glm::mat4 Matrix; glm::mat4 Matrix;
const Texture* DiffuseTexture; const Texture* SplatMap;
const Texture* NormalTexture; std::vector<const Texture*> DiffuseTexture;
const Texture* SpecularTexture; std::vector<const Texture*> NormalTexture;
const Texture* IncandescenceTexture; std::vector<const Texture*> SpecularTexture;
std::vector<const Texture*> IncandescenceTexture;
float Shininess = 0.f; float Shininess = 0.f;
glm::vec4 Color; glm::vec4 Color;
const ::Model* Model = nullptr; const ::Model* Model = nullptr;
@@ -95,7 +157,7 @@ struct ModelJob : RenderJob
void CalculateHash() override void CalculateHash() override
{ {
Hash = TextureID; Hash = TextureID + ModelID << 10 + ShaderID << 20;
} }
}; };
+8 -8
View File
@@ -76,10 +76,10 @@ public:
struct MaterialSingleTextures : public MaterialBasic struct MaterialSingleTextures : public MaterialBasic
{ {
TextureProperties ColorMaps; TextureProperties ColorMap;
TextureProperties NormalMaps; TextureProperties NormalMap;
TextureProperties SpecularMaps; TextureProperties SpecularMap;
TextureProperties IncandescenceMaps; TextureProperties IncandescenceMap;
}; };
enum class MaterialType { Basic = 1, SplatMapping, SingleTextures }; enum class MaterialType { Basic = 1, SplatMapping, SingleTextures };
@@ -136,10 +136,10 @@ private:
void ReadMaterialFile(std::string filePath); void ReadMaterialFile(std::string filePath);
void ReadMaterials(std::size_t& offset, char* fileData, const unsigned int& fileByteSize); void ReadMaterials(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadMaterialSingle(std::size_t& offset, char* fileData, const unsigned int& fileByteSize); void ReadMaterialSingle(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadMaterialBasic(MaterialBasic* Material, unsigned int &offset, char* fileData, unsigned int& fileByteSize); void ReadMaterialBasic(MaterialBasic* Material, std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadMaterialSingleTexture(MaterialSingleTextures* Material, unsigned int &offset, char* fileData, unsigned int& fileByteSize); void ReadMaterialSingleTexture(MaterialSingleTextures* Material, std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadMaterialSplatMapping(MaterialSplatMapping* Material, unsigned int &offset, char* fileData, unsigned int& fileByteSize); void ReadMaterialSplatMapping(MaterialSplatMapping* Material, std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadMaterialTextureProperties(TextureProperties& texture, unsigned int &offset, char* fileData, unsigned int& fileByteSize); void ReadMaterialTextureProperties(TextureProperties& texture, std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadAnimationFile(std::string filePath); void ReadAnimationFile(std::string filePath);
void ReadAnimationBindPoses(std::size_t& offset, char* fileData, const unsigned int& fileByteSize); void ReadAnimationBindPoses(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
-1
View File
@@ -47,7 +47,6 @@ private:
void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs); void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs);
bool isChildOfACamera(EntityWrapper entity); bool isChildOfACamera(EntityWrapper entity);
bool isChildOfCurrentCamera(EntityWrapper entity); bool isChildOfCurrentCamera(EntityWrapper entity);
}; };
#endif #endif
@@ -0,0 +1,245 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec2 ScreenDimensions;
uniform float FillPercentage;
uniform vec4 DiffuseColor;
uniform vec4 FillColor;
uniform vec4 Color;
uniform vec4 AmbientColor;
layout (binding = 0) uniform sampler2D SplatMapTexture;
layout (binding = 1) uniform sampler2D DiffuseTexture1;
layout (binding = 2) uniform sampler2D DiffuseTexture2;
layout (binding = 3) uniform sampler2D DiffuseTexture3;
layout (binding = 4) uniform sampler2D DiffuseTexture4;
layout (binding = 5) uniform sampler2D DiffuseTexture5;
layout (binding = 6) uniform sampler2D NormalMapTexture1;
layout (binding = 7) uniform sampler2D NormalMapTexture2;
layout (binding = 8) uniform sampler2D NormalMapTexture3;
layout (binding = 9) uniform sampler2D NormalMapTexture4;
layout (binding = 10) uniform sampler2D NormalMapTexture5;
layout (binding = 11) uniform sampler2D SpecularMapTexture1;
layout (binding = 12) uniform sampler2D SpecularMapTexture2;
layout (binding = 13) uniform sampler2D SpecularMapTexture3;
layout (binding = 14) uniform sampler2D SpecularMapTexture4;
layout (binding = 15) uniform sampler2D SpecularMapTexture5;
layout (binding = 16) uniform sampler2D GlowMapTexture1;
layout (binding = 17) uniform sampler2D GlowMapTexture2;
layout (binding = 18) uniform sampler2D GlowMapTexture3;
layout (binding = 19) uniform sampler2D GlowMapTexture4;
layout (binding = 20) uniform sampler2D GlowMapTexture5;
#define TILE_SIZE 16
struct LightSource {
vec4 Position;
vec4 Direction;
vec4 Color;
float Radius;
float Intensity;
float Falloff;
int Type;
};
layout (std430, binding = 1) buffer LightBuffer
{
LightSource List[];
} LightSources;
struct LightGrid {
float Start;
float Amount;
vec2 Padding;
};
layout (std430, binding = 2) buffer LightGridBuffer
{
LightGrid Data[];
} LightGrids;
layout (std430, binding = 4) buffer LightIndexBuffer
{
float LightIndex[];
};
in VertexData{
vec3 Position;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
}Input;
out vec4 sceneColor;
out vec4 bloomColor;
struct LightResult {
vec4 Diffuse;
vec4 Specular;
};
float CalcAttenuation(float radius, float dist, float falloff) {
return 1.0 - smoothstep(radius * 0.3, radius, dist);
}
vec4 CalcSpecular(vec4 lightColor, vec4 viewVec, vec4 lightVec, vec4 normal) {
vec4 R = normalize( reflect(-lightVec, normal));
float RdotV = max( dot(R, viewVec), 0.0);
return lightColor * pow(RdotV, 90.0);
}
vec4 CalcDiffuse(vec4 lightColor, vec4 lightVec, vec4 normal) {
float power = max( dot(normal, lightVec), 0.0);
return lightColor * power;
}
LightResult CalcPointLightSource(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff)
{
vec4 L = lightPos - position;
float dist = length(L);
L = normalize(L);
float attenuation = CalcAttenuation(lightRadius, dist, falloff);
LightResult result;
result.Diffuse = CalcDiffuse(lightColor, L, normal) * attenuation * intensity;
result.Specular = CalcSpecular(lightColor, viewVec, L, normal) * attenuation * intensity;
return result;
}
LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensity, vec4 viewVec, vec4 vertNormal)
{
vec4 L = normalize( -vec4(direction.xyz, 0) );
LightResult result;
result.Diffuse = CalcDiffuse(color, L, vertNormal) * intensity;
result.Specular = CalcSpecular(color, viewVec, L, vertNormal) * intensity;
return result;
}
vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap)
{
mat3 TBN = mat3(tangent, bitangent, normal);
vec3 NormalMap = texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0);
return vec4(TBN * normalize(NormalMap), 0.0);
}
#define TEXTURE_TILE 5.0
vec4 CalcBlendedTexel(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B, sampler2D A, sampler2D D, vec2 tileValues){
vec4 R_Channel = texture2D(R, Input.TextureCoordinate * tileValues);
vec4 G_Channel = texture2D(G, Input.TextureCoordinate * tileValues);
vec4 B_Channel = texture2D(B, Input.TextureCoordinate * tileValues);
vec4 A_Channel = texture2D(A, Input.TextureCoordinate * tileValues);
vec4 D_Channel = texture2D(D, Input.TextureCoordinate * tileValues);
float total = blendValue.r + blendValue.g + blendValue.b + blendValue.a;
if(total > 1.0f){
blendValue.r / total;
blendValue.g / total;
blendValue.b / total;
blendValue.a / total;
}
float D_percent = clamp( 1.0f - total, 0.0f, 1.0f);
return blendValue.r * R_Channel
+ blendValue.g * G_Channel
+ blendValue.b * B_Channel
+ blendValue.a * A_Channel
+ D_percent * D_Channel;
}
vec4 CalcBlendedNormal(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B, sampler2D A, sampler2D D, vec2 tileValues){
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
vec3 R_Channel = texture(R, Input.TextureCoordinate * tileValues).xyz * 2.0 - vec3(1.0);
vec3 G_Channel = texture(G, Input.TextureCoordinate * tileValues).xyz * 2.0 - vec3(1.0);
vec3 B_Channel = texture(B, Input.TextureCoordinate * tileValues).xyz * 2.0 - vec3(1.0);
vec3 A_Channel = texture(A, Input.TextureCoordinate * tileValues).xyz * 2.0 - vec3(1.0);
vec3 D_Channel = texture(D, Input.TextureCoordinate * tileValues).xyz * 2.0 - vec3(1.0);
if(blendValue.length() > 1.0f){
blendValue = normalize(blendValue);
}
float D_percent = 1.0f - blendValue.r - blendValue.g - blendValue.b - blendValue.a;
vec3 Normal_result = blendValue.r * R_Channel
+ blendValue.g * G_Channel
+ blendValue.b * B_Channel
+ blendValue.a * A_Channel
+ D_percent * D_Channel;
return vec4(TBN * normalize(Normal_result), 0.0);
}
void main()
{
vec4 splatTexel = texture2D(SplatMapTexture, Input.TextureCoordinate);
vec4 diffuseTexel = CalcBlendedTexel(splatTexel, DiffuseTexture1, DiffuseTexture2, DiffuseTexture3, DiffuseTexture4, DiffuseTexture5, vec2(TEXTURE_TILE, TEXTURE_TILE));
vec4 glowTexel = CalcBlendedTexel(splatTexel, GlowMapTexture1, GlowMapTexture2, GlowMapTexture3, GlowMapTexture4, GlowMapTexture5, vec2(TEXTURE_TILE, TEXTURE_TILE));
vec4 specularTexel = CalcBlendedTexel(splatTexel, SpecularMapTexture1, SpecularMapTexture2, SpecularMapTexture3, SpecularMapTexture4, SpecularMapTexture5, vec2(TEXTURE_TILE, TEXTURE_TILE));
vec4 position = V * M * vec4(Input.Position, 1.0);
//vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture);
vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3, NormalMapTexture4, NormalMapTexture5, vec2(TEXTURE_TILE, TEXTURE_TILE));
normal = normalize(normal);
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
vec4 viewVec = normalize(-position);
vec2 tilePos;
tilePos.x = int(gl_FragCoord.x/TILE_SIZE);
tilePos.y = int(gl_FragCoord.y/TILE_SIZE);
LightResult totalLighting;
totalLighting.Diffuse = vec4(AmbientColor.rgb, 1.0);
int currentTile = int(floor(gl_FragCoord.x/TILE_SIZE) + (floor(gl_FragCoord.y/TILE_SIZE) * int(ScreenDimensions.x/TILE_SIZE)));
int start = int(LightGrids.Data[currentTile].Start);
int amount = int(LightGrids.Data[currentTile].Amount);
for(int i = start; i < start + amount; i++) {
int l = int(LightIndex[i]);
LightSource light = LightSources.List[l];
LightResult light_result;
//These if statements should be removed.
if(light.Type == 1) { // point
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
} else if (light.Type == 2) { //Directional
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
}
totalLighting.Diffuse += light_result.Diffuse;
totalLighting.Specular += light_result.Specular;
}
vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed);
color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel));
//vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color;
float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0;
if(pos <= FillPercentage) {
color_result += FillColor;
}
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
color_result += glowTexel*3;
bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0);
//Tiled Debug Code
/*
if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 ) {
sceneColor += vec4(0.5, 0, 0, 0);
} else {
sceneColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/LightSources.List.length(), 0, 0, 1);
}
*/
}
+8 -8
View File
@@ -77,8 +77,8 @@ void DrawBloomPass::Draw(GLuint texture)
glBindVertexArray(m_ScreenQuad->VAO); glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1 glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex); , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
//Iterate some times to make it more gaussian. //Iterate some times to make it more gaussian.
for (int i = 1; i < m_iterations; i++) { for (int i = 1; i < m_iterations; i++) {
@@ -90,8 +90,8 @@ void DrawBloomPass::Draw(GLuint texture)
glBindVertexArray(m_ScreenQuad->VAO); glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1 glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex); , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
//horizontal pass //horizontal pass
@@ -102,8 +102,8 @@ void DrawBloomPass::Draw(GLuint texture)
glBindVertexArray(m_ScreenQuad->VAO); glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1 glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex); , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
} }
//final vertical gaussian after the iterations are done //final vertical gaussian after the iterations are done
@@ -115,8 +115,8 @@ void DrawBloomPass::Draw(GLuint texture)
glBindVertexArray(m_ScreenQuad->VAO); glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1 glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex); , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
GLERROR("DrawBloomPass::Draw: END"); GLERROR("DrawBloomPass::Draw: END");
} }
@@ -38,6 +38,6 @@ void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture, GLf
glBindVertexArray(m_ScreenQuad->VAO); glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1 glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex); , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
} }
+158 -50
View File
@@ -55,6 +55,15 @@ void DrawFinalPass::InitializeShaderPrograms()
m_ExplosionEffectProgram->BindFragDataLocation(1, "bloomColor"); m_ExplosionEffectProgram->BindFragDataLocation(1, "bloomColor");
m_ExplosionEffectProgram->Link(); m_ExplosionEffectProgram->Link();
GLERROR("Creating explosion program"); GLERROR("Creating explosion program");
m_ForwardPlusSplatMapProgram = ResourceManager::Load<ShaderProgram>("#ForwardPlusSplatMapProgram");
m_ForwardPlusSplatMapProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardPlus.vert.glsl")));
m_ForwardPlusSplatMapProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusSplatMap.frag.glsl")));
m_ForwardPlusSplatMapProgram->Compile();
m_ForwardPlusSplatMapProgram->BindFragDataLocation(0, "sceneColor");
m_ForwardPlusSplatMapProgram->BindFragDataLocation(1, "bloomColor");
m_ForwardPlusSplatMapProgram->Link();
GLERROR("Creating SplatMap program");
} }
void DrawFinalPass::Draw(RenderScene& scene) void DrawFinalPass::Draw(RenderScene& scene)
@@ -114,8 +123,9 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
{ {
GLuint forwardHandle = m_ForwardPlusProgram->GetHandle(); GLuint forwardHandle = m_ForwardPlusProgram->GetHandle();
GLERROR("forwardHandle"); GLERROR("forwardHandle");
GLuint explosionHandle = m_ExplosionEffectProgram->GetHandle(); GLuint explosionHandle = m_ExplosionEffectProgram->GetHandle();
GLERROR("explosionHandle"); GLERROR("explosionHandle");
GLuint forwardSplatHandle = m_ForwardPlusSplatMapProgram->GetHandle();
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
@@ -171,14 +181,32 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job); auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob) { if (modelJob) {
//bind forward program //bind forward program
m_ForwardPlusProgram->Bind(); //TODO: JOHAN/TOBIAS: Bind shader based on ModelJob->ShaderID;
glUniform2f(glGetUniformLocation(forwardHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); switch (modelJob->Type) {
case RawModel::MaterialType::Basic:
case RawModel::MaterialType::SingleTextures:
{
m_ForwardPlusProgram->Bind();
GLERROR("Bind Forward program");
//bind uniforms
BindModelUniforms(forwardHandle, modelJob, scene);
break;
}
case RawModel::MaterialType::SplatMapping:
{
m_ForwardPlusSplatMapProgram->Bind();
GLERROR("Bind SplatMap program");
//bind uniforms
BindModelUniforms(forwardSplatHandle, modelJob, scene);
break;
}
}
//bind textures
BindModelTextures(modelJob);
GLERROR("asdasd");
//bind uniforms
BindModelUniforms(forwardHandle, modelJob, scene);
//bind textures
BindModelTextures(modelJob);
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
@@ -230,48 +258,65 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<E
void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<ModelJob>& job, RenderScene& scene) void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<ModelJob>& job, RenderScene& scene)
{ {
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(job->Matrix)); GLERROR("Bind 1 uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); GLint Location_M = glGetUniformLocation(shaderHandle, "M");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniformMatrix4fv(Location_M, 1, GL_FALSE, glm::value_ptr(job->Matrix));
GLERROR("Bind 2 uniform");
GLint Location_V = glGetUniformLocation(shaderHandle, "V");
glUniformMatrix4fv(Location_V, 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
GLERROR("Bind 3 uniform");
GLint Location_P = glGetUniformLocation(shaderHandle, "P");
glUniformMatrix4fv(Location_P, 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
GLERROR("Bind 4 uniform");
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); GLint Location_ScreenDimensions = glGetUniformLocation(shaderHandle, "ScreenDimensions");
glUniform2f(Location_ScreenDimensions, m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
GLERROR("Bind 5 uniform");
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(job->Color)); GLint Location_FillPercentage = glGetUniformLocation(shaderHandle, "FillPercentage");
glUniform4fv(glGetUniformLocation(shaderHandle, "DiffuseColor"), 1, glm::value_ptr(job->DiffuseColor)); glUniform1f(Location_FillPercentage, job->FillPercentage);
glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(job->FillColor)); GLERROR("Bind 6 uniform");
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), job->FillPercentage); GLint Location_DiffuseColor = glGetUniformLocation(shaderHandle, "DiffuseColor");
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor)); glUniform4fv(Location_DiffuseColor, 1, glm::value_ptr(job->DiffuseColor));
GLERROR("Bind 7 uniform");
GLint Location_FillColor = glGetUniformLocation(shaderHandle, "FillColor");
glUniform4fv(Location_FillColor, 1, glm::value_ptr(job->FillColor));
GLERROR("Bind 8 uniform");
GLint Location_Color = glGetUniformLocation(shaderHandle, "Color");
glUniform4fv(Location_Color, 1, glm::value_ptr(job->Color));
GLERROR("Bind 9 uniform");
GLint Location_AmbientColor = glGetUniformLocation(shaderHandle, "AmbientColor");
glUniform4fv(Location_AmbientColor, 1, glm::value_ptr(scene.AmbientColor));
GLERROR("END"); GLERROR("END");
} }
void DrawFinalPass::BindExplosionTextures(std::shared_ptr<ExplosionEffectJob>& job) void DrawFinalPass::BindExplosionTextures(std::shared_ptr<ExplosionEffectJob>& job)
{ {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
if (job->DiffuseTexture != nullptr) { if (job->DiffuseTexture.size() > 0 && job->DiffuseTexture[0] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture[0]->m_Texture); //JOHAN TODO: support multiple diffuse Textures
} else { } else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
} }
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
if (job->NormalTexture != nullptr) { if (job->NormalTexture.size() > 0 && job->NormalTexture[0] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->NormalTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, job->NormalTexture[0]->m_Texture); //JOHAN TODO: support multiple diffuse Textures
} else { } else {
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
} }
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
if (job->SpecularTexture != nullptr) { if (job->SpecularTexture.size() > 0 && job->SpecularTexture[0] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, job->SpecularTexture[0]->m_Texture); //JOHAN TODO: support multiple diffuse Textures
} else { } else {
glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture);
} }
glActiveTexture(GL_TEXTURE3); glActiveTexture(GL_TEXTURE3);
if (job->IncandescenceTexture != nullptr) { if (job->IncandescenceTexture.size() > 0 && job->IncandescenceTexture[0] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture[0]->m_Texture); //JOHAN TODO: support multiple diffuse Textures
} else { } else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
} }
@@ -279,32 +324,95 @@ void DrawFinalPass::BindExplosionTextures(std::shared_ptr<ExplosionEffectJob>& j
void DrawFinalPass::BindModelTextures(std::shared_ptr<ModelJob>& job) void DrawFinalPass::BindModelTextures(std::shared_ptr<ModelJob>& job)
{ {
glActiveTexture(GL_TEXTURE0); switch (job->Type) {
if (job->DiffuseTexture != nullptr) { case RawModel::MaterialType::SingleTextures:
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture->m_Texture); case RawModel::MaterialType::Basic:
} else { {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); glActiveTexture(GL_TEXTURE0);
} if (job->DiffuseTexture.size() > 0 && job->DiffuseTexture[0] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture[0]->m_Texture);
}
else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
if (job->NormalTexture != nullptr) { if (job->NormalTexture.size() > 0 && job->NormalTexture[0] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->NormalTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, job->NormalTexture[0]->m_Texture);
} else { }
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture); else {
} glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
if (job->SpecularTexture != nullptr) { if (job->SpecularTexture.size() > 0 && job->SpecularTexture[0] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, job->SpecularTexture[0]->m_Texture);
} else { }
glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture); else {
} glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE3); glActiveTexture(GL_TEXTURE3);
if (job->IncandescenceTexture != nullptr) { if (job->IncandescenceTexture.size() > 0 && job->IncandescenceTexture[0] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture[0]->m_Texture);
} else { }
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); else {
} glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}
break;
}
case RawModel::MaterialType::SplatMapping:
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, job->SplatMap->m_Texture);
int texturePosition = GL_TEXTURE1;
//Bind 5 diffuse textures
for (unsigned int i = 0; i < 5; i++) {
glActiveTexture(texturePosition);
if (job->DiffuseTexture.size() > i && job->DiffuseTexture[i] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture[i]->m_Texture);
}
else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
texturePosition++;
}
//Bind 5 Normal textures
for (unsigned int i = 0; i < 5; i++) {
glActiveTexture(texturePosition);
if (job->NormalTexture.size() > i && job->NormalTexture[i] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->NormalTexture[i]->m_Texture);
}
else {
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
}
texturePosition++;
}
//Bind 5 Specular textures
for (unsigned int i = 0; i < 5; i++) {
glActiveTexture(texturePosition);
if (job->SpecularTexture.size() > i && job->SpecularTexture[i] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture[i]->m_Texture);
}
else {
glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture);
}
texturePosition++;
}
//Bind 5 Incandescence textures
for (unsigned int i = 0; i < 5; i++) {
glActiveTexture(texturePosition);
if (job->IncandescenceTexture.size() > i && job->IncandescenceTexture[i] != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture[i]->m_Texture);
}
else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}
texturePosition++;
}
break;
}
}
} }
+2 -2
View File
@@ -32,6 +32,6 @@ void DrawScreenQuadPass::Draw(GLuint texture)
glBindVertexArray(m_ScreenQuad->VAO); glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1 glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex); , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
} }
+63 -13
View File
@@ -5,19 +5,69 @@ Model::Model(std::string fileName)
//Try loading the model asyncronously, if it throws any exceptions then let it propagate back to caller. //Try loading the model asyncronously, if it throws any exceptions then let it propagate back to caller.
m_RawModel = ResourceManager::Load<RawModel, true>(fileName); m_RawModel = ResourceManager::Load<RawModel, true>(fileName);
for (auto& group : m_RawModel->MaterialGroups) { for (auto& materialProperty : m_RawModel->m_Materials) {
if (!group.TexturePath.empty()) { switch (materialProperty.type) {
group.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.TexturePath)); case RawModel::MaterialType::SingleTextures:
} {
if (!group.NormalMapPath.empty()) { RawModel::MaterialSingleTextures* materialSingleTexture = static_cast<RawModel::MaterialSingleTextures*>(materialProperty.material);
group.NormalMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.NormalMapPath)); if (!materialSingleTexture->ColorMap.TexturePath.empty()) {
} materialSingleTexture->ColorMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSingleTexture->ColorMap.TexturePath));
if (!group.SpecularMapPath.empty()) { }
group.SpecularMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.SpecularMapPath)); if (!materialSingleTexture->NormalMap.TexturePath.empty()) {
} materialSingleTexture->NormalMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSingleTexture->NormalMap.TexturePath));
if (!group.IncandescenceMapPath.empty()) { }
group.IncandescenceMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.IncandescenceMapPath)); if (!materialSingleTexture->SpecularMap.TexturePath.empty()) {
} materialSingleTexture->SpecularMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSingleTexture->SpecularMap.TexturePath));
}
if (!materialSingleTexture->IncandescenceMap.TexturePath.empty()) {
materialSingleTexture->IncandescenceMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSingleTexture->IncandescenceMap.TexturePath));
}
}
break;
case RawModel::MaterialType::SplatMapping:
{
RawModel::MaterialSplatMapping* materialSplatMapping = static_cast<RawModel::MaterialSplatMapping*>(materialProperty.material);
if (!materialSplatMapping->SplatMap.TexturePath.empty()) {
materialSplatMapping->SplatMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSplatMapping->SplatMap.TexturePath));
}
for (auto& texture : materialSplatMapping->ColorMaps)
{
if (!texture.TexturePath.empty()) {
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
}
else {
texture.Texture = nullptr;
}
}
for (auto& texture : materialSplatMapping->NormalMaps)
{
if (!texture.TexturePath.empty()) {
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
} else {
texture.Texture = nullptr;
}
}
for (auto& texture : materialSplatMapping->SpecularMaps)
{
if (!texture.TexturePath.empty()) {
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
}
else {
texture.Texture = nullptr;
}
}
for (auto& texture : materialSplatMapping->IncandescenceMaps)
{
if (!texture.TexturePath.empty()) {
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
}
else {
texture.Texture = nullptr;
}
}
}
break;
}
} }
// Generate GL buffers // Generate GL buffers
+26 -21
View File
@@ -34,7 +34,7 @@ void RawModelCustom::ReadMeshFile(std::string filePath)
ReadMeshFileHeader(offset, fileData); ReadMeshFileHeader(offset, fileData);
ReadMesh(offset, fileData, fileByteSize); ReadMesh(offset, fileData, fileByteSize);
} }
delete fileData; delete[] fileData;
} }
void RawModelCustom::ReadMeshFileHeader(std::size_t& offset, char* fileData) void RawModelCustom::ReadMeshFileHeader(std::size_t& offset, char* fileData)
@@ -116,7 +116,7 @@ void RawModelCustom::ReadMaterialFile(std::string filePath)
if (fileByteSize > 0) { if (fileByteSize > 0) {
ReadMaterials(offset, fileData, fileByteSize); ReadMaterials(offset, fileData, fileByteSize);
} }
delete fileData; delete[] fileData;
} }
void RawModelCustom::ReadMaterials(std::size_t& offset, char* fileData, const unsigned int& fileByteSize) void RawModelCustom::ReadMaterials(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
@@ -169,15 +169,8 @@ void RawModelCustom::ReadMaterialSingle(std::size_t& offset, char* fileData, con
m_Materials.push_back(newMaterialProperty); m_Materials.push_back(newMaterialProperty);
} }
void RawModelCustom::ReadMaterialBasic(RawModelCustom::MaterialBasic* newMaterial, unsigned int &offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadMaterialBasic(RawModelCustom::MaterialBasic* newMaterial, std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
{ {
if (offset + sizeof(unsigned int) * 4 > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material texture names length failed");
}
unsigned int* nameLengths = (unsigned int*)(fileData + offset);
offset += sizeof(unsigned int) * 4;
if (offset + sizeof(float) * 11 + sizeof(unsigned int) * 2 > fileByteSize) { if (offset + sizeof(float) * 11 + sizeof(unsigned int) * 2 > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material specular, reflection, color and start and end index values failed"); throw Resource::FailedLoadingException("Reading Material specular, reflection, color and start and end index values failed");
} }
@@ -200,42 +193,49 @@ void RawModelCustom::ReadMaterialBasic(RawModelCustom::MaterialBasic* newMateria
offset += sizeof(unsigned int); offset += sizeof(unsigned int);
} }
void RawModelCustom::ReadMaterialSingleTexture(RawModelCustom::MaterialSingleTextures* newMaterial, unsigned int &offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadMaterialSingleTexture(RawModelCustom::MaterialSingleTextures* newMaterial, std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
{ {
unsigned char numberOfMaps[4]; ReadMaterialBasic(newMaterial, offset, fileData, fileByteSize);
if (offset + sizeof(unsigned char) * 4 > fileByteSize) { if (offset + sizeof(unsigned char) * 4 > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material NumOfMaps failed"); throw Resource::FailedLoadingException("Reading Material NumOfMaps failed");
} }
unsigned char numberOfMaps[4];
memcpy(numberOfMaps, fileData + offset, sizeof(unsigned char) * 4);
offset += sizeof(unsigned char) * 4;
if (numberOfMaps[0] > 0) if (numberOfMaps[0] > 0)
{ {
ReadMaterialTextureProperties(newMaterial->ColorMaps, offset, fileData, fileByteSize); ReadMaterialTextureProperties(newMaterial->ColorMap, offset, fileData, fileByteSize);
} }
if (numberOfMaps[1] > 0) if (numberOfMaps[1] > 0)
{ {
ReadMaterialTextureProperties(newMaterial->SpecularMaps, offset, fileData, fileByteSize); ReadMaterialTextureProperties(newMaterial->SpecularMap, offset, fileData, fileByteSize);
} }
if (numberOfMaps[2] > 0) if (numberOfMaps[2] > 0)
{ {
ReadMaterialTextureProperties(newMaterial->NormalMaps, offset, fileData, fileByteSize); ReadMaterialTextureProperties(newMaterial->NormalMap, offset, fileData, fileByteSize);
} }
if (numberOfMaps[3] > 0) if (numberOfMaps[3] > 0)
{ {
ReadMaterialTextureProperties(newMaterial->IncandescenceMaps, offset, fileData, fileByteSize); ReadMaterialTextureProperties(newMaterial->IncandescenceMap, offset, fileData, fileByteSize);
} }
} }
void RawModelCustom::ReadMaterialSplatMapping(RawModelCustom::MaterialSplatMapping* newMaterial, unsigned int &offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadMaterialSplatMapping(RawModelCustom::MaterialSplatMapping* newMaterial, std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
{ {
ReadMaterialBasic(newMaterial, offset, fileData, fileByteSize);
ReadMaterialTextureProperties(newMaterial->SplatMap, offset, fileData, fileByteSize); ReadMaterialTextureProperties(newMaterial->SplatMap, offset, fileData, fileByteSize);
unsigned char numberOfMaps[4];
if (offset + sizeof(unsigned char) * 4 > fileByteSize) { if (offset + sizeof(unsigned char) * 4 > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material NumOfMaps failed"); throw Resource::FailedLoadingException("Reading Material NumOfMaps failed");
} }
unsigned char numberOfMaps[4];
memcpy(numberOfMaps, fileData + offset, sizeof(unsigned char) * 4);
offset += sizeof(unsigned char) * 4;
newMaterial->ColorMaps.resize(numberOfMaps[0]); newMaterial->ColorMaps.resize(numberOfMaps[0]);
for (unsigned char i = 0; i < numberOfMaps[0]; i++) for (unsigned char i = 0; i < numberOfMaps[0]; i++)
{ {
@@ -261,8 +261,10 @@ void RawModelCustom::ReadMaterialSplatMapping(RawModelCustom::MaterialSplatMappi
} }
} }
void RawModelCustom::ReadMaterialTextureProperties(RawModelCustom::TextureProperties& texture, unsigned int &offset, char* fileData, unsigned int& fileByteSize) { void RawModelCustom::ReadMaterialTextureProperties(RawModelCustom::TextureProperties& texture, std::size_t& offset, char* fileData, const unsigned int& fileByteSize) {
unsigned int nameLength = *(unsigned int*)(fileData + offset); unsigned int nameLength = *(unsigned int*)(fileData + offset);
offset += sizeof(unsigned int);
if (nameLength > 0) { if (nameLength > 0) {
if (offset + nameLength > fileByteSize) { if (offset + nameLength > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material texture path failed"); throw Resource::FailedLoadingException("Reading Material texture path failed");
@@ -312,7 +314,7 @@ void RawModelCustom::ReadAnimationFile(std::string filePath)
ReadAnimationBindPoses(offset, fileData, fileByteSize); ReadAnimationBindPoses(offset, fileData, fileByteSize);
ReadAnimationClips(offset, fileData, fileByteSize, numAnimations); ReadAnimationClips(offset, fileData, fileByteSize, numAnimations);
} }
delete fileData; delete[] fileData;
} }
void RawModelCustom::ReadAnimationBindPoses(std::size_t& offset, char* fileData, const unsigned int& fileByteSize) void RawModelCustom::ReadAnimationBindPoses(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
@@ -432,7 +434,7 @@ void RawModelCustom::ReadAnimationClipSingle(std::size_t& offset, char* fileData
#endif #endif
} }
void RawModelCustom::ReadAnimationKeyFrame(std::size_t& &offset, char* fileData, const unsigned int& fileByteSize, std::vector<Skeleton::Animation::Keyframe>& animation) void RawModelCustom::ReadAnimationKeyFrame(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, std::vector<Skeleton::Animation::Keyframe>& animation)
{ {
Skeleton::Animation::Keyframe newKeyFrame; Skeleton::Animation::Keyframe newKeyFrame;
@@ -475,6 +477,9 @@ RawModelCustom::~RawModelCustom()
if (m_Skeleton != nullptr) { if (m_Skeleton != nullptr) {
delete m_Skeleton; delete m_Skeleton;
} }
for (auto material : m_Materials) {
delete material.material;
}
} }
#endif #endif
+3
View File
@@ -113,6 +113,7 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs,
if (cModel["Transparent"]) { if (cModel["Transparent"]) {
transparentJobs.push_back(explosionEffectJob); transparentJobs.push_back(explosionEffectJob);
} else { } else {
explosionEffectJob->CalculateHash();
opaqueJobs.push_back(explosionEffectJob); opaqueJobs.push_back(explosionEffectJob);
} }
} else { } else {
@@ -132,6 +133,7 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs,
if (cModel["Transparent"]) { if (cModel["Transparent"]) {
transparentJobs.push_back(modelJob); transparentJobs.push_back(modelJob);
} else { } else {
modelJob->CalculateHash();
opaqueJobs.push_back(modelJob); opaqueJobs.push_back(modelJob);
} }
} }
@@ -252,6 +254,7 @@ void RenderSystem::Update(double dt)
} }
fillModels(scene.OpaqueObjects, scene.TransparentObjects); fillModels(scene.OpaqueObjects, scene.TransparentObjects);
scene.OpaqueObjects.sort();
fillPointLights(scene.PointLightJobs, m_World); fillPointLights(scene.PointLightJobs, m_World);
fillDirectionalLights(scene.DirectionalLightJobs, m_World); fillDirectionalLights(scene.DirectionalLightJobs, m_World);
fillText(scene.TextJobs, m_World); fillText(scene.TextJobs, m_World);
+3 -3
View File
@@ -48,16 +48,16 @@ std::vector<glm::mat4> Skeleton::GetFrameBones(const Animation& animation, doubl
while (time > animation.Duration) { while (time > animation.Duration) {
time -= animation.Duration; time -= animation.Duration;
} }
//JOHAN TODO: Ask Viktor about stuff
//int currentKeyframeIndex = GetKeyframe(animation, time); //int currentKeyframeIndex = GetKeyframe(animation, time);
//const Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex]; //const Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex];
//const Animation::Keyframe& nextFrame = animation.Keyframes[(currentKeyframeIndex + 1) % animation.Keyframes.size()]; //const Animation::Keyframe& nextFrame = animation.Keyframes[(currentKeyframeIndex + 1) % animation.Keyframes.size()];
double alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); //double alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
////auto animationFrame = Animations[""].Keyframes[frame]; ////auto animationFrame = Animations[""].Keyframes[frame];
std::map<int, glm::mat4> frameBones; std::map<int, glm::mat4> frameBones;
AccumulateBoneTransforms(noRootMotion, currentFrame, nextFrame, static_cast<float>(alpha), frameBones, RootBone, glm::mat4(1)); //AccumulateBoneTransforms(noRootMotion, currentFrame, nextFrame, static_cast<float>(alpha), frameBones, RootBone, glm::mat4(1));
std::vector<glm::mat4> finalMatrices; std::vector<glm::mat4> finalMatrices;
for (auto &kv : frameBones) { for (auto &kv : frameBones) {
+175 -15
View File
@@ -88,14 +88,30 @@ bool Material::findColorTexture(MaterialNode& material_node, MFnDependencyNode&
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
newTexture.FileNameLength = newTexture.FileName.length() + 1; newTexture.FileNameLength = newTexture.FileName.length() + 1;
newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat(); MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat();
uvRepeatFile.connectedTo(AllConnections, true, false);
for (int i = 0; i < AllConnections.length(); i++) {
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
MFnDependencyNode place2DTexture(AllConnections[i].node());
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
}
}
material_node.ColorMaps.push_back(newTexture); material_node.ColorMaps.push_back(newTexture);
if(material_node.type == MaterialNode::MaterialType::Basic)
material_node.type = MaterialNode::MaterialType::SingleTextures;
return true; return true;
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
MGlobal::displayInfo(MString() + "find splat map");
return findSplatTextures(material_node, material_node.ColorMaps, MFnDependencyNode(AllConnections[i].node()));
} }
} }
return false; return false;
} }
@@ -130,11 +146,25 @@ bool Material::findNormalTexture(MaterialNode& material_node, MFnDependencyNode&
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
newTexture.FileNameLength = newTexture.FileName.length() + 1; newTexture.FileNameLength = newTexture.FileName.length() + 1;
newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat(); MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat();
uvRepeatFile.connectedTo(AllConnections, true, false);
for (int i = 0; i < AllConnections.length(); i++) {
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
MFnDependencyNode place2DTexture(AllConnections[i].node());
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
}
}
material_node.NormalMaps.push_back(newTexture); material_node.NormalMaps.push_back(newTexture);
return true; return true;
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
MGlobal::displayInfo(MString() + "find splat map");
return findSplatTextures(material_node, material_node.NormalMaps, MFnDependencyNode(AllConnections[i].node()));
} }
} }
} }
@@ -168,11 +198,28 @@ bool Material::findSpecularTexture(MaterialNode& material_node, MFnDependencyNod
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
newTexture.FileNameLength = newTexture.FileName.length() + 1; newTexture.FileNameLength = newTexture.FileName.length() + 1;
newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat(); MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat();
uvRepeatFile.connectedTo(AllConnections, true, false);
for (int i = 0; i < AllConnections.length(); i++) {
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
//C:\Users\kamisama\Desktop\TacticalZ\assets\test
MFnDependencyNode place2DTexture(AllConnections[i].node());
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
}
}
material_node.SpecularMaps.push_back(newTexture); material_node.SpecularMaps.push_back(newTexture);
if (material_node.type == MaterialNode::MaterialType::Basic)
material_node.type = MaterialNode::MaterialType::SingleTextures;
return true; return true;
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
MGlobal::displayInfo(MString() + "find splat map");
return findSplatTextures(material_node, material_node.SpecularMaps, MFnDependencyNode(AllConnections[i].node()));
} }
} }
return false; return false;
@@ -203,21 +250,133 @@ bool Material::findIncandescenceTexture(MaterialNode& material_node, MFnDependen
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
newTexture.FileNameLength = newTexture.FileName.length() + 1; newTexture.FileNameLength = newTexture.FileName.length() + 1;
newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat(); MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat();
uvRepeatFile.connectedTo(AllConnections, true, false);
for (int i = 0; i < AllConnections.length(); i++) {
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
MFnDependencyNode place2DTexture(AllConnections[i].node());
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
}
}
material_node.IncandescenceMaps.push_back(newTexture); material_node.IncandescenceMaps.push_back(newTexture);
if (material_node.type == MaterialNode::MaterialType::Basic)
material_node.type = MaterialNode::MaterialType::SingleTextures;
return true; return true;
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) { } else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
return findSplatTextures(material_node.IncandescenceMaps, MFnDependencyNode(AllConnections[i].node())); MGlobal::displayInfo(MString() + "find splat map");
return findSplatTextures(material_node, material_node.IncandescenceMaps, MFnDependencyNode(AllConnections[i].node()));
} }
} }
return false; return false;
} }
bool Material::findSplatTextures(std::vector<MaterialNode::Texture>& textureVector, MFnDependencyNode& node) { //C:\Users\kamisama\Desktop\TacticalZ\assets\test
return false;
bool Material::findSplatTextures(MaterialNode& material_node, std::vector<MaterialNode::Texture>& textureVector, MFnDependencyNode& node) {
//Get all Inputs in LayeredTexture
MPlug inputs = node.findPlug("inputs");
MGlobal::displayInfo(MString() + "inputs.numElements(): " + inputs.numElements());
MPlugArray AllConnections;
MStatus test;
//Try to find splat texture if using custom splatmap build up.
inputs[0].child(1).connectedTo(AllConnections, true, false);
for (int i = 0; i < AllConnections.length(); i++) {
if (AllConnections[i].node().hasFn(MFn::kMultiplyDivide)) {
MGlobal::displayInfo(MString() + "found kMultiplyDivide");
MFnDependencyNode multiplyDivide(AllConnections[i].node());
multiplyDivide.findPlug("input1", &test).child(0).connectedTo(AllConnections, true, false);;
for (int i = 0; i < AllConnections.length(); i++) {
if (AllConnections[i].node().hasFn(MFn::kFileTexture)) {
MFnDependencyNode TextureNode(AllConnections[i].node());
std::string FullPath = TextureNode.findPlug("ftn").asString().asChar();
m_TexturePaths.push_back(FullPath);
MString workspace;
MStatus status = MGlobal::executeCommand(MString("workspace -q -rd;"),
workspace);
FullPath = FullPath.substr(workspace.length());
FullPath = FullPath.substr(FullPath.find_first_of("/") + 1);
MaterialNode::Texture newTexture;
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
newTexture.FileNameLength = newTexture.FileName.length() + 1;
MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
uvRepeatFile.connectedTo(AllConnections, true, false);
for (int i = 0; i < AllConnections.length(); i++) {
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
MFnDependencyNode place2DTexture(AllConnections[i].node());
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
}
}
material_node.SplatMap = newTexture;
material_node.type = MaterialNode::MaterialType::SplatMapping;
}
}
}
}
for (unsigned int i = 0; i < inputs.numElements(); i++) {
//Get connections to color in input[i]
inputs[i].child(0).connectedTo(AllConnections, true, false);
for (int i = 0; i < AllConnections.length(); i++) {
if (AllConnections[i].node().hasFn(MFn::kFileTexture)) {
MFnDependencyNode TextureNode(AllConnections[i].node());
std::string FullPath = TextureNode.findPlug("ftn").asString().asChar();
m_TexturePaths.push_back(FullPath);
MString workspace;
MStatus status = MGlobal::executeCommand(MString("workspace -q -rd;"),
workspace);
FullPath = FullPath.substr(workspace.length());
FullPath = FullPath.substr(FullPath.find_first_of("/") + 1);
MaterialNode::Texture newTexture;
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
newTexture.FileNameLength = newTexture.FileName.length() + 1;
MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
uvRepeatFile.connectedTo(AllConnections, true, false);
for (int i = 0; i < AllConnections.length(); i++) {
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
MFnDependencyNode place2DTexture(AllConnections[i].node());
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
}
}
textureVector.push_back(newTexture);
break;
}
}
if (AllConnections.length() == 0) {
MaterialNode::Texture newTexture;
newTexture.FileNameLength = 0;
textureVector.push_back(newTexture);
}
}
return true;
} }
// Returns the absolute path for all textures. Use for copying texture files. // Returns the absolute path for all textures. Use for copying texture files.
@@ -244,8 +403,6 @@ std::vector<MaterialNode>* Material::DoIt(Mesh mesh)
meshHasMaterial = true; meshHasMaterial = true;
MaterialStorage.IndexStart = totalIndices; MaterialStorage.IndexStart = totalIndices;
MaterialStorage.IndexEnd = totalIndices + aMeshMaterial.second.size() - 1; MaterialStorage.IndexEnd = totalIndices + aMeshMaterial.second.size() - 1;
MGlobal::displayInfo("Oh noes, breaking in material");
break;
} }
totalIndices += aMeshMaterial.second.size(); totalIndices += aMeshMaterial.second.size();
} }
@@ -262,7 +419,10 @@ std::vector<MaterialNode>* Material::DoIt(Mesh mesh)
MaterialStorage.ReflectionFactor = 0.0f; MaterialStorage.ReflectionFactor = 0.0f;
MaterialStorage.SpecularExponent = 0.0f; MaterialStorage.SpecularExponent = 0.0f;
} }
MaterialStorage.NumColorMaps = MaterialStorage.ColorMaps.size();
MaterialStorage.NumNormalMaps = MaterialStorage.NormalMaps.size();
MaterialStorage.NumSpecularMaps = MaterialStorage.SpecularMaps.size();
MaterialStorage.NumIncandescenceMaps = MaterialStorage.IncandescenceMaps.size();
m_AllMaterials.push_back(MaterialStorage); m_AllMaterials.push_back(MaterialStorage);
} }
matIt.next(); matIt.next();
+81 -50
View File
@@ -17,6 +17,8 @@
//#define NormalMapSplat 1 << 2 //#define NormalMapSplat 1 << 2
//#define IncandescenceMapSplat 1 << 3 //#define IncandescenceMapSplat 1 << 3
class MaterialNode : public OutputData class MaterialNode : public OutputData
{ {
public: public:
@@ -41,6 +43,10 @@ public:
} }
}; };
enum class MaterialType { Basic = 1, SplatMapping, SingleTextures };
MaterialType type = MaterialType::Basic;
std::string Name; std::string Name;
float ReflectionFactor; float ReflectionFactor;
@@ -53,11 +59,11 @@ public:
unsigned int IndexStart; unsigned int IndexStart;
unsigned int IndexEnd; unsigned int IndexEnd;
char NumColormaps = 0; unsigned char NumColorMaps = 0;
char NumSpecularMap = 0; unsigned char NumSpecularMaps = 0;
char NumNormalMap = 0; unsigned char NumNormalMaps = 0;
char NumIncandescenceMap = 0; unsigned char NumIncandescenceMaps = 0;
Texture SplatMap;
std::vector<Texture> ColorMaps; std::vector<Texture> ColorMaps;
std::vector<Texture> SpecularMaps; std::vector<Texture> SpecularMaps;
std::vector<Texture> NormalMaps; std::vector<Texture> NormalMaps;
@@ -65,6 +71,8 @@ public:
virtual void WriteBinary(std::ostream& out) virtual void WriteBinary(std::ostream& out)
{ {
out.write((char*)&type, sizeof(MaterialType));
out.write((char*)&SpecularExponent, sizeof(float)); out.write((char*)&SpecularExponent, sizeof(float));
out.write((char*)&ReflectionFactor, sizeof(float)); out.write((char*)&ReflectionFactor, sizeof(float));
@@ -74,30 +82,52 @@ public:
out.write((char*)&IndexStart, sizeof(unsigned int)); out.write((char*)&IndexStart, sizeof(unsigned int));
out.write((char*)&IndexEnd, sizeof(unsigned int)); out.write((char*)&IndexEnd, sizeof(unsigned int));
if (type != MaterialType::Basic) {
if (type == MaterialType::SplatMapping) {
SplatMap.WriteBinary(out);
}
out.write((char*)&NumColorMaps, sizeof(unsigned char));
out.write((char*)&NumSpecularMaps, sizeof(unsigned char));
out.write((char*)&NumNormalMaps, sizeof(unsigned char));
out.write((char*)&NumIncandescenceMaps, sizeof(unsigned char));
}
out.write((char*)&NumColormaps, sizeof(char)); if (type != MaterialType::Basic) {
out.write((char*)&NumSpecularMap, sizeof(char)); for (auto aTexture : ColorMaps) {
out.write((char*)&NumNormalMap, sizeof(char)); aTexture.WriteBinary(out);
out.write((char*)&NumIncandescenceMap, sizeof(char)); }
for (auto aTexture : SpecularMaps) {
for(auto aTexture : ColorMaps) { aTexture.WriteBinary(out);
aTexture.WriteBinary(out); }
} for (auto aTexture : NormalMaps) {
for (auto aTexture : SpecularMaps) { aTexture.WriteBinary(out);
aTexture.WriteBinary(out); }
} for (auto aTexture : IncandescenceMaps) {
for (auto aTexture : NormalMaps) { aTexture.WriteBinary(out);
aTexture.WriteBinary(out); }
}
for (auto aTexture : IncandescenceMaps) {
aTexture.WriteBinary(out);
} }
} }
virtual void WriteASCII(std::ostream& out) const virtual void WriteASCII(std::ostream& out) const
{ {
out << "New Material _ not in binary" << endl; out << "New Material _ not in binary" << endl;
out << "number of indices: " << Name << " _ not in binary" << endl;
out << "MaterialType(enum): ";
switch (type) {
case MaterialType::Basic:
out << "Basic";
break;
case MaterialType::SplatMapping:
out << "SplatMapping";
break;
case MaterialType::SingleTextures:
out << "SingleTextures";
break;
};
out << endl;
out << "Material Name: " << Name << " _ not in binary" << endl;
out << "SpecularExponent: " << SpecularExponent << endl; out << "SpecularExponent: " << SpecularExponent << endl;
out << "ReflectionFactor: " << ReflectionFactor << endl; out << "ReflectionFactor: " << ReflectionFactor << endl;
@@ -107,37 +137,38 @@ public:
out << "IndexStart: " << IndexStart << endl; out << "IndexStart: " << IndexStart << endl;
out << "IndexEnd: " << IndexEnd << endl; out << "IndexEnd: " << IndexEnd << endl;
if (NumColormaps > 0) switch (type) {
out << "NumColormaps: " << NumColormaps << endl; case MaterialType::SplatMapping:
out << "SplatMap _ not in binary " << endl;
SplatMap.WriteASCII(out);
//Intended fall trought
case MaterialType::SingleTextures:
out << "NumColormaps (is unsigned char in Binary): " << ((unsigned int)NumColorMaps) << endl;
out << "NumSpecularMap (is unsigned char in Binary): " << ((unsigned int)NumSpecularMaps) << endl;
out << "NumNormalMap (is unsigned char in Binary): " << ((unsigned int)NumNormalMaps) << endl;
out << "NumIncandescenceMap (is unsigned char in Binary): " << ((unsigned int)NumIncandescenceMaps )<< endl;
if (NumSpecularMap > 0) out << "ColorMaps _ not in binary " << endl;
out << "NumSpecularMap: " << NumSpecularMap << endl; for (auto aTexture : ColorMaps) {
aTexture.WriteASCII(out);
}
if (NumNormalMap > 0) out << "SpecularMaps _ not in binary " << endl;
out << "NumNormalMap: " << NumNormalMap << endl; for (auto aTexture : SpecularMaps) {
aTexture.WriteASCII(out);
}
if (NumIncandescenceMap > 0) out << "NormalMaps _ not in binary " << endl;
out << "NumIncandescenceMap: " << NumIncandescenceMap << endl; for (auto aTexture : NormalMaps) {
aTexture.WriteASCII(out);
}
out << "ColorMaps _ not in binary " << endl; out << "IncandescenceMaps _ not in binary " << endl;
for (auto aTexture : ColorMaps) { for (auto aTexture : IncandescenceMaps) {
aTexture.WriteASCII(out); aTexture.WriteASCII(out);
} }
break;
out << "SpecularMaps _ not in binary " << endl; };
for (auto aTexture : SpecularMaps) {
aTexture.WriteASCII(out);
}
out << "NormalMaps _ not in binary " << endl;
for (auto aTexture : NormalMaps) {
aTexture.WriteASCII(out);
}
out << "IncandescenceMaps _ not in binary " << endl;
for (auto aTexture : IncandescenceMaps) {
aTexture.WriteASCII(out);
}
} }
}; };
@@ -158,7 +189,7 @@ private:
bool findNormalTexture(MaterialNode& material_node, MFnDependencyNode& node); bool findNormalTexture(MaterialNode& material_node, MFnDependencyNode& node);
bool findSpecularTexture(MaterialNode& material_node, MFnDependencyNode& node); bool findSpecularTexture(MaterialNode& material_node, MFnDependencyNode& node);
bool findIncandescenceTexture(MaterialNode& material_node, MFnDependencyNode& node); bool findIncandescenceTexture(MaterialNode& material_node, MFnDependencyNode& node);
bool findSplatTextures(std::vector<MaterialNode::Texture>& textureVector, MFnDependencyNode& node); bool findSplatTextures(MaterialNode& material_node, std::vector<MaterialNode::Texture>& textureVector, MFnDependencyNode& node);
void grabLambertProperties(MaterialNode& material_node, MFnDependencyNode& node); void grabLambertProperties(MaterialNode& material_node, MFnDependencyNode& node);
void grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node); void grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node);
void grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node); void grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node);
+86 -86
View File
@@ -8,91 +8,91 @@ MeshClass::MeshClass()
} }
std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData() //std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData()
{ //{
MS status; // MS status;
map<int, WeightInfo> weightMap; // map<int, WeightInfo> weightMap;
//
MItDependencyNodes it(MFn::kSkinClusterFilter); // MItDependencyNodes it(MFn::kSkinClusterFilter);
//
while (!it.isDone()) { // while (!it.isDone()) {
//
MObject object = it.thisNode(&status); // MObject object = it.thisNode(&status);
if (status != MS::kSuccess) { // if (status != MS::kSuccess) {
MGlobal::displayError(MString() + " it.thisNode() ERROR: " + status.errorString()); // MGlobal::displayError(MString() + " it.thisNode() ERROR: " + status.errorString());
break; // break;
} // }
MFnSkinCluster skinCluster(object, &status); // MFnSkinCluster skinCluster(object, &status);
if (status != MS::kSuccess) { // if (status != MS::kSuccess) {
MGlobal::displayError(MString() + "skinCluster() ERROR: " + status.errorString()); // MGlobal::displayError(MString() + "skinCluster() ERROR: " + status.errorString());
break; // break;
} // }
MDagPathArray influences; // MDagPathArray influences;
//
unsigned int nrOfInfluences = skinCluster.influenceObjects(influences,&status); // unsigned int nrOfInfluences = skinCluster.influenceObjects(influences,&status);
if (status != MS::kSuccess) { // if (status != MS::kSuccess) {
MGlobal::displayError(MString() + "skinCluster.influenceObjects() ERROR: " + status.errorString()); // MGlobal::displayError(MString() + "skinCluster.influenceObjects() ERROR: " + status.errorString());
break; // break;
} // }
//
unsigned int index; // unsigned int index;
index = skinCluster.indexForOutputConnection(0,&status); // index = skinCluster.indexForOutputConnection(0,&status);
if (status != MS::kSuccess) { // if (status != MS::kSuccess) {
MGlobal::displayError(MString() + "skinCluster.indexForOutputConnection() ERROR: " + status.errorString()); // MGlobal::displayError(MString() + "skinCluster.indexForOutputConnection() ERROR: " + status.errorString());
break; // break;
} // }
MDagPath skinPath; // MDagPath skinPath;
status = skinCluster.getPathAtIndex(index, skinPath); // status = skinCluster.getPathAtIndex(index, skinPath);
if (status != MS::kSuccess) { // if (status != MS::kSuccess) {
MGlobal::displayError(MString() + "skinCluster.getPathAtIndex() ERROR: " + status.errorString()); // MGlobal::displayError(MString() + "skinCluster.getPathAtIndex() ERROR: " + status.errorString());
break; // break;
} // }
//
MItGeometry geomIter(skinPath); // MItGeometry geomIter(skinPath);
//for (unsigned int i = 0; i < nrOfInfluences; i++) { // //for (unsigned int i = 0; i < nrOfInfluences; i++) {
// MGlobal::displayInfo(MString() + " Influence object name: " + influences[i].partialPathName().asChar()); // // MGlobal::displayInfo(MString() + " Influence object name: " + influences[i].partialPathName().asChar());
//} // //}
WeightInfo weightInfo; // WeightInfo weightInfo;
//
while (!geomIter.isDone()) { // while (!geomIter.isDone()) {
MObject comp = geomIter.component(&status); // MObject comp = geomIter.component(&status);
if (status != MS::kSuccess) { // if (status != MS::kSuccess) {
MGlobal::displayError(MString() + "geomIter.component() ERROR: " + status.errorString()); // MGlobal::displayError(MString() + "geomIter.component() ERROR: " + status.errorString());
break; // break;
} // }
MFloatArray weights; // MFloatArray weights;
unsigned int influenceCount; // unsigned int influenceCount;
status = skinCluster.getWeights(skinPath, comp, weights, influenceCount); // status = skinCluster.getWeights(skinPath, comp, weights, influenceCount);
if (status != MS::kSuccess) { // if (status != MS::kSuccess) {
MGlobal::displayError(MString() + "skinCluster.getWeights() ERROR: " + status.errorString()); // MGlobal::displayError(MString() + "skinCluster.getWeights() ERROR: " + status.errorString());
break; // break;
} // }
MFnDependencyNode test(comp); // MFnDependencyNode test(comp);
unsigned int nrOfWeights = 0; // unsigned int nrOfWeights = 0;
//
for (unsigned int j = 0; j < weights.length() && nrOfWeights != 4; j++) { // for (unsigned int j = 0; j < weights.length() && nrOfWeights != 4; j++) {
if (weights[j] > 0.00001) { // if (weights[j] > 0.00001) {
weightInfo.BoneWeights[nrOfWeights] = weights[j]; // weightInfo.BoneWeights[nrOfWeights] = weights[j];
weightInfo.BoneIndices[nrOfWeights] = j; // weightInfo.BoneIndices[nrOfWeights] = j;
nrOfWeights++; // nrOfWeights++;
} // }
} // }
//
float totalWeight = 0.0f; // float totalWeight = 0.0f;
for (unsigned int i = 0; i < 4; i++) { // for (unsigned int i = 0; i < 4; i++) {
totalWeight += weightInfo.BoneWeights[i]; // totalWeight += weightInfo.BoneWeights[i];
} // }
for (unsigned int i = 0; i < 4; i++) { // for (unsigned int i = 0; i < 4; i++) {
weightInfo.BoneWeights[i] /= totalWeight; // weightInfo.BoneWeights[i] /= totalWeight;
} // }
weightMap[geomIter.index()] = weightInfo; // weightMap[geomIter.index()] = weightInfo;
//
geomIter.next(); // geomIter.next();
} // }
it.next(); // it.next();
} // }
return weightMap; // return weightMap;
} //}
Mesh MeshClass::GetMeshData(MObjectArray object) Mesh MeshClass::GetMeshData(MObjectArray object)
{ {
@@ -317,7 +317,7 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
} }
for (unsigned int i = 0; i < 4; i++) { for (unsigned int i = 0; i < 4; i++) {
thisVertex.BoneWeights[i] = thisVertex.BoneWeights[i] / totalWeight; //thisVertex.BoneWeights[i] = thisVertex.BoneWeights[i] / totalWeight;
} }
} else { } else {
thisVertex.useWeights = false; thisVertex.useWeights = false;
+1 -1
View File
@@ -62,7 +62,7 @@ public:
class Mesh : public OutputData { class Mesh : public OutputData {
public: public:
bool hasSkin = false; bool hasSkin = true; //Should be false by default... Have it true now since pipeline only support skinned vertecies
unsigned int NumVertices; unsigned int NumVertices;
unsigned int NumIndices; unsigned int NumIndices;
std::vector<VertexLayout> Vertices; std::vector<VertexLayout> Vertices;
+11 -13
View File
@@ -230,7 +230,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
MTime time = MAnimControl::currentTime(); MTime time = MAnimControl::currentTime();
MFnTransform thisJoint(jointIt.currentItem()); MFnTransform thisJoint(jointIt.currentItem());
MTransformationMatrix TransformationMatrix = thisJoint.transformationMatrix(); MTransformationMatrix transformationMatrix = thisJoint.transformationMatrix();
double doubleMat[4][4]; double doubleMat[4][4];
@@ -256,7 +256,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
MMatrix LastJointMatrix(doubleMat); MMatrix LastJointMatrix(doubleMat);
//Is same as last KeyFrame //Is same as last KeyFrame
if (LastJointMatrix.isEquivalent(transformationMatrix)) { if (LastJointMatrix.isEquivalent(transformationMatrix.asMatrix())) {
//jointID++; //jointID++;
//jointIt.next(); //jointIt.next();
currentFrame++; currentFrame++;
@@ -264,7 +264,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
continue; continue;
} else if(!haxBool){ } else if(!haxBool){
haxBool = true; haxBool = true;
MTransformationMatrix TransformationMatrix = LastJointMatrix; MTransformationMatrix LastJointTransformationMatrix = LastJointMatrix;
MObject jointOrientObj = thisJoint.attribute("jointOrient"); MObject jointOrientObj = thisJoint.attribute("jointOrient");
MFnNumericAttribute jointOrient(jointOrientObj); MFnNumericAttribute jointOrient(jointOrientObj);
double jointOrientDouble[3]; double jointOrientDouble[3];
@@ -279,7 +279,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
MQuaternion jo = joEuler.asQuaternion(); MQuaternion jo = joEuler.asQuaternion();
double tmp[4]; double tmp[4];
TransformationMatrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]); LastJointTransformationMatrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
MQuaternion rotation(tmp); MQuaternion rotation(tmp);
rotation = rotation * jo; rotation = rotation * jo;
@@ -294,11 +294,11 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
previousKeyFrame.Rotation[1] = tmp[1]; previousKeyFrame.Rotation[1] = tmp[1];
previousKeyFrame.Rotation[2] = tmp[2]; previousKeyFrame.Rotation[2] = tmp[2];
previousKeyFrame.Rotation[3] = tmp[3]; previousKeyFrame.Rotation[3] = tmp[3];
TransformationMatrix.getTranslation(MSpace::kTransform).get(tmp); LastJointTransformationMatrix.getTranslation(MSpace::kTransform).get(tmp);
previousKeyFrame.Position[0] = tmp[0]; previousKeyFrame.Position[0] = tmp[0];
previousKeyFrame.Position[1] = tmp[1]; previousKeyFrame.Position[1] = tmp[1];
previousKeyFrame.Position[2] = tmp[2]; previousKeyFrame.Position[2] = tmp[2];
TransformationMatrix.getScale(tmp, MSpace::kTransform); LastJointTransformationMatrix.getScale(tmp, MSpace::kTransform);
previousKeyFrame.Scale[0] = tmp[0]; previousKeyFrame.Scale[0] = tmp[0];
previousKeyFrame.Scale[1] = tmp[1]; previousKeyFrame.Scale[1] = tmp[1];
previousKeyFrame.Scale[2] = tmp[2]; previousKeyFrame.Scale[2] = tmp[2];
@@ -307,7 +307,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
} }
} }
transformationMatrix.get(doubleMat); transformationMatrix.asMatrix().get(doubleMat);
//Save transformationMatrix to joinCheckMap //Save transformationMatrix to joinCheckMap
joinCheckMap[thisJoint.name().asChar()][0][0] = doubleMat[0][0]; joinCheckMap[thisJoint.name().asChar()][0][0] = doubleMat[0][0];
@@ -327,8 +327,6 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
joinCheckMap[thisJoint.name().asChar()][3][2] = doubleMat[3][2]; joinCheckMap[thisJoint.name().asChar()][3][2] = doubleMat[3][2];
joinCheckMap[thisJoint.name().asChar()][3][3] = doubleMat[3][3]; joinCheckMap[thisJoint.name().asChar()][3][3] = doubleMat[3][3];
MTransformationMatrix TransformationMatrix = thisJoint.transformation();
if (currentFrame == startFrame) { if (currentFrame == startFrame) {
MPlug thisJointBindPose = thisJoint.findPlug("bindPose"); MPlug thisJointBindPose = thisJoint.findPlug("bindPose");
MDataHandle DataHandle; MDataHandle DataHandle;
@@ -348,7 +346,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
thisJointBindPoseMatrix = thisJointBindPoseMatrix * parentBindPoseMatrix.inverse(); thisJointBindPoseMatrix = thisJointBindPoseMatrix * parentBindPoseMatrix.inverse();
} }
if (thisJointBindPoseMatrix.isEquivalent(TransformationMatrix.asMatrix())) { if (thisJointBindPoseMatrix.isEquivalent(transformationMatrix.asMatrix())) {
//jointID++; //jointID++;
//jointIt.next(); //jointIt.next();
currentFrame++; currentFrame++;
@@ -372,7 +370,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
MQuaternion jo = joEuler.asQuaternion(); MQuaternion jo = joEuler.asQuaternion();
double tmp[4]; double tmp[4];
TransformationMatrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]); transformationMatrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
MQuaternion rotation(tmp); MQuaternion rotation(tmp);
rotation = rotation * jo; rotation = rotation * jo;
@@ -386,11 +384,11 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
thisKeyFrame.Rotation[1] = tmp[1]; thisKeyFrame.Rotation[1] = tmp[1];
thisKeyFrame.Rotation[2] = tmp[2]; thisKeyFrame.Rotation[2] = tmp[2];
thisKeyFrame.Rotation[3] = tmp[3]; thisKeyFrame.Rotation[3] = tmp[3];
TransformationMatrix.getTranslation(MSpace::kTransform).get(tmp); transformationMatrix.getTranslation(MSpace::kTransform).get(tmp);
thisKeyFrame.Position[0] = tmp[0]; thisKeyFrame.Position[0] = tmp[0];
thisKeyFrame.Position[1] = tmp[1]; thisKeyFrame.Position[1] = tmp[1];
thisKeyFrame.Position[2] = tmp[2]; thisKeyFrame.Position[2] = tmp[2];
TransformationMatrix.getScale(tmp, MSpace::kTransform); transformationMatrix.getScale(tmp, MSpace::kTransform);
thisKeyFrame.Scale[0] = tmp[0]; thisKeyFrame.Scale[0] = tmp[0];
thisKeyFrame.Scale[1] = tmp[1]; thisKeyFrame.Scale[1] = tmp[1];
thisKeyFrame.Scale[2] = tmp[2]; thisKeyFrame.Scale[2] = tmp[2];