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 vec3 lDirection;
uniform bool isSky; uniform bool isSky;
uniform bool isPhong; uniform bool isPhong;
uniform bool isPickerColor;
uniform sampler2D tex; uniform sampler2D tex;
uniform float skyMult; uniform float skyMult;
@ -16,7 +17,10 @@ void
main() main()
{ {
vec4 texColor = texture(tex, texCoords); vec4 texColor = texture(tex, texCoords);
if(isSky) {
if(isPickerColor){
fColor = ifColor;
} else if(isSky) {
fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2; fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2;
} else if(isPhong) { } else if(isPhong) {
// Get lighting vectors // Get lighting vectors

View File

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

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

@ -305,6 +305,9 @@ void Viewer::initShaders()
if ((m_skyMultLoc = m_program->uniformLocation("skyMult")) < 0) if ((m_skyMultLoc = m_program->uniformLocation("skyMult")) < 0)
qDebug() << "Unable to find m_shader location for" << "skyMult"; 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";
/* /*
* Adding Texture Shader * Adding Texture Shader
@ -480,6 +483,7 @@ void Viewer::visit(Cube &s)
glBindVertexArray(m_VAOs[VAO_Cube]); glBindVertexArray(m_VAOs[VAO_Cube]);
m_program->setUniformValue(m_isSkyLoc, false); m_program->setUniformValue(m_isSkyLoc, false);
m_program->setUniformValue(m_isPhongLoc, true); m_program->setUniformValue(m_isPhongLoc, true);
m_program->setUniformValue(m_pickerColor, true);
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix()); m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
m_program->setUniformValue(m_colorLocation, s.getColor()); 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 * Right now it's fine because we have simple Minecraft rules
* but could be important in the future * 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; std::cout << "Iterating through " << root.getChildren()->size() << "items"<<endl;
@ -559,6 +562,7 @@ Shape* Viewer::pickGeom(int x, int y){
} }
} }
root.accept(*this);
update(); update();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@ -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 Color: " << pickedColor->red() << " " << pickedColor->green() << " " << pickedColor->blue() << " " << pickedColor->alpha() << endl;
std::cout << "Picked Shape: " << pickedShape << endl; std::cout << "Picked Shape: " << pickedShape << endl;
//lastshader->bind();
return pickedShape; return pickedShape;
} }

View File

@ -98,6 +98,7 @@ private:
int m_isSkyLoc; int m_isSkyLoc;
int m_lDirLoc; int m_lDirLoc;
int m_skyMultLoc; int m_skyMultLoc;
bool m_pickerColor;
float angle_mult; float angle_mult;