added preview imange,
passed data to shader, need to process data in shader
This commit is contained in:
parent
30f1a1e627
commit
541a975624
|
@ -8,11 +8,13 @@ uniform mat3 n_matrix;
|
||||||
uniform vec3 cameraPosition;
|
uniform vec3 cameraPosition;
|
||||||
|
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
|
uniform sampler2D secondTexture;
|
||||||
uniform float materialShininess;
|
uniform float materialShininess;
|
||||||
uniform vec3 materialSpecularColor;
|
uniform vec3 materialSpecularColor;
|
||||||
|
|
||||||
uniform bool b_transparent;
|
uniform bool b_transparent;
|
||||||
uniform bool b_specular;
|
uniform bool b_specular;
|
||||||
|
uniform bool b_normalmap;
|
||||||
uniform bool b_light;
|
uniform bool b_light;
|
||||||
|
|
||||||
uniform struct Light {
|
uniform struct Light {
|
||||||
|
@ -35,7 +37,15 @@ void main()
|
||||||
if(b_light)
|
if(b_light)
|
||||||
{
|
{
|
||||||
// some values
|
// 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));
|
vec4 surfaceColor = vec4(texture2D(texture, v_surfaceUV));
|
||||||
surfaceColor.rgb = pow(surfaceColor.rgb, vec3(2.2));
|
surfaceColor.rgb = pow(surfaceColor.rgb, vec3(2.2));
|
||||||
|
@ -62,13 +72,13 @@ void main()
|
||||||
vec3 ambient = light.ambientCoefficient * surfaceColor.rgb * light.intensities;
|
vec3 ambient = light.ambientCoefficient * surfaceColor.rgb * light.intensities;
|
||||||
|
|
||||||
// diffuse
|
// diffuse
|
||||||
float diffuseCoefficient = max(0.0, dot(normalWorld, surfaceToLight));
|
float diffuseCoefficient = max(0.0, dot(finalNormal, surfaceToLight));
|
||||||
vec3 diffuse = diffuseCoefficient * surfaceColor.rgb * light.intensities;
|
vec3 diffuse = diffuseCoefficient * surfaceColor.rgb * light.intensities;
|
||||||
|
|
||||||
// specular
|
// specular
|
||||||
float specularCoefficient = 0.0;
|
float specularCoefficient = 0.0;
|
||||||
if(diffuseCoefficient > 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;
|
vec3 specColor;
|
||||||
if(b_specular)
|
if(b_specular)
|
||||||
specColor = vec3(surfaceColor.a);
|
specColor = vec3(surfaceColor.a);
|
||||||
|
|
|
@ -121,8 +121,9 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||||
normMatrix.translate(-m_boundings.center[0], -m_boundings.center[1], -m_boundings.center[2]);
|
normMatrix.translate(-m_boundings.center[0], -m_boundings.center[1], -m_boundings.center[2]);
|
||||||
program->setUniformValue("norm_matrix", normMatrix);
|
program->setUniformValue("norm_matrix", normMatrix);
|
||||||
|
|
||||||
// Allways use texture unit 0
|
// Allways use texture unit 0 and 1
|
||||||
program->setUniformValue("texture", 0);
|
program->setUniformValue("texture", 0);
|
||||||
|
program->setUniformValue("secondTexture", 1);
|
||||||
|
|
||||||
//setup the pipeline
|
//setup the pipeline
|
||||||
setupPipeline(program);
|
setupPipeline(program);
|
||||||
|
@ -133,23 +134,34 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||||
{
|
{
|
||||||
bool tmp_transparent(false);
|
bool tmp_transparent(false);
|
||||||
bool tmp_specular(false);
|
bool tmp_specular(false);
|
||||||
|
bool tmp_normalmap(false);
|
||||||
float shininess(0.0);
|
float shininess(0.0);
|
||||||
QVector3D specularColor;
|
QVector3D specularColor;
|
||||||
|
|
||||||
// bind the correct texture
|
// bind the correct texture
|
||||||
if (it.textureIndex < (unsigned)m_materials->size() && m_materials->at(it.textureIndex).texture0 != Q_NULLPTR)
|
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_transparent = m_materials->at(it.textureIndex).transparent;
|
||||||
tmp_specular = m_materials->at(it.textureIndex).flags[7];
|
tmp_specular = m_materials->at(it.textureIndex).flags[7];
|
||||||
shininess = m_materials->at(it.textureIndex).shininess;
|
shininess = m_materials->at(it.textureIndex).shininess;
|
||||||
specularColor = m_materials->at(it.textureIndex).specularColor.toVector3D();
|
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
|
else
|
||||||
{
|
{
|
||||||
m_defaultMaterial->texture0->bind();
|
m_defaultMaterial->texture0->bind(0);
|
||||||
tmp_transparent = m_defaultMaterial->transparent;
|
tmp_transparent = m_defaultMaterial->transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set model matrix
|
// Set model matrix
|
||||||
program->setUniformValue("m_matrix", it.modelMatrix);
|
program->setUniformValue("m_matrix", it.modelMatrix);
|
||||||
|
|
||||||
|
@ -159,6 +171,7 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||||
// set some more values
|
// set some more values
|
||||||
program->setUniformValue("b_transparent", tmp_transparent);
|
program->setUniformValue("b_transparent", tmp_transparent);
|
||||||
program->setUniformValue("b_specular", tmp_specular);
|
program->setUniformValue("b_specular", tmp_specular);
|
||||||
|
program->setUniformValue("b_normalmap", tmp_normalmap);
|
||||||
|
|
||||||
// set some material attributes
|
// set some material attributes
|
||||||
program->setUniformValue("materialShininess", shininess);
|
program->setUniformValue("materialShininess", shininess);
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 43 KiB |
Loading…
Reference in New Issue