[DEV] better file of material

This commit is contained in:
Edouard DUPIN 2018-05-04 23:01:45 +02:00
parent fc598bd164
commit e515e411fd
4 changed files with 102 additions and 64 deletions

View File

@ -12,7 +12,7 @@ struct DirectionalLight {
struct Material {
vec4 ambientFactor; // color of the material with a reflection factor (0.2 for example) ==> light the back of the object
vec4 diffuseFactor; // Direct exposition of the object by the light
vec4 diffuseFactor; // Direct exposition of the object by the light (object color)
vec4 specularFactor; // Shining the Object with the light
float shininess;
};
@ -24,29 +24,50 @@ uniform Material EW_material;
varying vec3 v_ecNormal;
void main(void) {
// Normalize v_ecNormal
vec3 ecNormal = normalize(v_ecNormal);
// Calculate ambient light
vec4 ambientLight = EW_directionalLight.ambientColor * EW_material.ambientFactor;
float ecNormalDotLightDirection = max(0.0, dot(ecNormal, EW_directionalLight.direction));
//float ecNormalDotLightDirection = (dot(ecNormal, EW_directionalLight.direction)+1.0) * 0.5;
// Calculate diffuse light
vec4 diffuseLight = ecNormalDotLightDirection * EW_directionalLight.diffuseColor * EW_material.diffuseFactor;
//vec4 diffuseLight = vec4(0.0, 0.0, 0.0, 0.0);
// Calculate specular light
vec4 specularLight = EW_directionalLight.specularColor * EW_material.specularFactor;
float ecNormalDotLightHalfplane = dot(ecNormal, EW_directionalLight.halfplane);
if (ecNormalDotLightHalfplane > 0.0) {
specularLight = pow(ecNormalDotLightHalfplane, EW_material.shininess) * EW_directionalLight.specularColor * EW_material.specularFactor;
specularLight = EW_directionalLight.specularColor * EW_material.specularFactor;
#if 1
// real basic version
void main(void) {
// Normalize v_ecNormal
vec3 ecNormal = normalize(v_ecNormal);
float ecNormalDotLightDirection = (dot(ecNormal, EW_directionalLight.direction)+1.0) * 0.5;
// Calculate diffuse light
vec4 diffuseLight = ecNormalDotLightDirection * EW_directionalLight.diffuseColor * EW_material.diffuseFactor;
vec4 light = diffuseLight;
gl_FragColor = light;
}
vec4 light = ambientLight + diffuseLight + specularLight;
gl_FragColor = light;
}
#else
// must work but it is full white
void main(void) {
// Normalize v_ecNormal
vec3 ecNormal = normalize(v_ecNormal);
// Calculate ambient light
vec4 ambientLight = EW_directionalLight.ambientColor * EW_material.ambientFactor;
float ecNormalDotLightDirection = max(0.0, dot(ecNormal, EW_directionalLight.direction));
//float ecNormalDotLightDirection = (dot(ecNormal, EW_directionalLight.direction)+1.0) * 0.5;
// Calculate diffuse light
vec4 diffuseLight = ecNormalDotLightDirection * EW_directionalLight.diffuseColor * EW_material.diffuseFactor;
//vec4 diffuseLight = EW_material.diffuseFactor;
//vec4 diffuseLight = vec4(0.0, 0.0, 0.0, 0.0);
// Calculate specular light
vec4 specularLight = EW_directionalLight.specularColor * EW_material.specularFactor;
float ecNormalDotLightHalfplane = dot(ecNormal, EW_directionalLight.halfplane);
if (ecNormalDotLightHalfplane > 0.0) {
specularLight = pow(ecNormalDotLightHalfplane, EW_material.shininess) * EW_directionalLight.specularColor * EW_material.specularFactor;
specularLight = EW_directionalLight.specularColor * EW_material.specularFactor;
}
// here, we have a white color
vec4 light = ambientLight + diffuseLight + specularLight;
// here we have color
//vec4 light = diffuseLight;
gl_FragColor = light;
}
#endif

View File

@ -66,6 +66,23 @@ void ege::Material::draw(ememory::SharedPtr<gale::resource::Program> _prog, cons
EGE_VERBOSE("draw Material: ( end )");
}
void ege::Material::setAmbientFactor(const vec4& _val) {
m_ambientFactor = _val;
}
void ege::Material::setDiffuseFactor(const vec4& _val) {
//EGE_ERROR("**************** set difuse factor:" << _val);
m_diffuseFactor = _val;
}
void ege::Material::setSpecularFactor(const vec4& _val) {
m_specularFactor = _val;
}
void ege::Material::setShininess(float _val) {
m_shininess = _val;
}
void ege::Material::setTexture0(const etk::String& _filename) {
ivec2 tmpSize(256, 256);
if (_filename != "") {
@ -104,6 +121,9 @@ void ege::Material::setTexture0Magic(const ivec2& _size) {
enum gale::openGL::renderMode ege::Material::getRenderModeOpenGl() {
return m_renderMode;
}
enum gale::openGL::renderMode ege::Material::getRenderMode() {
return m_renderMode;
}
void ege::Material::setRenderMode(enum gale::openGL::renderMode _val) {
switch (_val) {
@ -145,3 +165,24 @@ void ege::Material::setRenderMode(enum gale::openGL::renderMode _val) {
m_renderMode = _val;
}
void ege::Material::setImageSize(const ivec2& _newSize) {
if (m_texture0 == nullptr){
return;
}
m_texture0->setImageSize(_newSize);
}
egami::Image* ege::Material::get() {
if (m_texture0 == nullptr){
return nullptr;
}
return &m_texture0->get();
}
void ege::Material::flush() {
if (m_texture0 == nullptr){
return;
}
m_texture0->flush();
}

View File

@ -10,6 +10,7 @@
#include <etk/math/Vector4D.hpp>
#include <gale/resource/Program.hpp>
#include <ewol/resource/TextureFile.hpp>
#include <ege/debug.hpp>
namespace ege {
/**
@ -26,8 +27,6 @@ namespace ege {
MaterialGlId();
void link(ememory::SharedPtr<gale::resource::Program> _prog, const etk::String& _baseName);
};
class Material {
private:
// values
@ -35,7 +34,7 @@ namespace ege {
vec4 m_diffuseFactor;
vec4 m_specularFactor;
float m_shininess;
enum gale::openGL::renderMode m_renderMode; // Select Render mode (triangle/Line/point ...)
enum gale::openGL::renderMode m_renderMode; //!< Select Render mode (triangle/Line/point ...)
ememory::SharedPtr<ewol::resource::Texture> m_texture0;
public:
etk::Vector<uint32_t> m_listIndexFaces;
@ -43,46 +42,20 @@ namespace ege {
Material();
~Material();
void draw(ememory::SharedPtr<gale::resource::Program> _prog, const ege::MaterialGlId& _glID);
void setAmbientFactor(const vec4& _val) {
m_ambientFactor = _val;
}
void setDiffuseFactor(const vec4& _val) {
m_diffuseFactor = _val;
}
void setSpecularFactor(const vec4& _val) {
m_specularFactor = _val;
}
void setShininess(float _val) {
m_shininess = _val;
}
void setAmbientFactor(const vec4& _val);
void setDiffuseFactor(const vec4& _val);
void setSpecularFactor(const vec4& _val);
void setShininess(float _val);
void setRenderMode(enum gale::openGL::renderMode _val);
enum gale::openGL::renderMode getRenderModeOpenGl();
enum gale::openGL::renderMode getRenderMode() {
return m_renderMode;
}
enum gale::openGL::renderMode getRenderMode();
void setTexture0(const etk::String& _filename);
void setTexture0Magic(const ivec2& _size);
void setImageSize(const ivec2& _newSize) {
if (m_texture0 == nullptr){
return;
}
m_texture0->setImageSize(_newSize);
};
void setImageSize(const ivec2& _newSize);
// get the reference on this image to draw nomething on it ...
egami::Image* get() {
if (m_texture0 == nullptr){
return nullptr;
}
return &m_texture0->get();
};
egami::Image* get();
// flush the data to send it at the openGl system
void flush() {
if (m_texture0 == nullptr){
return;
}
m_texture0->flush();
};
void flush();
};
}

View File

@ -485,10 +485,13 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
float tmpVal1=0;
float tmpVal2=0;
float tmpVal3=0;
EGE_ERROR("************************** DiffuseFactor '" << inputDataLine << "'");
EGE_ERROR("************************** DiffuseFactor '" << &inputDataLine[3] << "'");
sscanf(&inputDataLine[3], "%f %f %f", &tmpVal1, &tmpVal2, &tmpVal3);
vec4 tmp(tmpVal1, tmpVal2, tmpVal3, 1);
material->setDiffuseFactor(tmp);
EGE_VERBOSE(" DiffuseFactor " << tmp);
EGE_ERROR(" DiffuseFactor " << tmp);
} else if(strncmp(inputDataLine,"Ks ",3) == 0) {
float tmpVal1=0;
float tmpVal2=0;