From 3cf466e5d363e2100fdb6882ca365ac1a9229d49 Mon Sep 17 00:00:00 2001 From: peri4 Date: Thu, 9 Feb 2023 17:21:59 +0300 Subject: [PATCH] shadows basically works --- shaders/ds_light.glsl | 29 ++++++- shaders/ds_tonemap.glsl | 1 + shaders/shadow.glsl | 24 ++++++ src/core/CMakeLists.txt | 2 +- src/core/core/glframebuffer.cpp | 6 +- src/core/core/glframebuffer.h | 3 +- src/core/core/glshaders_headers.h | 1 + src/core/core/glshaders_types.h | 15 ++-- src/core/core/gltexturearray.cpp | 5 +- src/core/core/gltexturearray.h | 4 +- src/core/core/parameteredobject.cpp | 1 + src/core/core/parameteredobject.h | 2 + src/core/render/renderer.cpp | 99 ++++++++++++++++++++---- src/core/render/renderer.h | 2 + src/core/render/renderer_base.cpp | 9 ++- src/core/scene/globject.cpp | 17 ++-- src/core/scene/globject.h | 10 --- src/core/{ => view}/glwidget.cpp | 15 ++-- src/core/{ => view}/glwidget.h | 4 +- src/core/{ => view}/mouse_controller.cpp | 10 +-- src/core/{ => view}/mouse_controller.h | 0 src/core/{ => view}/openglwindow.cpp | 5 ++ src/core/{ => view}/openglwindow.h | 1 + src/core/{ => view}/qglview.cpp | 69 +++++++---------- src/core/{ => view}/qglview.h | 58 ++++---------- src/qglview_test/qglview_window.cpp | 49 ++++++------ src/qglview_test/qglview_window.h | 50 ++++++------ src/qglview_test/qglview_window.ui | 2 +- src/widgets/view_editor.cpp | 6 +- 29 files changed, 293 insertions(+), 206 deletions(-) create mode 100644 shaders/shadow.glsl rename src/core/{ => view}/glwidget.cpp (98%) rename src/core/{ => view}/glwidget.h (98%) rename src/core/{ => view}/mouse_controller.cpp (97%) rename src/core/{ => view}/mouse_controller.h (100%) rename src/core/{ => view}/openglwindow.cpp (96%) rename src/core/{ => view}/openglwindow.h (97%) rename src/core/{ => view}/qglview.cpp (82%) rename src/core/{ => view}/qglview.h (89%) diff --git a/shaders/ds_light.glsl b/shaders/ds_light.glsl index 7f8c132..32275fe 100644 --- a/shaders/ds_light.glsl +++ b/shaders/ds_light.glsl @@ -19,7 +19,8 @@ in vec3 view_dir, world_dir; uniform vec2 dt; uniform float z_near; uniform sampler2D tex_coeffs[2]; -uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4; +uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4, tex_sh; +uniform sampler2DShadow tex_shadow[16]; uniform samplerCube tex_env; uniform int lights_start, lights_count; @@ -29,12 +30,20 @@ uniform mat3 view_mat; const vec3 luma = vec3(0.299, 0.587, 0.114); const float _min_rough = 1.e-8, max_lod = 8; +const float PI = 3.1416; vec4 pos, lpos, shp; vec3 li, si, ldir, halfV, bn, bn2, lwdir; //vec3 vds, vds2; float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist, shadow; +vec4 mapScreenToShadow(in int light_index) { + vec4 shp = qgl_light_position[light_index].shadow_matrix * pos; + shp.z += 0.095; + return shp; +} + + void calcLight(in int index, in vec3 n, in vec3 v) { lpos = qgl_light_position[index].position; ldir = lpos.xyz - (pos.xyz * lpos.w); @@ -49,6 +58,10 @@ void calcLight(in int index, in vec3 n, in vec3 v) { float scos = max(dot(-ldir, qgl_light_position[index].direction.xyz), 0.); spot *= scos * step(qgl_light_parameter[index].angles.w, scos); spot *= smoothstep(qgl_light_parameter[index].angles.w, qgl_light_parameter[index].angles.y, scos); + + vec4 shp = mapScreenToShadow(index); + spot *= textureProj(tex_shadow[index - lights_start], shp); + /*//lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz; //bn = normalize(cross(lwdir, vec3(1, 0, 0))); //bn2 = normalize(cross(lwdir, bn)); @@ -93,7 +106,7 @@ void calcLight(in int index, in vec3 n, in vec3 v) { ndlc = (1. - NdotHs) / NdotHs; float der = NdotHs * (rough_spec + ndlc); - spec = rough_spec / (der*der) / 3.1416; + spec = rough_spec / (der*der) / PI; //spec = texture(tex_coeffs[1], vec2(roughness, (NdotHs))).r; si += spot * spec * qgl_light_parameter[index].color.rgb; } @@ -172,7 +185,17 @@ void main(void) { res_col = mix(res_col, fog_color.rgb, fog); qgl_FragColor = vec4(res_col, alpha); - + /* +#ifdef SPOT + vec4 wpos = vec4(world_dir * z, 1); + vec4 shp = qgl_light_position[lights_start].shadow_matrix * (pos); + //shp.z += 0.095; + //qgl_FragColor.rgb = vec3(texture(tex_sh, shp.xy).rgb); + qgl_FragColor.rgb = vec3(textureProj(tex_shadow[0], shp)); + //vec4 rp = qgl_ViewProjMatrix*vec4(qgl_FragTexture.xy,z,1); + //qgl_FragColor.rgb = vec3(shp.xy,0); +#endif + */ //vec3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y); //qgl_FragColor.rgb = vec3(shlick * brdf.x + brdf.y); //qgl_FragColor.rgb = vec3(alpha); diff --git a/shaders/ds_tonemap.glsl b/shaders/ds_tonemap.glsl index 6b3aedc..254495e 100644 --- a/shaders/ds_tonemap.glsl +++ b/shaders/ds_tonemap.glsl @@ -22,4 +22,5 @@ void main(void) { l = 1 - exp(-l*g); res = max(vec3(0.f), res * l); qgl_FragColor = vec4(res, dot(res, luma)); + //qgl_FragColor = vec4(0.5); } diff --git a/shaders/shadow.glsl b/shaders/shadow.glsl new file mode 100644 index 0000000..679c292 --- /dev/null +++ b/shaders/shadow.glsl @@ -0,0 +1,24 @@ +// vert // + +void main(void) { + qgl_MaterialIndex = qgl_Material; + qgl_FragTexture = qgl_getFragTexture(); + gl_Position = qgl_ftransform(); +} + + +// frag // + +float z_near = 0.1f; +const float _pe = 2.4e-7; + +void main(void) { + vec4 diffuse = qgl_materialTexture(QGL_MAP_DIFFUSE, qgl_FragTexture.xy, vec4(0)); + if(diffuse.a < 0.5) + discard; + + float z = gl_FragCoord.z; + z = z + z - 1; + z = ((_pe - 2.) * z_near) / (z + _pe - 1.); // infinite depth + qgl_FragData[0] = vec4(z / 20); +} diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 644a085..9570beb 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -7,7 +7,7 @@ qad_find_qt(Core Gui OpenGL OpenGLWidgets Xml) find_package(OpenGL REQUIRED) qad_sources(SRC) set(_includes "${_qglengine_root_build}") -foreach (_d "formats" "core" "scene" "render") +foreach (_d "formats" "core" "scene" "render" "view") qad_sources(FSRC DIR "${_d}") list(APPEND SRC ${FSRC}) list(APPEND _includes "${CMAKE_CURRENT_SOURCE_DIR}/${_d}") diff --git a/src/core/core/glframebuffer.cpp b/src/core/core/glframebuffer.cpp index 6e2a267..77e46a7 100644 --- a/src/core/core/glframebuffer.cpp +++ b/src/core/core/glframebuffer.cpp @@ -70,7 +70,7 @@ void Framebuffer::resize(int width, int height, bool force) { if (fbo > 0) deleteGLFramebuffer(fbo); f->glGenFramebuffers(1, &fbo); f->glBindFramebuffer(GL_FRAMEBUFFER, fbo); - // qDebug() << "resize" << f << wid << hei << fbo; + // qDebug() << "resize" << f << wid << hei << fbo << colors.size(); for (int i = 0; i < colors.size(); ++i) { deleteGLTexture(f, colors[i]); createGLTexture(f, colors[i], width, height, color_formats[i], target_); @@ -94,6 +94,7 @@ void Framebuffer::resize(int width, int height, bool force) { f->glTexParameteri(target_, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); f->glTexParameteri(target_, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, target_, tex_d, 0); + // f->glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, target_, tex_d, 0); } f->glBindFramebuffer(GL_FRAMEBUFFER, 0); if (pbo.isInit()) { @@ -103,7 +104,8 @@ void Framebuffer::resize(int width, int height, bool force) { } -void Framebuffer::reinit() { +void Framebuffer::reinit(QOpenGLExtraFunctions * f_) { + if (f_) f = f_; pbo.reinit(); colors.fill(0); fbo = drbo = 0; diff --git a/src/core/core/glframebuffer.h b/src/core/core/glframebuffer.h index 955f155..12cca60 100644 --- a/src/core/core/glframebuffer.h +++ b/src/core/core/glframebuffer.h @@ -61,8 +61,9 @@ public: GLbitfield mask = GL_COLOR_BUFFER_BIT, GLenum filter = GL_NEAREST) const; + void resize(QSize sz, bool force = false) { resize(sz.width(), sz.height(), force); } void resize(int width, int height, bool force = false); - void reinit(); + void reinit(QOpenGLExtraFunctions * f_ = nullptr); void bind(); void release(); void setReadBuffer(int index) { glReadBuffer(GL_COLOR_ATTACHMENT0 + index); } diff --git a/src/core/core/glshaders_headers.h b/src/core/core/glshaders_headers.h index 3f96a1a..8187a78 100644 --- a/src/core/core/glshaders_headers.h +++ b/src/core/core/glshaders_headers.h @@ -99,6 +99,7 @@ const char qgl_structs[] = "#define QGL_MAPS_COUNT 6\n" "struct QGLLightPosition {\n" " vec4 position;\n" " vec4 direction;\n" + " mat4 shadow_matrix;\n" "};\n" ""; diff --git a/src/core/core/glshaders_types.h b/src/core/core/glshaders_types.h index bc2e36f..4598651 100644 --- a/src/core/core/glshaders_types.h +++ b/src/core/core/glshaders_types.h @@ -89,12 +89,13 @@ enum BindingPoints { }; enum MapType { - mtDiffuse = 0, - mtNormal = 1, - mtMetalness = 2, - mtRoughness = 3, - mtEmission = 4, - mtRelief = 5, + mtDiffuse = 0, + mtNormal = 1, + mtMetalness = 2, + mtRoughness = 3, + mtEmission = 4, + mtRelief = 5, + mtShadowCone = 8, }; enum TextureArrayRole { tarEmpty = 0, @@ -131,8 +132,10 @@ struct QGLLightParameter { QVector4D angles; // [start, cos(start), end, cos(end)] }; struct QGLLightPosition { + QGLLightPosition() { QMatrix4x4().copyDataTo(shadowmatrix); } QVector4D position; QVector4D direction; + GLfloat shadowmatrix[16]; }; #pragma pack(pop) diff --git a/src/core/core/gltexturearray.cpp b/src/core/core/gltexturearray.cpp index eafdc9b..f419fe5 100644 --- a/src/core/core/gltexturearray.cpp +++ b/src/core/core/gltexturearray.cpp @@ -22,8 +22,9 @@ #include -Texture2DArray::Texture2DArray(bool filter) { +Texture2DArray::Texture2DArray(GLenum format, bool filter) { target_ = GL_TEXTURE_2D_ARRAY; + format_ = format; texture_ = 0; layers_ = 0; filtering_ = filter; @@ -81,7 +82,7 @@ bool Texture2DArray::resize(QOpenGLExtraFunctions * f, QSize new_size, int layer f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_NEAREST); f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } - f->glTexImage3D(target_, 0, GL_RGBA8, size_.width(), size_.height(), layers_, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + f->glTexImage3D(target_, 0, GL_RGBA8, size_.width(), size_.height(), layers_, 0, format_, GL_UNSIGNED_BYTE, nullptr); return true; } diff --git a/src/core/core/gltexturearray.h b/src/core/core/gltexturearray.h index 80b2c13..c845515 100644 --- a/src/core/core/gltexturearray.h +++ b/src/core/core/gltexturearray.h @@ -24,7 +24,7 @@ class QGLENGINE_CORE_EXPORT Texture2DArray { public: - Texture2DArray(bool filter); + Texture2DArray(GLenum format, bool filter); ~Texture2DArray(); void init(QOpenGLExtraFunctions * f); @@ -44,7 +44,7 @@ public: int layersCount() const { return layers_; } private: - GLenum target_; + GLenum target_, format_; GLuint texture_; QSize size_; int layers_; diff --git a/src/core/core/parameteredobject.cpp b/src/core/core/parameteredobject.cpp index 718bbbe..d429a12 100644 --- a/src/core/core/parameteredobject.cpp +++ b/src/core/core/parameteredobject.cpp @@ -26,4 +26,5 @@ PIValueTree ParameteredObject::parameters() const { void ParameteredObject::setParameters(const PIValueTree & p) { params.applyValues(p); + parametersChanged(); } diff --git a/src/core/core/parameteredobject.h b/src/core/core/parameteredobject.h index fa46ad2..1818661 100644 --- a/src/core/core/parameteredobject.h +++ b/src/core/core/parameteredobject.h @@ -33,6 +33,8 @@ public: void setParameters(const PIValueTree & p); protected: + virtual void parametersChanged() {} + PIValueTree params; }; diff --git a/src/core/render/renderer.cpp b/src/core/render/renderer.cpp index 8da29d4..f3f7dcc 100644 --- a/src/core/render/renderer.cpp +++ b/src/core/render/renderer.cpp @@ -61,6 +61,8 @@ Renderer::Renderer(QGLView * view_) shader_files[srFinalPass] = "ds_final.glsl"; shader_files[srTonemapPass] = "ds_tonemap.glsl"; + shader_files[srShadowPass] = "shadow.glsl"; + shader_defines[srGeometrySolidPass] << "SOLID"; shader_defines[srLightSpotPass] << "SPOT"; @@ -161,15 +163,16 @@ bool Renderer::bindShader(QOpenGLShaderProgram * sp) { void Renderer::initShaders() { if (!need_init_shaders) return; - need_init_shaders = false; - initUniformBuffer(shaders.value(srGeometrySolidPass), &buffer_materials, bpMaterials, "QGLMaterialData"); - initUniformBuffer(shaders.value(srGeometryTransparentPass), &buffer_materials, bpMaterials, "QGLMaterialData"); + need_init_shaders = false; + // initUniformBuffer(shaders.value(srGeometrySolidPass), &buffer_materials, bpMaterials, "QGLMaterialData"); + // initUniformBuffer(shaders.value(srGeometryTransparentPass), &buffer_materials, bpMaterials, "QGLMaterialData"); + // initUniformBuffer(shaders.value(srShadowPass), &buffer_materials, bpMaterials, "QGLMaterialData"); QOpenGLShaderProgram * prog = 0; for (ShaderRole role: {srLightOmniPass, srLightSpotPass}) { - initUniformBuffer(shaders.value(role), &buffer_materials, bpMaterials, "QGLMaterialData"); - initUniformBuffer(shaders.value(role), &buffer_lights, bpLightParameters, "QGLLightParameterData"); - initUniformBuffer(shaders.value(role), &buffer_lights_pos, bpLightPositions, "QGLLightPositionData"); if (!bindShader(role, &prog)) continue; + initUniformBuffer(prog, &buffer_materials, bpMaterials, "QGLMaterialData"); + initUniformBuffer(prog, &buffer_lights, bpLightParameters, "QGLLightParameterData"); + initUniformBuffer(prog, &buffer_lights_pos, bpLightPositions, "QGLLightPositionData"); for (int i = 0; i < 5; ++i) prog->setUniformValue(QString("tex_%1").arg(i).toLatin1().constData(), i); prog->setUniformValue("tex_coeffs[0]", (int)Renderer::dbrBuffersCount); @@ -182,10 +185,9 @@ void Renderer::initShaders() { prog->setUniformValue("tex_t_0", 3); prog->setUniformValue("tex_t_1", 4); } - if (bindShader(srGeometrySolidPass, &prog)) { - setUniformMaps(prog); - } - if (bindShader(srGeometryTransparentPass, &prog)) { + for (ShaderRole role: {srGeometrySolidPass, srGeometryTransparentPass, srShadowPass}) { + if (!bindShader(role, &prog)) continue; + initUniformBuffer(prog, &buffer_materials, bpMaterials, "QGLMaterialData"); setUniformMaps(prog); } if (bindShader(srTonemapPass, &prog)) { @@ -286,6 +288,18 @@ void Renderer::renderLight(int first_wr_buff, bool clear_only) { back.setAlpha(0); foreach(PassPair pass, passes) { if (bindShader(pass.first, &prog)) { + if (pass.second == Light::Cone) { + QVector samplers; + samplers.resize(16); + auto & cone_ll(cur_lights[pass.second]); + for (int i = 0; i < cone_ll.size(); ++i) { + Light * l = cone_ll[i]; + l->shadow_map.bindDepthTexture(mtShadowCone + i); + // l->shadow_map.bindColorTexture(0, 10); + samplers[i] = mtShadowCone + i; + } + prog->setUniformValueArray("tex_shadow", samplers.data(), samplers.size()); + } fbo_out.setWriteBuffer(first_wr_buff + pass.second); glClearFramebuffer(back, false); if (clear_only) continue; @@ -303,6 +317,26 @@ void Renderer::renderLight(int first_wr_buff, bool clear_only) { } +void Renderer::renderShadow(Light * light) { + Scene & scene(*(view->scene())); + bool force_resize = false; + if (!light->shadow_map.isInit()) { + light->shadow_map.reinit(view); + force_resize = true; + } + light->shadow_map.resize(view->shadow_map_size, force_resize); + if (force_resize) { + light->shadow_map.bindDepthTexture(mtShadowCone); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + light->shadow_map.bind(); + glClearFramebuffer(); + renderObjects(scene, rpSolid); + light->shadow_map.release(); +} + + void Renderer::renderScene() { timings.clear(); Measurer phase(&timings); @@ -315,6 +349,7 @@ void Renderer::renderScene() { Camera * cam = view->camera(); QOpenGLShaderProgram * prog = 0; bool scene_changed = scene.prepare(); + cur_lights = scene.lights_used; scene.destroyUnused(f); phase.end(); @@ -335,9 +370,36 @@ void Renderer::renderScene() { } phase.end(); + /// shadows + phase.begin("shadows"); + if (bindShader(srShadowPass, &prog)) { + glEnableDepth(); + textures_empty.bind(f, tarEmpty); + textures_maps.bind(f, tarMaps); + auto cam_ivm = cam->fullViewMatrix().inverted(); + auto cone_ll = cur_lights.value(Light::Cone); + QMatrix4x4 mat_vp; + mat_vp.scale(0.5, 0.5); + mat_vp.translate(1, 1); + for (int i = 0; i < cone_ll.size(); ++i) { + Light * l = cone_ll[i]; + QMatrix4x4 pm = glMatrixPerspective(l->angle_end, 1., 0.1), om, vm; + om.translate(-l->worldAim()); + vm.translate(0., 0., -l->distance()); + // vm.rotate(-roll_, 0., 0., 1.); + QMatrix4x4 pmat = l->worldTransform(); + pmat(0, 3) = pmat(1, 3) = pmat(2, 3) = 0.; + vm *= pmat.inverted(); + auto vpm = pm * (vm * om); + prog->setUniformValue("qgl_ViewProjMatrix", vpm); + renderShadow(l); + l->shadow_matrix = mat_vp * vpm * cam_ivm; + } + } + phase.end(); + /// lights phase.begin("lights prepare"); - cur_lights = scene.lights_used; bool use_camlight = (camera_light_mode == QGLView::clmOn); if ((camera_light_mode == QGLView::clmAuto) && cur_lights.isEmpty()) { use_camlight = true; @@ -360,6 +422,7 @@ void Renderer::renderScene() { } phase.end(); + /// solid geometry pass phase.begin("geometry solid"); fbo_ds.bind(); @@ -369,7 +432,9 @@ void Renderer::renderScene() { setUniformCamera(prog, cam); textures_empty.bind(f, tarEmpty); textures_maps.bind(f, tarMaps); + glPolygonMode(GL_FRONT_AND_BACK, view->renderMode()); renderObjects(scene, rpSolid); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } fbo_ds.blit(dbrNormalZ, fbo_ds.id(), dbrNormalZSolid, fbo_ds.rect(), fbo_ds.rect()); fbo_ds.blit(dbrSpecularReflect, fbo_ds.id(), dbrSpecularReflectSolid, fbo_ds.rect(), fbo_ds.rect()); @@ -392,7 +457,9 @@ void Renderer::renderScene() { setUniformCamera(prog, cam); textures_empty.bind(f, tarEmpty); textures_maps.bind(f, tarMaps); + glPolygonMode(GL_FRONT_AND_BACK, view->renderMode()); renderObjects(scene, rpTransparent); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } fbo_ds.release(); phase.end(); @@ -434,7 +501,7 @@ void Renderer::renderScene() { /// FXAA phase.begin("fxaa"); - if (view->isFeatureEnabled(QGLView::qglFXAA)) { + if (view->FXAA_) { prog = shader_fxaa; if (bindShader(prog)) { auto free = getFreePlanes(0); @@ -462,7 +529,7 @@ void Renderer::renderScene() { rend_selection.drawSelection(fbo_out, cur_write_plane); rend_service.renderService(); } else { - fbo_out.blit(cur_write_plane, 0, 0, fbo_out.rect(), QRect(QPoint(), view->size() * view->devicePixelRatio())); + fbo_out.blit(cur_write_plane, 0, 0, fbo_out.rect(), QRect(QPoint(), view->pixelSize())); } phase.end(); @@ -474,6 +541,12 @@ void Renderer::renderScene() { // qDebug() << last_img.size(); } phase.end(); + /* + auto cone_ll = cur_lights.value(Light::Cone); + if (!cone_ll.isEmpty()) { + Light * l = cone_ll[0]; + l->shadow_map.blit(0, 0, 0, l->shadow_map.rect(), l->shadow_map.rect()); + }*/ } diff --git a/src/core/render/renderer.h b/src/core/render/renderer.h index c718911..ef26eb0 100644 --- a/src/core/render/renderer.h +++ b/src/core/render/renderer.h @@ -57,6 +57,7 @@ class QGLENGINE_CORE_EXPORT Renderer: public RendererBase { srLightSpotPass, srFinalPass, srTonemapPass, + srShadowPass, }; enum OutBufferRole { obrSolidOmni, @@ -112,6 +113,7 @@ protected: void reloadObjects(); void renderObjects(Scene & scene, RenderPass pass); void renderLight(int first_wr_buff, bool clear_only); + void renderShadow(Light * light); bool bindShader(ShaderRole role, QOpenGLShaderProgram ** ret = 0); bool bindShader(QOpenGLShaderProgram * sp); diff --git a/src/core/render/renderer_base.cpp b/src/core/render/renderer_base.cpp index 0d57a2c..3f26d5e 100644 --- a/src/core/render/renderer_base.cpp +++ b/src/core/render/renderer_base.cpp @@ -35,8 +35,8 @@ RendererBase::RendererBase(QGLView * view_) , buffer_materials(GL_UNIFORM_BUFFER, GL_STREAM_DRAW) , buffer_lights(GL_UNIFORM_BUFFER, GL_STREAM_DRAW) , buffer_lights_pos(GL_UNIFORM_BUFFER, GL_STREAM_DRAW) - , textures_empty(false) - , textures_maps(true) { + , textures_empty(GL_RGBA, false) + , textures_maps(GL_RGBA, true) { textures_manager = new TextureManager(view); maps_size = QSize(1024, 1024); maps_hash = 0; @@ -237,11 +237,12 @@ void RendererBase::reloadLightsPositions(Camera * cam) { QGLLightPosition & so(cur_lights_pos_[i]); Light * l = current_lights[i]; QMatrix4x4 m = mat * l->worldTransform(); - QVector4D pos(0, 0, 0, 1.), dir(QVector3D(0, 0, -1), 1); + QVector4D pos(0, 0, 0, 1.), dir(0, 0, -1, 1); pos = m * pos; - dir = (m * QVector4D(QVector3D(0, 0, -1), 0)).normalized(); + dir = (m * QVector4D(0, 0, -1, 0)).normalized(); so.position = pos; so.direction = dir; + l->shadow_matrix.transposed().copyDataTo(so.shadowmatrix); } buffer_lights_pos.bind(view); buffer_lights_pos.resize(view, cur_lights_pos_.size() * sizeof(QGLLightPosition)); diff --git a/src/core/scene/globject.cpp b/src/core/scene/globject.cpp index 34b5938..52fa9c1 100644 --- a/src/core/scene/globject.cpp +++ b/src/core/scene/globject.cpp @@ -26,11 +26,10 @@ // static int _count = 0; ObjectBase::ObjectBase(Mesh * geom, Material * mat) { - type_ = glMesh; - render_mode = View; - prev_pass = rpSolid; - parent_ = nullptr; - color_ = Qt::white; + type_ = glMesh; + prev_pass = rpSolid; + parent_ = nullptr; + color_ = Qt::white; is_root = is_init = selected_ = false; visible_ = accept_fog = accept_light = cast_shadow = rec_shadow = select_ = true; line_width = -1.; @@ -588,7 +587,7 @@ void AimedObject::orbitXY(const float & a) { void AimedObject::transformChanged() {} -Light::Light(): AimedObject(), shadow_map(0, true, GL_R16F) { +Light::Light(): AimedObject(), shadow_map(nullptr, 1, true) { type_ = glLight; light_type = Omni; intensity = 1.; @@ -599,7 +598,7 @@ Light::Light(): AimedObject(), shadow_map(0, true, GL_R16F) { } -Light::Light(const QVector3D & p, const QColor & c, float i): AimedObject(), shadow_map(0, true, GL_R16F) { +Light::Light(const QVector3D & p, const QColor & c, float i): AimedObject(), shadow_map(nullptr, 1, true) { type_ = glLight; light_type = Omni; intensity = i; @@ -655,7 +654,6 @@ QDataStream & operator<<(QDataStream & s, const ObjectBase * p) { .add(6, p->rec_shadow) .add(7, p->raw_matrix) .add(8, p->line_width) - .add(9, int(p->render_mode)) .add(14, p->mat_) .add(16, p->children_.size()) .add(17, p->name_) @@ -741,9 +739,6 @@ QDataStream & operator>>(QDataStream & s, ObjectBase *& p) { case 8: if (p) p->line_width = cs.getData(); break; - case 9: - if (p) p->render_mode = (ObjectBase::RenderMode)cs.getData(); - break; case 14: if (p) p->mat_ = cs.getData(); break; diff --git a/src/core/scene/globject.h b/src/core/scene/globject.h index 9a36608..71f15fd 100644 --- a/src/core/scene/globject.h +++ b/src/core/scene/globject.h @@ -39,12 +39,6 @@ public: glCamera, glParticlesSystem }; - enum RenderMode { - View = 0, - Point = GL_POINT, - Line = GL_LINE, - Fill = GL_FILL - }; explicit ObjectBase(Mesh * geom = 0, Material * mat = 0); virtual ~ObjectBase(); @@ -61,9 +55,6 @@ public: RenderPass pass() const; uint id() const { return id_; } - RenderMode renderMode() const { return render_mode; } - void setRenderMode(RenderMode mode) { render_mode = mode; } - float lineWidth() const { return line_width; } void setLineWidth(const float & width) { line_width = width; } @@ -338,7 +329,6 @@ protected: QColor color_; uint id_; Type type_; - RenderMode render_mode; Box3D bound; Transform trans, trans_texture; ObjectBaseList children_; diff --git a/src/core/glwidget.cpp b/src/core/view/glwidget.cpp similarity index 98% rename from src/core/glwidget.cpp rename to src/core/view/glwidget.cpp index e18bcc0..5c5509f 100644 --- a/src/core/glwidget.cpp +++ b/src/core/view/glwidget.cpp @@ -37,6 +37,16 @@ GLWidget::GLWidget(QWidget * parent): QWidget(parent) { } +Renderer * GLWidget::renderer() { + return &(view_->renderer_); +} + + +Scene * GLWidget::scene() { + return view_->scene(); +} + + qreal GLWidget::lineWidth() const { return view_->lineWidth(); } @@ -107,11 +117,6 @@ qreal GLWidget::selectionHaloFillAlpha() const { } -Scene * GLWidget::scene() { - return view_->scene(); -} - - void GLWidget::addObject(ObjectBase * o) { view_->scene()->addObject(o); } diff --git a/src/core/glwidget.h b/src/core/view/glwidget.h similarity index 98% rename from src/core/glwidget.h rename to src/core/view/glwidget.h index 4fb7e52..ba0d44f 100644 --- a/src/core/glwidget.h +++ b/src/core/view/glwidget.h @@ -27,6 +27,7 @@ class QGLView; class ObjectBase; class Scene; +class Renderer; class QGLENGINE_CORE_EXPORT GLWidget: public QWidget { Q_OBJECT @@ -47,6 +48,8 @@ class QGLENGINE_CORE_EXPORT GLWidget: public QWidget { public: explicit GLWidget(QWidget * parent = nullptr); QGLView * view() { return view_; } + Renderer * renderer(); + Scene * scene(); QColor backColor() const; qreal lineWidth() const; @@ -64,7 +67,6 @@ public: bool isSelectionHaloEnabled() const; QColor selectionHaloColor() const; qreal selectionHaloFillAlpha() const; - Scene * scene(); void addObject(ObjectBase * o); QByteArray saveCamera(); diff --git a/src/core/mouse_controller.cpp b/src/core/view/mouse_controller.cpp similarity index 97% rename from src/core/mouse_controller.cpp rename to src/core/view/mouse_controller.cpp index 27daf52..3f1aac3 100644 --- a/src/core/mouse_controller.cpp +++ b/src/core/view/mouse_controller.cpp @@ -94,7 +94,7 @@ void MouseController::mouseReleaseEvent(QMouseEvent * e) { void MouseController::mousePressEvent(QMouseEvent * e) { QPoint cpos = e->pos() * view->devicePixelRatio(); - downPos = cpos; + downPos = cpos; if (cur_action != RendererService::haNoAction && e->buttons() == Qt::LeftButton) { return; } @@ -103,7 +103,7 @@ void MouseController::mousePressEvent(QMouseEvent * e) { view->renderer_.mouse_rect = QRect(); return; } - if (!QRect(QPoint(), view->size() * view->devicePixelRatio()).contains(cpos)) return; + if (!QRect(QPoint(), view->pixelSize()).contains(cpos)) return; lastPos = cpos; downPos = cpos; emit view->glMousePressEvent(e); @@ -206,7 +206,7 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) { } return; } - QRect g_rect(QPoint(), view->size() * view->devicePixelRatio()); + QRect g_rect(QPoint(), view->pixelSize()); if (mouseRotate_) { float dx = cpos.x() - lastPos.x(); float dy = cpos.y() - lastPos.y(); @@ -264,8 +264,8 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) { return; } lastPos = g_rect.center(); - int dx = cpos.x() - lastPos.x(); - int dy = cpos.y() - lastPos.y(); + int dx = cpos.x() - lastPos.x(); + int dy = cpos.y() - lastPos.y(); emit view->glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers())); return; } diff --git a/src/core/mouse_controller.h b/src/core/view/mouse_controller.h similarity index 100% rename from src/core/mouse_controller.h rename to src/core/view/mouse_controller.h diff --git a/src/core/openglwindow.cpp b/src/core/view/openglwindow.cpp similarity index 96% rename from src/core/openglwindow.cpp rename to src/core/view/openglwindow.cpp index 6443fe6..74584dc 100644 --- a/src/core/openglwindow.cpp +++ b/src/core/view/openglwindow.cpp @@ -76,6 +76,11 @@ int OpenGLWindow::pixelHeight() const { } +QSize OpenGLWindow::pixelSize() const { + return QSize(pixelWidth(), pixelHeight()); +} + + // void OpenGLWindow::setSamples(int samples) { // QSurfaceFormat f = requestedFormat(); // if (f.samples() != samples) { diff --git a/src/core/openglwindow.h b/src/core/view/openglwindow.h similarity index 97% rename from src/core/openglwindow.h rename to src/core/view/openglwindow.h index ce16fc8..fe409d6 100644 --- a/src/core/openglwindow.h +++ b/src/core/view/openglwindow.h @@ -29,6 +29,7 @@ public: int pixelWidth() const; int pixelHeight() const; + QSize pixelSize() const; public slots: void renderLater(); diff --git a/src/core/qglview.cpp b/src/core/view/qglview.cpp similarity index 82% rename from src/core/qglview.cpp rename to src/core/view/qglview.cpp index b129c98..8c2b653 100644 --- a/src/core/qglview.cpp +++ b/src/core/view/qglview.cpp @@ -41,40 +41,41 @@ QGLView::QGLView(): OpenGLWindow(), renderer_(this), mouse(this) { max_texture_chanels = 8; lightEnabled_ = true; shaders_supported = false; + FXAA_ = false; fps_cnt = 0; fps_tm = fps_ = 0.; fogColor_ = Qt::darkGray; fogDensity_ = 0.; fogDecay_ = 10.; hoverHaloFill_ = selectionHaloFill_ = 0.15f; - // lmode = Simple; - setFeature(qglFXAA, false); - setFeature(qglAnisotropicLevel, 8); - setFeature(qglEyeAccomodationEnabled, false); - setFeature(qglEyeAccomodationTime, 16.); - setFeature(qglEyeAccomodationMaxSpeed, 0.2); - setFeature(qglBloomEnabled, false); - setFeature(qglBloomThreshold, 0.9); - setFeature(qglBloomFactor, 1.); - setFeature(qglBloomRadius, 8); - setFeature(qglMotionBlurEnabled, false); - setFeature(qglMotionBlurFactor, 1.); - setFeature(qglMotionBlurSteps, 8); - setFeature(qglShadowsEnabled, false); - setFeature(qglShadowsMapSize, 512); - setFeature(qglShadowsSoftEnabled, true); - setFeature(qglReflectionsEnabled, false); - setFeature(qglReflectionsBlur, true); - setFeature(qglSSAOEnabled, false); - setFeature(qglSSAORadius, 5); - setFeature(qglDepthOfFieldEnabled, false); - setFeature(qglDepthOfFieldAutoFocusEnabled, true); - setFeature(qglDepthOfFieldAutoFocusSpeed, 0.1); - setFeature(qglDepthOfFieldFocus, 1.); - setFeature(qglDepthOfFieldDiaphragm, 8.); + render_mode = rmFill; + shadow_map_size = QSize(512, 512); + // setFeature(qglFXAA, false); + // setFeature(qglAnisotropicLevel, 8); + // setFeature(qglEyeAccomodationEnabled, false); + // setFeature(qglEyeAccomodationTime, 16.); + // setFeature(qglEyeAccomodationMaxSpeed, 0.2); + // setFeature(qglBloomEnabled, false); + // setFeature(qglBloomThreshold, 0.9); + // setFeature(qglBloomFactor, 1.); + // setFeature(qglBloomRadius, 8); + // setFeature(qglMotionBlurEnabled, false); + // setFeature(qglMotionBlurFactor, 1.); + // setFeature(qglMotionBlurSteps, 8); + // setFeature(qglShadowsEnabled, false); + // setFeature(qglShadowsMapSize, 512); + // setFeature(qglShadowsSoftEnabled, true); + // setFeature(qglReflectionsEnabled, false); + // setFeature(qglReflectionsBlur, true); + // setFeature(qglSSAOEnabled, false); + // setFeature(qglSSAORadius, 5); + // setFeature(qglDepthOfFieldEnabled, false); + // setFeature(qglDepthOfFieldAutoFocusEnabled, true); + // setFeature(qglDepthOfFieldAutoFocusSpeed, 0.1); + // setFeature(qglDepthOfFieldFocus, 1.); + // setFeature(qglDepthOfFieldDiaphragm, 8.); hoverHalo_ = selectionHalo_ = true; fogEnabled_ = shaders_bind = false; - rmode = ObjectBase::Fill; scene_ = new Scene(); connect(scene_, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); connect(scene_, SIGNAL(__destroyed()), this, SLOT(__destroyed())); @@ -266,19 +267,3 @@ void QGLView::restoreCamera(const QByteArray & ba) { camera()->setAngles(ang); camera()->setFOV(fov); } - - -QByteArray QGLView::saveFeatures() { - QByteArray ba; - QDataStream ds(&ba, QIODevice::WriteOnly); - ds << features_; - return ba; -} - - -void QGLView::restoreFeatures(const QByteArray & ba) { - QHash f; - QDataStream ds(ba); - ds >> f; - features_ = f; -} diff --git a/src/core/qglview.h b/src/core/view/qglview.h similarity index 89% rename from src/core/qglview.h rename to src/core/view/qglview.h index a9c9833..7b42f82 100644 --- a/src/core/qglview.h +++ b/src/core/view/qglview.h @@ -31,7 +31,10 @@ #include #include -class QGLENGINE_CORE_EXPORT QGLView: public OpenGLWindow { +class QGLENGINE_CORE_EXPORT QGLView + : public OpenGLWindow + , public ParameteredObject { + friend class Renderer; friend class RendererSelection; Q_OBJECT Q_PROPERTY(float lineWidth READ lineWidth WRITE setLineWidth) @@ -67,32 +70,10 @@ public: clmAuto, clmOn, }; - - enum Feature { - qglFXAA, - qglAnisotropicLevel, - qglEyeAccomodationEnabled, - qglEyeAccomodationTime, - qglEyeAccomodationMaxSpeed, - qglBloomEnabled, - qglBloomThreshold, - qglBloomFactor, - qglBloomRadius, - qglMotionBlurEnabled, - qglMotionBlurFactor, - qglMotionBlurSteps, - qglShadowsEnabled, - qglShadowsMapSize, - qglShadowsSoftEnabled, - qglReflectionsEnabled, - qglReflectionsBlur, - qglSSAOEnabled, - qglSSAORadius, - qglDepthOfFieldEnabled, - qglDepthOfFieldAutoFocusEnabled, - qglDepthOfFieldAutoFocusSpeed, - qglDepthOfFieldFocus, - qglDepthOfFieldDiaphragm + enum RenderMode { + rmPoint = GL_POINT, + rmLine = GL_LINE, + rmFill = GL_FILL }; Q_ENUM(CameraLightMode) @@ -108,6 +89,8 @@ public: bool autoExposure() const { return renderer_.tone_proc.enabled; } int maxAnisotropicLevel() const { return max_anisotropic; } QString environmentMapFile() const { return renderer_.tex_env.fileHDR(); } + bool FXAA() const { return FXAA_; } + void setFXAA(bool on) { FXAA_ = on; } QColor fogColor() const { return fogColor_; } float fogDensity() const { return fogDensity_; } @@ -125,16 +108,8 @@ public: QColor selectionHaloColor() const { return selectionHaloColor_; } float selectionHaloFillAlpha() const { return selectionHaloFill_; } - QVariant feature(Feature f) const { return features_.value(int(f)); } - QVariant setFeature(Feature f, const QVariant & value) { - QVariant ret = features_.value(int(f)); - features_[int(f)] = value; - return ret; - } - bool isFeatureEnabled(Feature f) const { return features_[int(f)].toBool(); } - - int renderMode() const { return (int)rmode; } - void setRenderMode(int mode) { rmode = (ObjectBase::RenderMode)mode; } + int renderMode() const { return (int)render_mode; } + void setRenderMode(int mode) { render_mode = (RenderMode)mode; } bool isServiceMode() const { return renderer_.edit_mode; } void setServiceMode(bool yes) { renderer_.edit_mode = yes; } @@ -170,8 +145,6 @@ public: bool isDefaultCamera() const { return camera_ == default_camera; } QByteArray saveCamera(); void restoreCamera(const QByteArray & ba); - QByteArray saveFeatures(); - void restoreFeatures(const QByteArray & ba); QImage materialThumbnail(Material * m) { return renderer_.materialThumbnail(m); } void setCurrentAction(RendererService::HandleAction ha) { renderer_.rend_service.setCurrentAction(ha); } @@ -219,14 +192,13 @@ private: QColor fogColor_, hoverHaloColor_, selectionHaloColor_; QElapsedTimer time; GLint max_anisotropic, max_texture_chanels; - ObjectBase::RenderMode rmode; - QHash features_; - QSize prev_size; + RenderMode render_mode; + QSize prev_size, shadow_map_size; float lineWidth_; float fps_, fps_tm, fogDensity_, fogDecay_; float hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor; int timer, fps_cnt, sh_id_loc; - bool fogEnabled_, lightEnabled_; + bool fogEnabled_, lightEnabled_, FXAA_; bool shaders_supported, shaders_bind; bool hoverHalo_, selectionHalo_; bool is_init; diff --git a/src/qglview_test/qglview_window.cpp b/src/qglview_test/qglview_window.cpp index 2f11df0..33d458d 100644 --- a/src/qglview_test/qglview_window.cpp +++ b/src/qglview_test/qglview_window.cpp @@ -87,6 +87,7 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView view->view()->setSelectionMode(Scene::smMultiSelection); auto * e = new Effect1(); + e->setEnabled(false); view->view()->renderer_.addFramebufferEffect(e); PIValueTree params; @@ -96,30 +97,30 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView // widgetParameters->setFullEditMode(true); widgetParameters->setGrouping(PIValueTreeEdit::Groups); widgetParameters->setValue(params); - - groupShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsEnabled)); - groupEyeAccomodation->setChecked(view->view()->isFeatureEnabled(QGLView::qglEyeAccomodationEnabled)); - groupBloom->setChecked(view->view()->isFeatureEnabled(QGLView::qglBloomEnabled)); - groupMotionBlur->setChecked(view->view()->isFeatureEnabled(QGLView::qglMotionBlurEnabled)); - groupReflections->setChecked(view->view()->isFeatureEnabled(QGLView::qglReflectionsEnabled)); - checkSoftShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsSoftEnabled)); - groupSSAO->setChecked(view->view()->isFeatureEnabled(QGLView::qglSSAOEnabled)); - spinAccom->setValue(view->view()->feature(QGLView::qglEyeAccomodationTime).toDouble()); - spinAccomMS->setValue(view->view()->feature(QGLView::qglEyeAccomodationMaxSpeed).toDouble()); - checkReflectionsBlur->setChecked(view->view()->isFeatureEnabled(QGLView::qglReflectionsBlur)); - spinShadowmapSize->setValue(view->view()->feature(QGLView::qglShadowsMapSize).toInt()); - spinMotionBlurFactor->setValue(view->view()->feature(QGLView::qglMotionBlurFactor).toDouble()); - spinMotionBlurSteps->setValue(view->view()->feature(QGLView::qglMotionBlurSteps).toInt()); - spinBloomFactor->setValue(view->view()->feature(QGLView::qglBloomFactor).toDouble()); - spinBloomRadius->setValue(view->view()->feature(QGLView::qglBloomRadius).toInt()); - spinBloomThreshold->setValue(view->view()->feature(QGLView::qglBloomThreshold).toDouble()); - spinSSAORadius->setValue(view->view()->feature(QGLView::qglSSAORadius).toInt()); - groupDOF->setChecked(view->view()->isFeatureEnabled(QGLView::qglDepthOfFieldEnabled)); - checkDOFAutoFocus->setChecked(view->view()->isFeatureEnabled(QGLView::qglDepthOfFieldAutoFocusEnabled)); - spinDOFFocus->setValue(view->view()->feature(QGLView::qglDepthOfFieldFocus).toDouble()); - spinDOFDiaphragm->setValue(view->view()->feature(QGLView::qglDepthOfFieldDiaphragm).toDouble()); - spinDOFSpeed->setValue(view->view()->feature(QGLView::qglDepthOfFieldAutoFocusSpeed).toDouble()); - + /* + groupShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsEnabled)); + groupEyeAccomodation->setChecked(view->view()->isFeatureEnabled(QGLView::qglEyeAccomodationEnabled)); + groupBloom->setChecked(view->view()->isFeatureEnabled(QGLView::qglBloomEnabled)); + groupMotionBlur->setChecked(view->view()->isFeatureEnabled(QGLView::qglMotionBlurEnabled)); + groupReflections->setChecked(view->view()->isFeatureEnabled(QGLView::qglReflectionsEnabled)); + checkSoftShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsSoftEnabled)); + groupSSAO->setChecked(view->view()->isFeatureEnabled(QGLView::qglSSAOEnabled)); + spinAccom->setValue(view->view()->feature(QGLView::qglEyeAccomodationTime).toDouble()); + spinAccomMS->setValue(view->view()->feature(QGLView::qglEyeAccomodationMaxSpeed).toDouble()); + checkReflectionsBlur->setChecked(view->view()->isFeatureEnabled(QGLView::qglReflectionsBlur)); + spinShadowmapSize->setValue(view->view()->feature(QGLView::qglShadowsMapSize).toInt()); + spinMotionBlurFactor->setValue(view->view()->feature(QGLView::qglMotionBlurFactor).toDouble()); + spinMotionBlurSteps->setValue(view->view()->feature(QGLView::qglMotionBlurSteps).toInt()); + spinBloomFactor->setValue(view->view()->feature(QGLView::qglBloomFactor).toDouble()); + spinBloomRadius->setValue(view->view()->feature(QGLView::qglBloomRadius).toInt()); + spinBloomThreshold->setValue(view->view()->feature(QGLView::qglBloomThreshold).toDouble()); + spinSSAORadius->setValue(view->view()->feature(QGLView::qglSSAORadius).toInt()); + groupDOF->setChecked(view->view()->isFeatureEnabled(QGLView::qglDepthOfFieldEnabled)); + checkDOFAutoFocus->setChecked(view->view()->isFeatureEnabled(QGLView::qglDepthOfFieldAutoFocusEnabled)); + spinDOFFocus->setValue(view->view()->feature(QGLView::qglDepthOfFieldFocus).toDouble()); + spinDOFDiaphragm->setValue(view->view()->feature(QGLView::qglDepthOfFieldDiaphragm).toDouble()); + spinDOFSpeed->setValue(view->view()->feature(QGLView::qglDepthOfFieldAutoFocusSpeed).toDouble()); + */ view->view()->start(-1); startTimer(1000 / 60); diff --git a/src/qglview_test/qglview_window.h b/src/qglview_test/qglview_window.h index dcd586c..e8363fd 100644 --- a/src/qglview_test/qglview_window.h +++ b/src/qglview_test/qglview_window.h @@ -65,29 +65,29 @@ private: bool isChanged; private slots: - void on_groupShadows_clicked(bool val) { view->view()->setFeature(QGLView::qglShadowsEnabled, val); } - void on_groupEyeAccomodation_clicked(bool val) { view->view()->setFeature(QGLView::qglEyeAccomodationEnabled, val); } - void on_groupBloom_clicked(bool val) { view->view()->setFeature(QGLView::qglBloomEnabled, val); } - void on_groupMotionBlur_clicked(bool val) { view->view()->setFeature(QGLView::qglMotionBlurEnabled, val); } - void on_groupReflections_clicked(bool val) { view->view()->setFeature(QGLView::qglReflectionsEnabled, val); } - void on_checkSoftShadows_clicked(bool val) { view->view()->setFeature(QGLView::qglShadowsSoftEnabled, val); } - void on_groupSSAO_clicked(bool val) { view->view()->setFeature(QGLView::qglSSAOEnabled, val); } - void on_groupDOF_clicked(bool val) { view->view()->setFeature(QGLView::qglDepthOfFieldEnabled, val); } - void on_checkDOFAutoFocus_clicked(bool val) { view->view()->setFeature(QGLView::qglDepthOfFieldAutoFocusEnabled, val); } - void on_spinDOFFocus_valueChanged(double val) { view->view()->setFeature(QGLView::qglDepthOfFieldFocus, val); } - void on_spinDOFDiaphragm_valueChanged(double val) { view->view()->setFeature(QGLView::qglDepthOfFieldDiaphragm, val); } - void on_spinDOFSpeed_valueChanged(double val) { view->view()->setFeature(QGLView::qglDepthOfFieldAutoFocusSpeed, val); } - void on_spinAccom_valueChanged(double val) { view->view()->setFeature(QGLView::qglEyeAccomodationTime, val); } - void on_spinAccomMS_valueChanged(double val) { view->view()->setFeature(QGLView::qglEyeAccomodationMaxSpeed, val); } - void on_checkReflectionsBlur_clicked(bool val) { view->view()->setFeature(QGLView::qglReflectionsBlur, val); } - void on_spinShadowmapSize_valueChanged(double val) { view->view()->setFeature(QGLView::qglShadowsMapSize, val); } - void on_spinMotionBlurFactor_valueChanged(double val) { view->view()->setFeature(QGLView::qglMotionBlurFactor, val); } - void on_spinMotionBlurSteps_valueChanged(int val) { view->view()->setFeature(QGLView::qglMotionBlurSteps, val); } - void on_spinBloomFactor_valueChanged(double val) { view->view()->setFeature(QGLView::qglBloomFactor, val); } - void on_spinBloomRadius_valueChanged(int val) { view->view()->setFeature(QGLView::qglBloomRadius, val); } - void on_spinBloomThreshold_valueChanged(double val) { view->view()->setFeature(QGLView::qglBloomThreshold, val); } - void on_spinSSAORadius_valueChanged(int val) { view->view()->setFeature(QGLView::qglSSAORadius, val); } - + /* void on_groupShadows_clicked(bool val) { view->view()->setFeature(QGLView::qglShadowsEnabled, val); } + void on_groupEyeAccomodation_clicked(bool val) { view->view()->setFeature(QGLView::qglEyeAccomodationEnabled, val); } + void on_groupBloom_clicked(bool val) { view->view()->setFeature(QGLView::qglBloomEnabled, val); } + void on_groupMotionBlur_clicked(bool val) { view->view()->setFeature(QGLView::qglMotionBlurEnabled, val); } + void on_groupReflections_clicked(bool val) { view->view()->setFeature(QGLView::qglReflectionsEnabled, val); } + void on_checkSoftShadows_clicked(bool val) { view->view()->setFeature(QGLView::qglShadowsSoftEnabled, val); } + void on_groupSSAO_clicked(bool val) { view->view()->setFeature(QGLView::qglSSAOEnabled, val); } + void on_groupDOF_clicked(bool val) { view->view()->setFeature(QGLView::qglDepthOfFieldEnabled, val); } + void on_checkDOFAutoFocus_clicked(bool val) { view->view()->setFeature(QGLView::qglDepthOfFieldAutoFocusEnabled, val); } + void on_spinDOFFocus_valueChanged(double val) { view->view()->setFeature(QGLView::qglDepthOfFieldFocus, val); } + void on_spinDOFDiaphragm_valueChanged(double val) { view->view()->setFeature(QGLView::qglDepthOfFieldDiaphragm, val); } + void on_spinDOFSpeed_valueChanged(double val) { view->view()->setFeature(QGLView::qglDepthOfFieldAutoFocusSpeed, val); } + void on_spinAccom_valueChanged(double val) { view->view()->setFeature(QGLView::qglEyeAccomodationTime, val); } + void on_spinAccomMS_valueChanged(double val) { view->view()->setFeature(QGLView::qglEyeAccomodationMaxSpeed, val); } + void on_checkReflectionsBlur_clicked(bool val) { view->view()->setFeature(QGLView::qglReflectionsBlur, val); } + void on_spinShadowmapSize_valueChanged(double val) { view->view()->setFeature(QGLView::qglShadowsMapSize, val); } + void on_spinMotionBlurFactor_valueChanged(double val) { view->view()->setFeature(QGLView::qglMotionBlurFactor, val); } + void on_spinMotionBlurSteps_valueChanged(int val) { view->view()->setFeature(QGLView::qglMotionBlurSteps, val); } + void on_spinBloomFactor_valueChanged(double val) { view->view()->setFeature(QGLView::qglBloomFactor, val); } + void on_spinBloomRadius_valueChanged(int val) { view->view()->setFeature(QGLView::qglBloomRadius, val); } + void on_spinBloomThreshold_valueChanged(double val) { view->view()->setFeature(QGLView::qglBloomThreshold, val); } + void on_spinSSAORadius_valueChanged(int val) { view->view()->setFeature(QGLView::qglSSAORadius, val); } + */ void on_actionExit_triggered() { close(); } void on_actionReset_triggered(); void on_actionImport_triggered(); @@ -105,10 +105,6 @@ private slots: void on_actionRotate_triggered(bool on); void on_actionScale_triggered(bool on); - void on_colorFogBack_colorChanged(const QColor & v) { view->view()->setFogColor(v); } - void on_spinFogDensity_valueChanged(double v) { view->view()->setFogDensity(v); } - void on_spinFogDecay_valueChanged(double v) { view->view()->setFogDecay(v); } - void on_pushButton_3_clicked(); public slots: diff --git a/src/qglview_test/qglview_window.ui b/src/qglview_test/qglview_window.ui index e740164..a2dde62 100644 --- a/src/qglview_test/qglview_window.ui +++ b/src/qglview_test/qglview_window.ui @@ -50,7 +50,7 @@ - 2 + 0 diff --git a/src/widgets/view_editor.cpp b/src/widgets/view_editor.cpp index 714196c..de44f19 100644 --- a/src/widgets/view_editor.cpp +++ b/src/widgets/view_editor.cpp @@ -49,7 +49,7 @@ void ViewEditor::assignQGLView(QGLView * v) { ui->spinSelectionHaloFill->setValue(view->selectionHaloFillAlpha()); ui->colorHoverHalo->setColor(view->hoverHaloColor()); ui->colorSelectionHalo->setColor(view->selectionHaloColor()); - ui->checkFXAA->setChecked(view->isFeatureEnabled(QGLView::qglFXAA)); + ui->checkFXAA->setChecked(view->FXAA()); ui->checkCameraOrbit->setChecked(view->isCameraOrbit()); ui->checkCameraLight->setCheckState((Qt::CheckState)view->cameraLightMode()); ui->checkService->setChecked(view->isServiceMode()); @@ -93,7 +93,7 @@ void ViewEditor::on_spinViewGamma_valueChanged(double val) { void ViewEditor::on_comboViewRenderMode_currentIndexChanged(int val) { if (!view || !active) return; static int modes[] = {GL_POINT, GL_LINE, GL_FILL}; - view->setRenderMode((ObjectBase::RenderMode)modes[val]); + view->setRenderMode((QGLView::RenderMode)modes[val]); } @@ -141,7 +141,7 @@ void ViewEditor::on_checkAutoExposure_toggled(bool val) { void ViewEditor::on_checkFXAA_clicked(bool val) { if (!view || !active) return; - view->setFeature(QGLView::qglFXAA, val); + view->setFXAA(val); }