added preview imange,

passed data to shader,
need to process data in shader
This commit is contained in:
Anakin 2017-02-05 20:10:05 +01:00
parent 30f1a1e627
commit 541a975624
3 changed files with 29 additions and 6 deletions

View File

@ -8,11 +8,13 @@ uniform mat3 n_matrix;
uniform vec3 cameraPosition;
uniform sampler2D texture;
uniform sampler2D secondTexture;
uniform float materialShininess;
uniform vec3 materialSpecularColor;
uniform bool b_transparent;
uniform bool b_specular;
uniform bool b_normalmap;
uniform bool b_light;
uniform struct Light {
@ -35,7 +37,15 @@ void main()
if(b_light)
{
// some values
vec3 normalWorld = normalize(n_matrix * v_surfaceNormal);
mat3 tbn = transpose(mat3(a_polyTan, a_polyBiTan, a_polyNorm));
vec3 finalNormal = normalize(n_matrix * v_surfaceNormal);
// if(b_normalmap)
// {
// finalNormal = texture2D(secondTexture, v_surfaceUV).rgb;
// finalNormal = normalize(finalNormal * 2.0 -1.0)
// }
vec4 surfaceColor = vec4(texture2D(texture, v_surfaceUV));
surfaceColor.rgb = pow(surfaceColor.rgb, vec3(2.2));
@ -62,13 +72,13 @@ void main()
vec3 ambient = light.ambientCoefficient * surfaceColor.rgb * light.intensities;
// diffuse
float diffuseCoefficient = max(0.0, dot(normalWorld, surfaceToLight));
float diffuseCoefficient = max(0.0, dot(finalNormal, surfaceToLight));
vec3 diffuse = diffuseCoefficient * surfaceColor.rgb * light.intensities;
// specular
float specularCoefficient = 0.0;
if(diffuseCoefficient > 0.0)
specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normalWorld))), materialShininess);
specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, finalNormal))), materialShininess);
vec3 specColor;
if(b_specular)
specColor = vec3(surfaceColor.a);

View File

@ -121,8 +121,9 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
normMatrix.translate(-m_boundings.center[0], -m_boundings.center[1], -m_boundings.center[2]);
program->setUniformValue("norm_matrix", normMatrix);
// Allways use texture unit 0
// Allways use texture unit 0 and 1
program->setUniformValue("texture", 0);
program->setUniformValue("secondTexture", 1);
//setup the pipeline
setupPipeline(program);
@ -133,23 +134,34 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
{
bool tmp_transparent(false);
bool tmp_specular(false);
bool tmp_normalmap(false);
float shininess(0.0);
QVector3D specularColor;
// bind the correct texture
if (it.textureIndex < (unsigned)m_materials->size() && m_materials->at(it.textureIndex).texture0 != Q_NULLPTR)
{
m_materials->at(it.textureIndex).texture0->bind();
m_materials->at(it.textureIndex).texture0->bind(0);
tmp_transparent = m_materials->at(it.textureIndex).transparent;
tmp_specular = m_materials->at(it.textureIndex).flags[7];
shininess = m_materials->at(it.textureIndex).shininess;
specularColor = m_materials->at(it.textureIndex).specularColor.toVector3D();
if (m_materials->at(it.textureIndex).rendertype == 27 || m_materials->at(it.textureIndex).rendertype == 28)
{
if (m_materials->at(it.textureIndex).texture1 != Q_NULLPTR)
{
tmp_normalmap = true;
m_materials->at(it.textureIndex).texture1->bind(1);
}
}
}
else
{
m_defaultMaterial->texture0->bind();
m_defaultMaterial->texture0->bind(0);
tmp_transparent = m_defaultMaterial->transparent;
}
// Set model matrix
program->setUniformValue("m_matrix", it.modelMatrix);
@ -159,6 +171,7 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
// set some more values
program->setUniformValue("b_transparent", tmp_transparent);
program->setUniformValue("b_specular", tmp_specular);
program->setUniformValue("b_normalmap", tmp_normalmap);
// set some material attributes
program->setUniformValue("materialShininess", shininess);

BIN
preview.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB