// Draw 3d stuff void TemplateGame::_draw3d() { glEnable( GL_TEXTURE_2D ); // Set up basic shader glUseProgram( m_basicShader ); GLint mvp = glGetUniformLocation( m_basicShader, "matrixPMV"); glUniformMatrix4fv( mvp, 1, 0, (GLfloat*)(&m_modelviewProj) ); glActiveTexture(GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, m_simpleTex.textureId ); GLint paramTex = glGetUniformLocation( m_basicShader, "sampler_dif0" ); glUniform1i( paramTex, 0 ); // Draw something _drawMesh( m_cube ); }
void GLWidget::paintGL() { ErrorChecker::printGLErrors("start of paintGL"); if (resetFromSceneEditorGroomingTexture != NULL && resetFromSceneEditorGrowthTexture != NULL){ applySceneEditor(resetFromSceneEditorGrowthTexture, resetFromSceneEditorGroomingTexture); resetFromSceneEditorGroomingTexture = NULL; resetFromSceneEditorGrowthTexture = NULL; } m_clock.restart(); _resizeDepthPeelFramebuffers(); // Update simulation if not paused. if (!isPaused()) { m_increment++; float time = m_increment / (float) m_targetFPS; // Time in seconds (assuming 60 FPS). m_testSimulation->update(time); m_hairObject->update(time); } // Update transformation matrices. glm::mat4 model = glm::mat4(1.f); model = m_testSimulation->m_xform; m_lightPosition = glm::vec3(2, 2, 2); glm::mat4 lightProjection = glm::perspective(1.3f, 1.f, .1f, 100.f); glm::mat4 lightView = glm::lookAt(m_lightPosition, glm::vec3(0), glm::vec3(0,1,0)); m_eyeToLight = lightProjection * lightView * glm::inverse(m_view); // Bind textures. m_noiseTexture->bind(GL_TEXTURE0); m_hairShadowFramebuffer->depthTexture->bind(GL_TEXTURE1); m_opacityMapFramebuffer->colorTexture->bind(GL_TEXTURE2); m_meshShadowFramebuffer->depthTexture->bind(GL_TEXTURE3); m_finalFramebuffer->colorTexture->bind(GL_TEXTURE4); m_hairObject->m_blurredHairGrowthMapTexture->bind(GL_TEXTURE5); m_depthPeel0Framebuffer->depthTexture->bind(GL_TEXTURE6); m_depthPeel0Framebuffer->colorTexture->bind(GL_TEXTURE7); m_depthPeel1Framebuffer->colorTexture->bind(GL_TEXTURE8); #if FEEDBACK int numTriangles = m_hairObject->m_guideHairs.size() // # guide hairs * m_hairObject->m_numGroupHairs // # hairs per guide hair * (m_hairObject->m_numSplineVertices-1) // # segments per hair * 2; // # triangles per segment m_tessellator->setNumTriangles(numTriangles); m_tessellator->beginTessellation(); _drawHair(m_tessellator->program, model, m_view, m_projection, false); m_tessellator->endTessellation(); #endif if (useShadows) { // Render hair shadow map. m_hairShadowFramebuffer->bind(); glViewport(0, 0, m_hairShadowFramebuffer->depthTexture->width(), m_hairShadowFramebuffer->depthTexture->height()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #if FEEDBACK _drawHairFromFeedback(m_TFwhiteHairProgram, model, lightView, lightProjection); #else _drawHair(m_whiteHairProgram, model, lightView, lightProjection); #endif // Render mesh shadow map. m_meshShadowFramebuffer->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); _drawMesh(m_whiteMeshProgram, model, lightView, lightProjection); // Enable additive blending for opacity map. glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); // Render opacity map. m_opacityMapFramebuffer->bind(); glViewport(0, 0, m_hairShadowFramebuffer->depthTexture->width(), m_hairShadowFramebuffer->depthTexture->height()); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #if FEEDBACK _drawHairFromFeedback(m_TFhairOpacityProgram, model, lightView, lightProjection); #else _drawHair(m_hairOpacityProgram, model, lightView, lightProjection); #endif // Restore previous state. m_opacityMapFramebuffer->unbind(); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); } if (useTransparency) { glViewport(0, 0, m_depthPeel0Framebuffer->colorTexture->width(), m_depthPeel0Framebuffer->colorTexture->height()); glClearColor(0.5f, 0.5f, 0.5f, 0.0f); // Draw first (front-most) depth peeling layer. m_depthPeel0Framebuffer->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #if FEEDBACK _drawHairFromFeedback(m_TFhairProgram, model, m_view, m_projection); #else _drawHair(m_hairProgram, model, m_view, m_projection); #endif _drawMesh(m_meshProgram, model, m_view, m_projection); // Draw second depth peeling layer. m_depthPeel1Framebuffer->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #if FEEDBACK _drawHairFromFeedback(m_TFhairDepthPeelProgram, model, m_view, m_projection); #else _drawHair(m_hairDepthPeelProgram, model, m_view, m_projection); #endif _drawMesh(m_meshDepthPeelProgram, model, m_view, m_projection); // Render farthest layer to screen. m_depthPeel1Framebuffer->unbind(); glViewport(0, 0, width(), height()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_DEPTH_TEST); m_depthPeel1Framebuffer->colorTexture->renderFullScreen(); // Blend closer layers on top. glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); m_depthPeel0Framebuffer->colorTexture->renderFullScreen(); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } else { if (useSupersampling) { // Render into supersample framebuffer. m_finalFramebuffer->bind(); glViewport(0, 0, m_finalFramebuffer->colorTexture->width(), m_finalFramebuffer->colorTexture->height()); } else { // Render into default framebuffer... glViewport(0, 0, width(), height()); } // Render scene. glClearColor(0.5f, 0.5f, 0.5f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #if FEEDBACK _drawHairFromFeedback(m_TFhairProgram, model, m_view, m_projection); #else _drawHair(m_hairProgram, model, m_view, m_projection); #endif _drawMesh(m_meshProgram, model, m_view, m_projection); if (useSupersampling) { // Render supersampled texture. m_finalFramebuffer->unbind(); glViewport(0, 0, width(), height()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_finalFramebuffer->colorTexture->renderFullScreen(); } } // Clean up. m_noiseTexture->unbind(GL_TEXTURE0); m_hairShadowFramebuffer->depthTexture->unbind(GL_TEXTURE1); m_opacityMapFramebuffer->colorTexture->unbind(GL_TEXTURE2); m_meshShadowFramebuffer->depthTexture->unbind(GL_TEXTURE3); m_finalFramebuffer->colorTexture->unbind(GL_TEXTURE4); m_hairObject->m_blurredHairGrowthMapTexture->unbind(GL_TEXTURE5); m_depthPeel0Framebuffer->depthTexture->bind(GL_TEXTURE6); m_depthPeel0Framebuffer->colorTexture->bind(GL_TEXTURE7); m_depthPeel1Framebuffer->colorTexture->bind(GL_TEXTURE8); // Update UI. m_hairInterface->updateFPSLabel(m_increment); if (m_paused || m_pausedLastFrame) { m_hairInterface->updateFPSLabelPaused(1000.0 / m_clock.elapsed()); } m_pausedLastFrame = isPaused(); }