This commit is contained in:
Dmitri K 2016-11-10 15:36:22 -05:00
parent d1ed0a00dd
commit 89c2187f7f
6 changed files with 724 additions and 731 deletions

View File

@ -2,6 +2,7 @@
uniform vec3 lDirection;
uniform bool isSky;
uniform bool isPhong;
uniform bool isPickerColor;
uniform sampler2D tex;
uniform float skyMult;
@ -16,7 +17,10 @@ void
main()
{
vec4 texColor = texture(tex, texCoords);
if(isSky) {
if(isPickerColor){
fColor = ifColor;
} else if(isSky) {
fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2;
} else if(isPhong) {
// Get lighting vectors
@ -40,5 +44,5 @@ main()
//fColor = vec4(fNormal, 1);
} else {
fColor = texColor * ifColor;
}
}
}

View File

@ -8,6 +8,7 @@ uniform vec4 color;
uniform bool isSky;
uniform bool isPhong;
uniform bool isPickerColor;
in vec4 vPosition;
in vec3 vNormal;
@ -30,7 +31,7 @@ main()
ifColor = color;
if(!isPhong && !isSky) {
if(!isPickerColor && !isPhong && !isSky) {
// Get lighting vectors
vec3 LightDirection = normalize(lDirection);
vec3 nfNormal = normalize(fNormal);
@ -50,5 +51,6 @@ main()
ifColor = vec4(color * (0.1 + diffuse + specular), 1);
//ifColor = vec4(fNormal, 1);
}
}

View File

@ -9,7 +9,7 @@ in vec4 vPosition;
void
main()
{
gl_Position = projMatrix * mvMatrix * vPosition;
texCoords = vUv;
gl_Position = projMatrix * mvMatrix * vPosition;
texCoords = vUv;
}

View File

@ -1,15 +0,0 @@
#version 400 core
uniform mat4 mvMatrix;
uniform mat4 projMatrix;
out vec2 texCoords;
in vec2 vUv;
in vec4 vPosition;
void
main()
{
gl_Position = projMatrix * mvMatrix * vPosition;
texCoords = vUv;
}

View File

@ -300,10 +300,13 @@ void Viewer::initShaders()
qDebug() << "Unable to find m_shader location for" << "isPhong";
if ((m_lDirLoc = m_program->uniformLocation("lDirection")) < 0)
qDebug() << "Unable to find m_shader location for" << "lDirection";
qDebug() << "Unable to find m_shader location for" << "lDirection";
if ((m_skyMultLoc = m_program->uniformLocation("skyMult")) < 0)
qDebug() << "Unable to find m_shader location for" << "skyMult";
if ((m_skyMultLoc = m_program->uniformLocation("skyMult")) < 0)
qDebug() << "Unable to find m_shader location for" << "skyMult";
if ((m_pickerColor = m_program->uniformLocation("isPickerColor")) < 0)
qDebug() << "Unable to find m_shader location for" << "isPickerColor";
/*
@ -367,9 +370,9 @@ void Viewer::initGeometries()
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
//glEnable( GL_CULL_FACE );
//glEnable( GL_CULL_FACE );
glFrontFace( GL_CCW );
//glCullFace( GL_BACK );
//glCullFace( GL_BACK );
glClearColor(0.0,0.0,0.0,0.0);
// Create our VertexArrays Objects and VertexBuffer Objects
@ -478,8 +481,9 @@ void Viewer::visit(Cube &s)
int faces = floor(numVerticesCube/6);
for(int i = 0; i < faces; i++){ // 6 vertexes par face
glBindVertexArray(m_VAOs[VAO_Cube]);
m_program->setUniformValue(m_isSkyLoc, false);
m_program->setUniformValue(m_isPhongLoc, true);
m_program->setUniformValue(m_isSkyLoc, false);
m_program->setUniformValue(m_isPhongLoc, true);
m_program->setUniformValue(m_pickerColor, true);
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
m_program->setUniformValue(m_colorLocation, s.getColor());
@ -532,9 +536,8 @@ Shape* Viewer::pickGeom(int x, int y){
* Right now it's fine because we have simple Minecraft rules
* but could be important in the future
*/
QOpenGLShaderProgram *lastshader = m_program;
//colorPickerShaderProgram->bind();
m_program->setUniformValue(m_pickerColor, true);
std::cout << "Iterating through " << root.getChildren()->size() << "items"<<endl;
@ -559,21 +562,22 @@ Shape* Viewer::pickGeom(int x, int y){
}
}
root.accept(*this);
update();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// for debugging purposes
// for debugging purposes
/*QImage *im = new QImage(128,128, QImage::Format_RGB32);
for(int i = 0; i< 128; i++){
for(int j = 0; j< 128; j++){
glReadPixels(x-64+i, y+64-j, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]);
QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]);
if(i==64&&j==64) pickedColor->setRgba(0xFFFFFFFF);
im->setPixelColor(i, j, pickedColor->rgb());
}
}
im->save("./screenshot.bmp");//*/
}
im->save("./screenshot.bmp");//*/
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]);
@ -582,8 +586,5 @@ Shape* Viewer::pickGeom(int x, int y){
std::cout << "Picked Color: " << pickedColor->red() << " " << pickedColor->green() << " " << pickedColor->blue() << " " << pickedColor->alpha() << endl;
std::cout << "Picked Shape: " << pickedShape << endl;
//lastshader->bind();
return pickedShape;
}

View File

@ -97,7 +97,8 @@ private:
int m_isPhongLoc;
int m_isSkyLoc;
int m_lDirLoc;
int m_skyMultLoc;
int m_skyMultLoc;
bool m_pickerColor;
float angle_mult;