Skip to content
Snippets Groups Projects
Commit b9cecd05 authored by ansgar's avatar ansgar
Browse files

added scene fx normal map dump

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/branches/new_gfx@2149 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 0efd3a5e
No related branches found
No related tags found
No related merge requests found
...@@ -246,6 +246,8 @@ if (USE_SHADER) ...@@ -246,6 +246,8 @@ if (USE_SHADER)
shader/convolute1_fs.glsl shader/convolute1_fs.glsl
shader/scenefx_vs.glsl shader/scenefx_vs.glsl
shader/scenefx_fs.glsl shader/scenefx_fs.glsl
shader/dumpnorm_vs.glsl
shader/dumpnorm_fs.glsl
) )
copy_if_different("./" "${SHARED_DATA_PATH}/shader" "${SHADER_FILES}" copy_if_different("./" "${SHARED_DATA_PATH}/shader" "${SHADER_FILES}"
"SHADER_TARGETS" ost_gfx) "SHADER_TARGETS" ost_gfx)
......
...@@ -220,9 +220,12 @@ void CPKRenderer::RenderCPK2() ...@@ -220,9 +220,12 @@ void CPKRenderer::RenderCPK2()
aelist = CPKOcclusion(); aelist = CPKOcclusion();
} }
uint write_normals = Shader::Instance().GetCurrentName()=="dumpnorm" ? 1 : 0;
Shader::Instance().PushProgram(); Shader::Instance().PushProgram();
Shader::Instance().Activate("fast_sphere"); Shader::Instance().Activate("fast_sphere");
Shader::Instance().UpdateState(); Shader::Instance().UpdateState();
glUniform1i(glGetUniformLocation(Shader::Instance().GetCurrentProgram(),"write_normals"),write_normals);
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
......
...@@ -37,6 +37,8 @@ SceneFX::~SceneFX() ...@@ -37,6 +37,8 @@ SceneFX::~SceneFX()
void SceneFX::Setup() void SceneFX::Setup()
{ {
LOGN_VERBOSE("SceneFX: setup");
glGenTextures(1,&scene_tex_id_); glGenTextures(1,&scene_tex_id_);
glGenTextures(1,&depth_tex_id_); glGenTextures(1,&depth_tex_id_);
glGenTextures(1,&shadow_tex_id_); glGenTextures(1,&shadow_tex_id_);
...@@ -91,6 +93,7 @@ void SceneFX::Setup() ...@@ -91,6 +93,7 @@ void SceneFX::Setup()
void SceneFX::Resize(unsigned int w, unsigned int h) void SceneFX::Resize(unsigned int w, unsigned int h)
{ {
#if 0
glBindTexture(GL_TEXTURE_2D, scene_tex2_id_); glBindTexture(GL_TEXTURE_2D, scene_tex2_id_);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, norm_tex2_id_); glBindTexture(GL_TEXTURE_2D, norm_tex2_id_);
...@@ -109,13 +112,14 @@ void SceneFX::Resize(unsigned int w, unsigned int h) ...@@ -109,13 +112,14 @@ void SceneFX::Resize(unsigned int w, unsigned int h)
if(status!=GL_FRAMEBUFFER_COMPLETE) { if(status!=GL_FRAMEBUFFER_COMPLETE) {
use_fb_=false; use_fb_=false;
LOGN_VERBOSE("framebuffer error code " << status); LOGN_VERBOSE("SceneFX: framebuffer error code " << status);
} else { } else {
use_fb_=true; use_fb_=true;
} }
glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif
} }
void SceneFX::Preprocess() void SceneFX::Preprocess()
...@@ -128,23 +132,36 @@ void SceneFX::Preprocess() ...@@ -128,23 +132,36 @@ void SceneFX::Preprocess()
void SceneFX::Postprocess() void SceneFX::Postprocess()
{ {
Viewport vp=Scene::Instance().GetViewport(); Viewport vp=Scene::Instance().GetViewport();
// grab color buffer
glBindTexture(GL_TEXTURE_2D, scene_tex_id_);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, vp.x, vp.y, vp.width, vp.height, 0);
// and depth buffer
glBindTexture(GL_TEXTURE_2D, depth_tex_id_);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, vp.x, vp.y, vp.width, vp.height, 0);
if(use_fb_) { if(use_fb_) {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
} else {
// grab color buffer
glBindTexture(GL_TEXTURE_2D, scene_tex_id_);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, vp.x, vp.y, vp.width, vp.height, 0);
// and depth buffer
glBindTexture(GL_TEXTURE_2D, depth_tex_id_);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, vp.x, vp.y, vp.width, vp.height, 0);
if(amb_occl_flag) {
// now for the normal buffer hack if the framebuffer stuff failed
Shader::Instance().PushProgram();
Shader::Instance().Activate("dumpnorm");
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Scene::Instance().GetRootNode()->RenderGL(STANDARD_RENDER_PASS);
Shader::Instance().PopProgram();
glBindTexture(GL_TEXTURE_2D, norm_tex_id_);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, vp.x, vp.y, vp.width, vp.height, 0);
}
} }
if(shadow_flag) { if(shadow_flag) {
prep_shadow_map(); prep_shadow_map();
} }
if(amb_occl_flag) { if(amb_occl_flag) {
//prep_amb_occlusion(); prep_amb_occlusion();
//draw_debug_tex(vp.width,vp.height,norm_tex_id_); draw_debug_tex(vp.width,vp.height,occl_tex_id_);
return;
} }
if(depth_dark_flag) { if(depth_dark_flag) {
//prep_depth_darkening(); //prep_depth_darkening();
...@@ -272,7 +289,6 @@ void SceneFX::prep_amb_occlusion() ...@@ -272,7 +289,6 @@ void SceneFX::prep_amb_occlusion()
{ {
Viewport vp=Scene::Instance().GetViewport(); Viewport vp=Scene::Instance().GetViewport();
// kernel is static for now, inside the convolution shader
Shader::Instance().PushProgram(); Shader::Instance().PushProgram();
Shader::Instance().Activate("amboccl"); Shader::Instance().Activate("amboccl");
GLuint cpr=Shader::Instance().GetCurrentProgram(); GLuint cpr=Shader::Instance().GetCurrentProgram();
...@@ -287,9 +303,9 @@ void SceneFX::prep_amb_occlusion() ...@@ -287,9 +303,9 @@ void SceneFX::prep_amb_occlusion()
// set up viewport filling quad to run the fragment shader // set up viewport filling quad to run the fragment shader
draw_screen_quad(vp.width,vp.height); draw_screen_quad(vp.width,vp.height);
glActiveTexture(GL_TEXTURE3); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, occl_tex_id_); glBindTexture(GL_TEXTURE_2D, occl_tex_id_);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, 0,0, vp.width, vp.height, 0); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0,0, vp.width, vp.height, 0);
Shader::Instance().PopProgram(); Shader::Instance().PopProgram();
} }
......
...@@ -148,6 +148,8 @@ void Shader::Setup() ...@@ -148,6 +148,8 @@ void Shader::Setup()
{"fast_sphere_vs.glsl", GL_VERTEX_SHADER}, {"fast_sphere_vs.glsl", GL_VERTEX_SHADER},
{"fast_sphere_fs.glsl", GL_FRAGMENT_SHADER}, {"fast_sphere_fs.glsl", GL_FRAGMENT_SHADER},
{"outline_vs.glsl", GL_VERTEX_SHADER}, {"outline_vs.glsl", GL_VERTEX_SHADER},
{"dumpnorm_vs.glsl", GL_VERTEX_SHADER},
{"dumpnorm_fs.glsl", GL_FRAGMENT_SHADER},
{"quadpp_vs.glsl", GL_VERTEX_SHADER}, {"quadpp_vs.glsl", GL_VERTEX_SHADER},
{"convolute1_fs.glsl", GL_FRAGMENT_SHADER}, {"convolute1_fs.glsl", GL_FRAGMENT_SHADER},
{"amboccl_fs.glsl", GL_FRAGMENT_SHADER}, {"amboccl_fs.glsl", GL_FRAGMENT_SHADER},
...@@ -253,6 +255,13 @@ void Shader::Setup() ...@@ -253,6 +255,13 @@ void Shader::Setup()
if(link_shader(shader_program_list,"outline",shader_program_id)) { if(link_shader(shader_program_list,"outline",shader_program_id)) {
shader_program_map_["outline"]=shader_program_id; shader_program_map_["outline"]=shader_program_id;
} }
// dumpnorm shader
shader_program_list.clear();
shader_program_list.push_back(shader_code_map_["dumpnorm_vs.glsl"]);
shader_program_list.push_back(shader_code_map_["dumpnorm_fs.glsl"]);
if(link_shader(shader_program_list,"dumpnorm",shader_program_id)) {
shader_program_map_["dumpnorm"]=shader_program_id;
}
// convolute1 shader // convolute1 shader
shader_program_list.clear(); shader_program_list.clear();
shader_program_list.push_back(shader_code_map_["quadpp_vs.glsl"]); shader_program_list.push_back(shader_code_map_["quadpp_vs.glsl"]);
......
...@@ -4,6 +4,6 @@ uniform sampler2D norm; ...@@ -4,6 +4,6 @@ uniform sampler2D norm;
void main() void main()
{ {
float val = texture2D(depth,gl_TexCoord[0].xy).r; float val = texture2D(depth,gl_TexCoord[0].xy).r;
gl_FragColor.rgb=1.0; gl_FragColor.rgb=vec3(val,val,val);
gl_FragColor.a=1.0; gl_FragColor.a=1.0;
} }
...@@ -5,6 +5,6 @@ void main() ...@@ -5,6 +5,6 @@ void main()
float fog = fog_flag ? clamp((gl_Fog.end-gl_FogFragCoord) * gl_Fog.scale, 0.0, 1.0) : 1.0; float fog = fog_flag ? clamp((gl_Fog.end-gl_FogFragCoord) * gl_Fog.scale, 0.0, 1.0) : 1.0;
gl_FragColor.rgb = mix(gl_Fog.color.rgb, gl_Color.rgb, fog); gl_FragColor.rgb = mix(gl_Fog.color.rgb, gl_Color.rgb, fog);
gl_FragColor.a = gl_Color.a; gl_FragColor.a = gl_Color.a;
gl_FragBuffer[1].rgb=gl_TexCoord[0].stp*0.5+0.5; // gl_FragBuffer[1].rgb=gl_TexCoord[0].stp*0.5+0.5;
} }
void main()
{
gl_FragColor.rgb=normalize(gl_TexCoord[0]).stp*0.5+0.5;
}
void main()
{
gl_Position = ftransform();
vec3 normal = gl_NormalMatrix * gl_Normal;
gl_TexCoord[0].stp=normal;
}
uniform bool lighting_flag; uniform bool lighting_flag;
uniform bool two_sided_flag; uniform bool two_sided_flag;
uniform bool fog_flag; uniform bool fog_flag;
uniform bool write_normals;
// copy from basic_fl_vs ! // copy from basic_fl_vs !
bool DirectionalLight(in vec3 normal, bool DirectionalLight(in vec3 normal,
...@@ -32,6 +33,13 @@ void main() ...@@ -32,6 +33,13 @@ void main()
float z1 = gl_TexCoord[0].z*zz; float z1 = gl_TexCoord[0].z*zz;
float z2 = gl_TexCoord[0].w*zz; float z2 = gl_TexCoord[0].w*zz;
gl_FragDepth = gl_FragCoord.z+z2;
if(write_normals) {
gl_FragColor.rgb=normal*0.5+0.5;
return;
}
vec4 amb = vec4(0.0); vec4 amb = vec4(0.0);
vec4 diff = vec4(0.0); vec4 diff = vec4(0.0);
vec4 spec = vec4(0.0); vec4 spec = vec4(0.0);
...@@ -50,5 +58,4 @@ void main() ...@@ -50,5 +58,4 @@ void main()
gl_FragColor.rgb = color.rgb; gl_FragColor.rgb = color.rgb;
gl_FragColor.a = 1.0; gl_FragColor.a = 1.0;
gl_FragDepth = gl_FragCoord.z+z2;
} }
...@@ -81,5 +81,5 @@ void main() ...@@ -81,5 +81,5 @@ void main()
float fog = fog_flag ? clamp((gl_Fog.end-gl_FogFragCoord) * gl_Fog.scale, 0.0, 1.0) : 1.0; float fog = fog_flag ? clamp((gl_Fog.end-gl_FogFragCoord) * gl_Fog.scale, 0.0, 1.0) : 1.0;
gl_FragColor.rgb = mix(gl_Fog.color.rgb, gl_FragColor.rgb, fog); gl_FragColor.rgb = mix(gl_Fog.color.rgb, gl_FragColor.rgb, fog);
gl_FragColor.a = gl_Color.a; gl_FragColor.a = gl_Color.a;
gl_FragBuffer[1].rgb=gl_TexCoord[0].stp*0.5+0.5; //gl_FragBuffer[1].rgb=gl_TexCoord[0].stp*0.5+0.5;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment