void rayCasting(void){ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, finalImage, 0); glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT ); // backFaceBuffer -> texture0 glActiveTexture( GL_TEXTURE0 ); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, backFaceBuffer); //gradientTexture -> texture1 glActiveTexture( GL_TEXTURE1 ); //glEnable(GL_TEXTURE_3D); glBindTexture(GL_TEXTURE_3D,gradientTexture3D); //TransferTexture -> texture2 glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_1D, TransferTexture); //intensityTexture -> texture3 glActiveTexture( GL_TEXTURE3 ); glBindTexture(GL_TEXTURE_3D,intensityTexture3D); glUseProgram(glslprogram); uniform1f( "stepSize", stepSize ); uniform1f( "viewWidth", WINDOW_WIDTH ); uniform1f( "viewHeight", WINDOW_HEIGHT ); uniform1i( "backFace", 0 ); // backFaceBuffer -> texture0 uniform1i( "gradientVol", 1 ); // gradientTexture -> texture2 uniform1i( "intensityVol", 3 ); uniform1i( "showGradient",showGradient); uniform1i( "TransferTexture",2); uniform1f( "edgeThresh", edgeThresh ); uniform1f( "edgeExp", edgeExp ); uniform1f( "DitherRay", DitherRay ); uniform1f( "boundExp", boundExp ); uniform3fv("clearColor",ClearColor[1],ClearColor[2],ClearColor[3]); uniform1f( "isRGBA", true); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glMatrixMode(GL_MODELVIEW); glScalef(1,1,1); drawQuads(1.0,1.0,1.0); glDisable(GL_CULL_FACE); glUseProgram(0); //glActiveTexture( GL_TEXTURE1 ); //glDisable(GL_TEXTURE_3D); glActiveTexture( GL_TEXTURE0 ); glDisable(GL_TEXTURE_2D); }
void app_update_and_render(App *app) { app->current_scene = (int)(app->elapsed_time / 20.0f) % NUM_SCENES; Scene scene = app->scenes[app->current_scene]; float model_scale = animate_model_scale(app->elapsed_time); float aspect_ratio = app->window_width / (float)app->window_height; mat4 mat_projection = perspective(scene.fov, aspect_ratio, scene.z_near, scene.z_far); mat4 mat_cube_model = rotateX(PI / 2.0f) * scale(model_scale); mat4 mat_view = animate_camera(app->elapsed_time); glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthRangef(0.0, 1.0); glClearDepthf(1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); //////////////// // Draw backdrop glDepthMask(GL_FALSE); glUseProgram(app->program_backdrop); glBindBuffer(GL_ARRAY_BUFFER, app->vbo_quad); attribfv(backdrop, position, 2, 0); uniform3fv(backdrop, sun_dir, scene.sun_dir); uniform2f(backdrop, screen_size, app->window_width, app->window_height); uniform1f(backdrop, inv_tan_fov, 1.0f / (scene.fov / 2.0f)); uniformm4(backdrop, view, mat_view); glDrawArrays(GL_TRIANGLES, 0, 6); glDepthMask(GL_TRUE); ////////////////////////// // Draw tessellated sphere glUseProgram(app->program_mapping); glBindBuffer(GL_ARRAY_BUFFER, app->vbo_cube); attribfv(mapping, position, 3, 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_CUBE_MAP, scene.heightmap); uniform1i(mapping, heightmap, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_CUBE_MAP, scene.diffusemap); uniform1i(mapping, diffusemap, 1); uniform1f(mapping, height_scale, scene.height_scale); uniform1f(mapping, use_mip, scene.use_mip ? 1.0f : 0.0f); uniform1f(mapping, max_lod_coverage, scene.max_lod_coverage); uniform2f(mapping, screen_size, app->window_width, app->window_height); uniformm4(mapping, model, mat_cube_model); uniformm4(mapping, view, mat_view); uniformm4(mapping, projection, mat_projection); glPatchParameteri(GL_PATCH_VERTICES, VERTICES_PER_PATCH); glDrawArrays(GL_PATCHES, 0, NUM_PATCHES * VERTICES_PER_PATCH); }
/*! SLGLShaderProg::beginUse starts using the shaderprogram and transfers the the standard light and material parameter as uniform variables. It also passes the custom uniform variables of the _uniform1fList as well as the texture names. */ void SLGLShaderProg::beginUse(SLMaterial* mat) { if (_programObjectGL==0 && _shaderList.size()>0) init(); if (_isLinked) { // 1: Activate the shader program object _stateGL->useProgram(_programObjectGL); // 2: Pass light & material parameters _stateGL->globalAmbientLight = SLScene::current->globalAmbiLight(); SLint loc = uniform4fv("u_globalAmbient", 1, (SLfloat*) _stateGL->globalAmbient()); loc = uniform1i("u_numLightsUsed", _stateGL->numLightsUsed); if (_stateGL->numLightsUsed > 0) { SLint nL = SL_MAX_LIGHTS; _stateGL->calcLightPosVS(_stateGL->numLightsUsed); _stateGL->calcLightDirVS(_stateGL->numLightsUsed); loc = uniform1iv("u_lightIsOn", nL, (SLint*) _stateGL->lightIsOn); loc = uniform4fv("u_lightPosVS", nL, (SLfloat*) _stateGL->lightPosVS); loc = uniform4fv("u_lightAmbient", nL, (SLfloat*) _stateGL->lightAmbient); loc = uniform4fv("u_lightDiffuse", nL, (SLfloat*) _stateGL->lightDiffuse); loc = uniform4fv("u_lightSpecular", nL, (SLfloat*) _stateGL->lightSpecular); loc = uniform3fv("u_lightDirVS", nL, (SLfloat*) _stateGL->lightDirVS); loc = uniform1fv("u_lightSpotCutoff",nL, (SLfloat*) _stateGL->lightSpotCutoff); loc = uniform1fv("u_lightSpotCosCut",nL, (SLfloat*) _stateGL->lightSpotCosCut); loc = uniform1fv("u_lightSpotExp", nL, (SLfloat*) _stateGL->lightSpotExp); loc = uniform3fv("u_lightAtt", nL, (SLfloat*) _stateGL->lightAtt); loc = uniform1iv("u_lightDoAtt", nL, (SLint*) _stateGL->lightDoAtt); loc = uniform4fv("u_matAmbient", 1, (SLfloat*)&_stateGL->matAmbient); loc = uniform4fv("u_matDiffuse", 1, (SLfloat*)&_stateGL->matDiffuse); loc = uniform4fv("u_matSpecular", 1, (SLfloat*)&_stateGL->matSpecular); loc = uniform4fv("u_matEmissive", 1, (SLfloat*)&_stateGL->matEmissive); loc = uniform1f ("u_matShininess", _stateGL->matShininess); } // 2b: Set stereo states loc = uniform1i ("u_projection", _stateGL->projection); loc = uniform1i ("u_stereoEye", _stateGL->stereoEye); loc = uniformMatrix3fv("u_stereoColorFilter", 1, (SLfloat*)&_stateGL->stereoColorFilter); // 3: Pass the custom uniform1f variables of the list for (SLuint i=0; i<_uniform1fList.size(); i++) { loc = uniform1f(_uniform1fList[i]->name(), _uniform1fList[i]->value()); } for (SLuint i=0; i<_uniform1iList.size(); i++) { loc = uniform1i(_uniform1iList[i]->name(), _uniform1iList[i]->value()); } // 4: Send texture units as uniforms texture samplers if (mat) { for (SLint i=0; i<(SLint)mat->textures().size(); ++i) { SLchar name[100]; sprintf(name,"u_texture%d", i); loc = uniform1i(name, i); } } GET_GL_ERROR; } }