[DEV] better file of material
This commit is contained in:
parent
fc598bd164
commit
e515e411fd
@ -12,7 +12,7 @@ struct DirectionalLight {
|
|||||||
|
|
||||||
struct Material {
|
struct Material {
|
||||||
vec4 ambientFactor; // color of the material with a reflection factor (0.2 for example) ==> light the back of the object
|
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
|
vec4 specularFactor; // Shining the Object with the light
|
||||||
float shininess;
|
float shininess;
|
||||||
};
|
};
|
||||||
@ -24,7 +24,23 @@ uniform Material EW_material;
|
|||||||
|
|
||||||
varying vec3 v_ecNormal;
|
varying vec3 v_ecNormal;
|
||||||
|
|
||||||
void main(void) {
|
#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;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// must work but it is full white
|
||||||
|
void main(void) {
|
||||||
// Normalize v_ecNormal
|
// Normalize v_ecNormal
|
||||||
vec3 ecNormal = normalize(v_ecNormal);
|
vec3 ecNormal = normalize(v_ecNormal);
|
||||||
|
|
||||||
@ -36,6 +52,7 @@ void main(void) {
|
|||||||
|
|
||||||
// Calculate diffuse light
|
// Calculate diffuse light
|
||||||
vec4 diffuseLight = ecNormalDotLightDirection * EW_directionalLight.diffuseColor * EW_material.diffuseFactor;
|
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);
|
//vec4 diffuseLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||||
|
|
||||||
// Calculate specular light
|
// Calculate specular light
|
||||||
@ -47,6 +64,10 @@ void main(void) {
|
|||||||
specularLight = EW_directionalLight.specularColor * EW_material.specularFactor;
|
specularLight = EW_directionalLight.specularColor * EW_material.specularFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// here, we have a white color
|
||||||
vec4 light = ambientLight + diffuseLight + specularLight;
|
vec4 light = ambientLight + diffuseLight + specularLight;
|
||||||
|
// here we have color
|
||||||
|
//vec4 light = diffuseLight;
|
||||||
gl_FragColor = light;
|
gl_FragColor = light;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@ -66,6 +66,23 @@ void ege::Material::draw(ememory::SharedPtr<gale::resource::Program> _prog, cons
|
|||||||
EGE_VERBOSE("draw Material: ( end )");
|
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) {
|
void ege::Material::setTexture0(const etk::String& _filename) {
|
||||||
ivec2 tmpSize(256, 256);
|
ivec2 tmpSize(256, 256);
|
||||||
if (_filename != "") {
|
if (_filename != "") {
|
||||||
@ -104,6 +121,9 @@ void ege::Material::setTexture0Magic(const ivec2& _size) {
|
|||||||
enum gale::openGL::renderMode ege::Material::getRenderModeOpenGl() {
|
enum gale::openGL::renderMode ege::Material::getRenderModeOpenGl() {
|
||||||
return m_renderMode;
|
return m_renderMode;
|
||||||
}
|
}
|
||||||
|
enum gale::openGL::renderMode ege::Material::getRenderMode() {
|
||||||
|
return m_renderMode;
|
||||||
|
}
|
||||||
|
|
||||||
void ege::Material::setRenderMode(enum gale::openGL::renderMode _val) {
|
void ege::Material::setRenderMode(enum gale::openGL::renderMode _val) {
|
||||||
switch (_val) {
|
switch (_val) {
|
||||||
@ -145,3 +165,24 @@ void ege::Material::setRenderMode(enum gale::openGL::renderMode _val) {
|
|||||||
m_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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <etk/math/Vector4D.hpp>
|
#include <etk/math/Vector4D.hpp>
|
||||||
#include <gale/resource/Program.hpp>
|
#include <gale/resource/Program.hpp>
|
||||||
#include <ewol/resource/TextureFile.hpp>
|
#include <ewol/resource/TextureFile.hpp>
|
||||||
|
#include <ege/debug.hpp>
|
||||||
|
|
||||||
namespace ege {
|
namespace ege {
|
||||||
/**
|
/**
|
||||||
@ -26,8 +27,6 @@ namespace ege {
|
|||||||
MaterialGlId();
|
MaterialGlId();
|
||||||
void link(ememory::SharedPtr<gale::resource::Program> _prog, const etk::String& _baseName);
|
void link(ememory::SharedPtr<gale::resource::Program> _prog, const etk::String& _baseName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Material {
|
class Material {
|
||||||
private:
|
private:
|
||||||
// values
|
// values
|
||||||
@ -35,7 +34,7 @@ namespace ege {
|
|||||||
vec4 m_diffuseFactor;
|
vec4 m_diffuseFactor;
|
||||||
vec4 m_specularFactor;
|
vec4 m_specularFactor;
|
||||||
float m_shininess;
|
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;
|
ememory::SharedPtr<ewol::resource::Texture> m_texture0;
|
||||||
public:
|
public:
|
||||||
etk::Vector<uint32_t> m_listIndexFaces;
|
etk::Vector<uint32_t> m_listIndexFaces;
|
||||||
@ -43,46 +42,20 @@ namespace ege {
|
|||||||
Material();
|
Material();
|
||||||
~Material();
|
~Material();
|
||||||
void draw(ememory::SharedPtr<gale::resource::Program> _prog, const ege::MaterialGlId& _glID);
|
void draw(ememory::SharedPtr<gale::resource::Program> _prog, const ege::MaterialGlId& _glID);
|
||||||
void setAmbientFactor(const vec4& _val) {
|
void setAmbientFactor(const vec4& _val);
|
||||||
m_ambientFactor = _val;
|
void setDiffuseFactor(const vec4& _val);
|
||||||
}
|
void setSpecularFactor(const vec4& _val);
|
||||||
void setDiffuseFactor(const vec4& _val) {
|
void setShininess(float _val);
|
||||||
m_diffuseFactor = _val;
|
|
||||||
}
|
|
||||||
void setSpecularFactor(const vec4& _val) {
|
|
||||||
m_specularFactor = _val;
|
|
||||||
}
|
|
||||||
void setShininess(float _val) {
|
|
||||||
m_shininess = _val;
|
|
||||||
}
|
|
||||||
void setRenderMode(enum gale::openGL::renderMode _val);
|
void setRenderMode(enum gale::openGL::renderMode _val);
|
||||||
enum gale::openGL::renderMode getRenderModeOpenGl();
|
enum gale::openGL::renderMode getRenderModeOpenGl();
|
||||||
enum gale::openGL::renderMode getRenderMode() {
|
enum gale::openGL::renderMode getRenderMode();
|
||||||
return m_renderMode;
|
|
||||||
}
|
|
||||||
void setTexture0(const etk::String& _filename);
|
void setTexture0(const etk::String& _filename);
|
||||||
void setTexture0Magic(const ivec2& _size);
|
void setTexture0Magic(const ivec2& _size);
|
||||||
|
void setImageSize(const ivec2& _newSize);
|
||||||
void setImageSize(const ivec2& _newSize) {
|
|
||||||
if (m_texture0 == nullptr){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_texture0->setImageSize(_newSize);
|
|
||||||
};
|
|
||||||
// get the reference on this image to draw nomething on it ...
|
// get the reference on this image to draw nomething on it ...
|
||||||
egami::Image* get() {
|
egami::Image* get();
|
||||||
if (m_texture0 == nullptr){
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return &m_texture0->get();
|
|
||||||
};
|
|
||||||
// flush the data to send it at the openGl system
|
// flush the data to send it at the openGl system
|
||||||
void flush() {
|
void flush();
|
||||||
if (m_texture0 == nullptr){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_texture0->flush();
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,10 +485,13 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
|
|||||||
float tmpVal1=0;
|
float tmpVal1=0;
|
||||||
float tmpVal2=0;
|
float tmpVal2=0;
|
||||||
float tmpVal3=0;
|
float tmpVal3=0;
|
||||||
|
EGE_ERROR("************************** DiffuseFactor '" << inputDataLine << "'");
|
||||||
|
EGE_ERROR("************************** DiffuseFactor '" << &inputDataLine[3] << "'");
|
||||||
|
|
||||||
sscanf(&inputDataLine[3], "%f %f %f", &tmpVal1, &tmpVal2, &tmpVal3);
|
sscanf(&inputDataLine[3], "%f %f %f", &tmpVal1, &tmpVal2, &tmpVal3);
|
||||||
vec4 tmp(tmpVal1, tmpVal2, tmpVal3, 1);
|
vec4 tmp(tmpVal1, tmpVal2, tmpVal3, 1);
|
||||||
material->setDiffuseFactor(tmp);
|
material->setDiffuseFactor(tmp);
|
||||||
EGE_VERBOSE(" DiffuseFactor " << tmp);
|
EGE_ERROR(" DiffuseFactor " << tmp);
|
||||||
} else if(strncmp(inputDataLine,"Ks ",3) == 0) {
|
} else if(strncmp(inputDataLine,"Ks ",3) == 0) {
|
||||||
float tmpVal1=0;
|
float tmpVal1=0;
|
||||||
float tmpVal2=0;
|
float tmpVal2=0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user