From 36540468dc7c5075c9c354a2c6f767724ec63c8c Mon Sep 17 00:00:00 2001 From: peri4 Date: Mon, 13 Feb 2023 18:35:25 +0300 Subject: [PATCH] nvidia fix, soft shadows --- shaders/ds_light.glsl | 97 +++++++++++++------- shaders/ds_tonemap.glsl | 1 - src/core/core/glshaders_headers.h | 21 +++-- src/core/core/glshaders_types.h | 7 +- src/core/render/renderer.cpp | 9 +- src/core/render/renderer_base.cpp | 12 ++- src/core/render/renderer_base.h | 1 + src/core/render/renderer_material.cpp | 3 +- src/core/scene/globject.cpp | 7 +- src/core/scene/globject.h | 1 + src/core/view/qglview.cpp | 45 ++++++--- src/core/view/qglview.h | 18 +++- src/widgets/object_editor.cpp | 4 +- src/widgets/object_editor.ui | 41 ++++++++- src/widgets/view_editor.cpp | 58 ++++++++++-- src/widgets/view_editor.h | 13 ++- src/widgets/view_editor.ui | 127 ++++++++++++++++++++------ 17 files changed, 358 insertions(+), 107 deletions(-) diff --git a/shaders/ds_light.glsl b/shaders/ds_light.glsl index 0c89578..6656e02 100644 --- a/shaders/ds_light.glsl +++ b/shaders/ds_light.glsl @@ -23,7 +23,8 @@ uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4, tex_sh; //uniform sampler2DShadow tex_shadow[16]; uniform sampler2DArray tex_shadows_cone; uniform samplerCube tex_env; -uniform int lights_start, lights_count; +uniform int lights_start, lights_count, soft_shadows_samples = 16; +uniform bool soft_shadows_enabled = false; uniform vec4 fog_color = vec4(0.5, 0.5, 0.5, 1); uniform float fog_decay = 10, fog_density = 0; @@ -36,7 +37,7 @@ 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; +float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist, shadow, shadow_dz; uint flags; @@ -47,8 +48,8 @@ vec4 mapScreenToShadow(in int light_index, in vec3 offset) { } -float getShadow(in vec3 uvz, in int layer) { - vec2 uvpix = uvz.xy * shadow_size + vec2(0.5f); +float getShadow(in vec3 uvz, in int layer, in vec2 uv_offset) { + vec2 uvpix = (uvz.xy + uv_offset) * shadow_size + vec2(0.5f); vec2 uvp = fract(uvpix), iuvp = vec2(1.f) - uvp; vec4 gt = textureGather(tex_shadows_cone, vec3(floor(uvpix.xy) / shadow_size, layer), 0); vec4 uvv; @@ -56,7 +57,18 @@ float getShadow(in vec3 uvz, in int layer) { uvv[1] = uvp.x * uvp.y; uvv[2] = uvp.x * iuvp.y; uvv[3] = iuvp.x * iuvp.y; - return dot(step(vec4(uvz.z), gt), uvv); + shadow_dz = max(max(uvz.z - gt[0], uvz.z - gt[1]), max(uvz.z - gt[2], uvz.z - gt[3])); + return clamp(dot(step(vec4(uvz.z), gt), uvv), 0, 1); +} + + +float rand(vec2 co) { + float a = 12.9898; + float b = 78.233; + float c = 43758.5453; + float dt= dot(co.xy ,vec2(a,b)); + float sn= mod(dt,3.14); + return fract(sin(sn) * c) - 0.5; } @@ -75,25 +87,42 @@ void calcLight(in int index, in vec3 n, in vec3 v) { 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); - if (qgl_light_parameter[index].flags == 1 && bitfieldExtract(flags, 3, 1) == 1) { + if (int(round(qgl_light_parameter[index].flags)) == 1 && bitfieldExtract(flags, 3, 1) == 1) { - float ds = ldist/300.; - //float bias = ldist * 0.05; - //vds = ds * bn.xyz; - //vds2 = ds * bn2.xyz; - int layer = index - lights_start; float shadow = 0.; vec4 shp = mapScreenToShadow(index, vec3(0)); - shp.xy /= shp.w; + + if (soft_shadows_enabled) { + + float ds = (ldist / 2.) / qgl_light_parameter[index].size; + vds = ds * bn.xyz; + vds2 = ds * bn2.xyz; + vec2 so; + + for (int i = 1; i <= soft_shadows_samples; ++i) { + //shadow += step(shp.z, texture(tex_shadows_cone, vec3(shp.xy, layer)).r); + so = vec2(rand(vec2(shp.x + i, shp.y)), rand(vec2(shp.x + i + 1, shp.y))); + vec4 shp = mapScreenToShadow(index, vds * so.x + vds2 * so.y); + shp.xy /= shp.w; + shadow += getShadow(shp.xyz, layer, vec2(0)); + } + + //shadow = getShadow(shp.xyz, layer, vec2(0)); + spot *= shadow / (soft_shadows_samples + 0);// / 25.f; + + } else { + + shp.xy /= shp.w; + spot *= getShadow(shp.xyz, layer, vec2(0)); + + } //shp.z -= bias; - //for (int xi = -2; xi <= 2; ++xi) { - // for (int yi = -2; yi <= 2; ++yi) { - //shadow += step(shp.z, texture(tex_shadows_cone, vec3(shp.xy, layer), ivec2(0, 0)).r); - shadow = getShadow(shp.xyz, layer); - // } - //} - spot *= shadow;// / 25.f; + //shadow += getShadow(shp.xyz, layer, vec2(0)); + + + //spot *= dot(so,vec2(1)) / scount + 0.5;// / 25.f; + //spot *= shadow_dz; //spot = texture(tex_shadows_cone, shp.xyz).r/20; //spot = sz; @@ -167,7 +196,6 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) { } - void main(void) { ivec2 tc = ivec2(gl_FragCoord.xy); vec4 v1 = texelFetch(tex_1, tc, 0); @@ -193,12 +221,12 @@ void main(void) { float reflectivity = v2.b; float NdotV = dot(normal, v); float roughness3 = roughness*roughness*roughness; - //bn = normalize(cross(normal, view_dir)); - //bn2 = normalize(cross(normal, bn)); + bn = normalize(cross(normal, view_dir)); + bn2 = normalize(cross(normal, bn)); rough_diff = max(roughness, _min_rough); rough_spec = max(roughness3, _min_rough); float shlick = clamp(metalness + (1 - metalness) * pow(1 - NdotV, 5), 0, 1); - flags = uint(v2.w); + flags = uint(round(v2.w)); li = vec3(0.);//qgl_AmbientLight.color.rgb * qgl_AmbientLight.intensity; si = vec3(0.); @@ -229,19 +257,26 @@ void main(void) { } qgl_FragColor = vec4(res_col, alpha); - //qgl_FragColor.rgb = vec3((v2.w/15)); - //qgl_FragColor.rgb = diffuse.rgb; - /* + //qgl_FragColor.rgb = vec3(qgl_light_parameter[0].size); + #ifdef SPOT - vec4 wpos = vec4(world_dir * z, 1); - vec4 shp = qgl_light_position[lights_start].shadow_matrix * (pos); + //vec4 shp = mapScreenToShadow(0, vec3(0)); + //shp.xy /= shp.w; + //shp.z -= bias; + //for (int xi = -2; xi <= 2; ++xi) { + // for (int yi = -2; yi <= 2; ++yi) { + //qgl_FragColor.rgb = vec3(step(shp.z, texture(tex_shadows_cone, vec3(shp.xy, 0)).r)); + //qgl_FragColor.r = texture(tex_shadows_cone, vec3(0)).r; + //qgl_FragColor.gb = vec2(1); + //qgl_FragColor.rg = shp.xy;//vec4(res_col, alpha); + //shp.z += 0.095; //qgl_FragColor.rgb = vec3(texture(tex_sh, shp.xy).rgb); - qgl_FragColor.rgb = vec3(textureProj(tex_shadow[0], shp)); + //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); + //qgl_FragColor.rgb = vec3(texture(tex_shadows_cone, vec3(gl_FragCoord.xy/1000, 0)).r); #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 254495e..6b3aedc 100644 --- a/shaders/ds_tonemap.glsl +++ b/shaders/ds_tonemap.glsl @@ -22,5 +22,4 @@ 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/src/core/core/glshaders_headers.h b/src/core/core/glshaders_headers.h index 42181e1..1c6f3ec 100644 --- a/src/core/core/glshaders_headers.h +++ b/src/core/core/glshaders_headers.h @@ -27,15 +27,15 @@ const int max_lights = 256; const char qgl_common_head[] = "#version 400 core\n" ""; -const char qgl_vertex_head[] = "layout(location = 1 ) in vec3 qgl_Vertex ;\n" - "layout(location = 2 ) in vec3 qgl_Normal ;\n" - "layout(location = 3 ) in vec3 qgl_Tangent ;\n" - "layout(location = 4 ) in vec3 qgl_Bitangent ;\n" - "layout(location = 5 ) in vec2 qgl_Texture ;\n" - "layout(location = 6 ) in uvec4 qgl_ObjectIntegers;\n" - "layout(location = 7 ) in uint qgl_ObjectSelected;\n" - "layout(location = 8 ) in vec4 qgl_ObjectColor ;\n" - "layout(location = 9 ) in mat4 qgl_ModelMatrix ;\n" +const char qgl_vertex_head[] = "layout(location = 1 ) in vec3 qgl_Vertex ;\n" + "layout(location = 2 ) in vec3 qgl_Normal ;\n" + "layout(location = 3 ) in vec3 qgl_Tangent ;\n" + "layout(location = 4 ) in vec3 qgl_Bitangent ;\n" + "layout(location = 5 ) in vec2 qgl_Texture ;\n" + "layout(location = 6 ) in uvec4 qgl_ObjectIntegers;\n" + "layout(location = 7 ) in uint qgl_ObjectSelected;\n" + "layout(location = 8 ) in vec4 qgl_ObjectColor ;\n" + "layout(location = 9 ) in mat4 qgl_ModelMatrix ;\n" "layout(location = 13) in mat2x3 qgl_TextureMatrix ;\n" "out vec2 qgl_FragTexture;\n" "flat out uint qgl_MaterialIndex;\n" @@ -97,7 +97,8 @@ const char qgl_structs[] = "#define QGL_MAPS_COUNT 6\n" " vec4 color;\n" " vec4 decay_intensity;\n" " vec4 angles;\n" - " uint flags;\n" + " float size;\n" + " float flags;\n" "};\n" "struct QGLLightPosition {\n" " vec4 position;\n" diff --git a/src/core/core/glshaders_types.h b/src/core/core/glshaders_types.h index bf588ef..e08a067 100644 --- a/src/core/core/glshaders_types.h +++ b/src/core/core/glshaders_types.h @@ -108,7 +108,7 @@ enum MapType { enum TextureArrayRole { tarEmpty = 0, tarMaps = 1, - tarShadowsCone = 2, + tarShadowsCone = 10, }; enum EmptyMapRole { emrWhite = 0, @@ -139,8 +139,9 @@ struct QGLLightParameter { QVector4D color; QVector4D decay_intensity; // [^0, ^1, ^2, intensity] QVector4D angles; // [start, cos(start), end, cos(end)] - GLuint flags = 0; - GLuint _align[3]; + GLfloat size = 0.1f; + GLfloat flags = 0; + GLfloat _align[2]; }; struct QGLLightPosition { QGLLightPosition() { QMatrix4x4().copyDataTo(shadowmatrix); } diff --git a/src/core/render/renderer.cpp b/src/core/render/renderer.cpp index 7b0c096..f58540a 100644 --- a/src/core/render/renderer.cpp +++ b/src/core/render/renderer.cpp @@ -291,7 +291,7 @@ void Renderer::renderLight(int first_wr_buff, bool clear_only) { } fbo_ds.bindColorTextures(); fbo_out.bind(); - tex_env.bind((int)Renderer::dbrBuffersCount + 1); + // tex_env.bind((int)Renderer::dbrBuffersCount + 1); typedef QPair PassPair; QVector passes; passes << PassPair(srLightOmniPass, Light::Omni) << PassPair(srLightSpotPass, Light::Cone); @@ -319,6 +319,10 @@ void Renderer::renderLight(int first_wr_buff, bool clear_only) { prog->setUniformValue("fog_density", view->fogDensity()); prog->setUniformValue("view_mat", cam->viewMatrix().inverted().toGenericMatrix<3, 3>()); prog->setUniformValue("shadow_size", view->shadow_map_size); + prog->setUniformValue("tex_shadows_cone", (int)tarShadowsCone); + prog->setUniformValue("soft_shadows_enabled", view->soft_shadows); + prog->setUniformValue("soft_shadows_samples", view->soft_shadows_samples); + shadow_maps_cone.bind(view, tarShadowsCone); renderQuad(prog, quad, cam); } } @@ -561,7 +565,8 @@ void Renderer::renderScene() { 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_base.cpp b/src/core/render/renderer_base.cpp index a6cdb00..063c956 100644 --- a/src/core/render/renderer_base.cpp +++ b/src/core/render/renderer_base.cpp @@ -55,7 +55,7 @@ void RendererBase::initTextureArrays() { textures_maps.init(f); textures_empty.init(f); textures_empty.resize(f, QSize(1, 1), 2); - textures_empty.bind(f); + textures_empty.bind(f, tarEmpty); QImage im(1, 1, QImage::Format_RGBA8888); im.fill(0xFFFFFFFF); textures_empty.load(f, im, emrWhite); @@ -153,11 +153,11 @@ void RendererBase::reloadMaterials(Scene & scene) { for (Material * m: scene.materials) { m->load(textures_manager); } - uint cur_maps_hash = textures_manager->texturesHash(); + uint cur_maps_hash = textures_manager->texturesHash() ^ ((maps_size.width() << 16) | maps_size.height()); if (maps_hash != cur_maps_hash) { maps_hash = cur_maps_hash; // textures_maps.resize(view, maps_size, textures_manager->texturesCount()); - textures_maps.bind(view); + textures_maps.bind(view, tarMaps); textures_manager->loadToTexture2DArray(&textures_maps, maps_size); qDebug() << "loaded" << textures_maps.layersCount() << "bitmaps"; } @@ -225,6 +225,7 @@ void RendererBase::reloadLightsParameters(const QMap> & ligh so.decay_intensity[1] = l->decay_linear; so.decay_intensity[2] = l->decay_quadratic; so.decay_intensity[3] = l->intensity; + so.size = l->size; so.flags = l->cast_shadow ? 1 : 0; } buffer_lights.bind(view); @@ -260,6 +261,11 @@ void RendererBase::markReloadTextures() { } +void RendererBase::markReloadMaterials() { + view->scene()->need_reload_materials = true; +} + + void RendererBase::setMapsSize(QSize sz) { maps_size = sz; markReloadTextures(); diff --git a/src/core/render/renderer_base.h b/src/core/render/renderer_base.h index a7edf0f..421aa87 100644 --- a/src/core/render/renderer_base.h +++ b/src/core/render/renderer_base.h @@ -43,6 +43,7 @@ protected: void reloadLightsParameters(const QMap> & lights); void reloadLightsPositions(Camera * cam); void markReloadTextures(); + void markReloadMaterials(); void setMapsSize(QSize sz); void initQuad(Mesh * mesh, QMatrix4x4 mat = QMatrix4x4()); void renderQuad(QOpenGLShaderProgram * prog, Mesh * mesh, Camera * cam = 0, bool uniforms = true); diff --git a/src/core/render/renderer_material.cpp b/src/core/render/renderer_material.cpp index 44bb27a..55881b0 100644 --- a/src/core/render/renderer_material.cpp +++ b/src/core/render/renderer_material.cpp @@ -78,7 +78,8 @@ void RendererMaterial::renderMaterial(Material * m) { r->textures_empty.bind(f, tarEmpty); r->textures_maps.bind(f, tarMaps); Object o; - o.material = m->_index; + o.material = m->_index; + o.f_accept_light = 1; mat_sphere->loadObject(f, o); mat_sphere->draw(f, 1); } diff --git a/src/core/scene/globject.cpp b/src/core/scene/globject.cpp index ceabf30..1c0142f 100644 --- a/src/core/scene/globject.cpp +++ b/src/core/scene/globject.cpp @@ -604,6 +604,7 @@ Light::Light(const QVector3D & p, const QColor & c, float i): AimedObject(), sha angle_start = angle_end = 90.; decay_linear = decay_quadratic = decay_start = 0.; decay_const = decay_end = 1.; + size = 0.1; setPos(p); setDirection(0, 0, -1.); } @@ -673,7 +674,8 @@ QDataStream & operator<<(QDataStream & s, const ObjectBase * p) { .add(107, l->decay_start) .add(108, l->decay_end) .add(109, int(l->light_type)) - .add(111, l->distance()); + .add(111, l->distance()) + .add(112, l->size); } if (p->type_ == ObjectBase::glCamera) { // qDebug() << "place camera ..."; @@ -792,6 +794,9 @@ QDataStream & operator>>(QDataStream & s, ObjectBase *& p) { case 111: if (l) l->setDistance(cs.getData()); break; + case 112: + if (l) l->size = cs.getData(); + break; case 200: if (c) c->setAim(cs.getData()); break; diff --git a/src/core/scene/globject.h b/src/core/scene/globject.h index a5f021e..4794bf0 100644 --- a/src/core/scene/globject.h +++ b/src/core/scene/globject.h @@ -423,6 +423,7 @@ public: float decay_quadratic; float decay_start; float decay_end; + float size; Type light_type; Framebuffer shadow_map; QMatrix4x4 shadow_matrix; diff --git a/src/core/view/qglview.cpp b/src/core/view/qglview.cpp index 8c2b653..5a932b5 100644 --- a/src/core/view/qglview.cpp +++ b/src/core/view/qglview.cpp @@ -32,17 +32,19 @@ using namespace QGLEngineShaders; QGLView::QGLView(): OpenGLWindow(), renderer_(this), mouse(this) { setIcon(QIcon(":/icons/qglview.png")); - is_init = false; - timer = 0; - hoverHaloColor_ = QColor(195, 140, 255); - selectionHaloColor_ = QColor(175, 255, 140); - lineWidth_ = 1.; - max_anisotropic = 1; - max_texture_chanels = 8; - lightEnabled_ = true; - shaders_supported = false; - FXAA_ = false; - fps_cnt = 0; + is_init = false; + timer = 0; + hoverHaloColor_ = QColor(195, 140, 255); + selectionHaloColor_ = QColor(175, 255, 140); + lineWidth_ = 1.; + max_anisotropic = 1; + max_texture_chanels = 8; + lightEnabled_ = true; + shaders_supported = false; + FXAA_ = false; + fps_cnt = 0; + soft_shadows_samples = 16; + soft_shadows = false; fps_tm = fps_ = 0.; fogColor_ = Qt::darkGray; fogDensity_ = 0.; @@ -267,3 +269,24 @@ void QGLView::restoreCamera(const QByteArray & ba) { camera()->setAngles(ang); camera()->setFOV(fov); } + + +void QGLView::setShadowMapSize(QSize sz) { + shadow_map_size = sz; +} + + +void QGLView::setTextureMapSize(QSize sz) { + renderer_.maps_size = sz; + renderer_.markReloadMaterials(); +} + + +QSize QGLView::shadowMapSize() const { + return shadow_map_size; +} + + +QSize QGLView::textureMapSize() const { + return renderer_.maps_size; +} diff --git a/src/core/view/qglview.h b/src/core/view/qglview.h index 7b42f82..24ad217 100644 --- a/src/core/view/qglview.h +++ b/src/core/view/qglview.h @@ -60,6 +60,10 @@ class QGLENGINE_CORE_EXPORT QGLView Q_PROPERTY(Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton) Q_PROPERTY(Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier) Q_PROPERTY(Scene::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) + Q_PROPERTY(QSize textureMapSize READ textureMapSize WRITE setTextureMapSize) + Q_PROPERTY(QSize shadowMapSize READ shadowMapSize WRITE setShadowMapSize) + Q_PROPERTY(int softShadowsSamples READ softShadowsSamples WRITE setSoftShadowsSamples) + Q_PROPERTY(bool softShadows READ softShadows WRITE setSoftShadows) public: QGLView(); @@ -157,6 +161,16 @@ public: bool isGrabImage() const { return renderer_.isGrabImage(); } QImage getImage() const { return renderer_.getImage(); } + void setShadowMapSize(QSize sz); + void setTextureMapSize(QSize sz); + QSize shadowMapSize() const; + QSize textureMapSize() const; + + int softShadowsSamples() const { return soft_shadows_samples; } + void setSoftShadowsSamples(int s) { soft_shadows_samples = s; } + bool softShadows() const { return soft_shadows; } + void setSoftShadows(bool on) { soft_shadows = on; } + GLfloat aspect, iaspect; Renderer renderer_; @@ -197,11 +211,11 @@ private: float lineWidth_; float fps_, fps_tm, fogDensity_, fogDecay_; float hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor; - int timer, fps_cnt, sh_id_loc; + int timer, fps_cnt, sh_id_loc, soft_shadows_samples; bool fogEnabled_, lightEnabled_, FXAA_; bool shaders_supported, shaders_bind; bool hoverHalo_, selectionHalo_; - bool is_init; + bool is_init, soft_shadows; private slots: void __destroyed(); diff --git a/src/widgets/object_editor.cpp b/src/widgets/object_editor.cpp index c33402f..8761109 100644 --- a/src/widgets/object_editor.cpp +++ b/src/widgets/object_editor.cpp @@ -51,7 +51,7 @@ ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) { ol.clear(); ol << ui->spinLightIntensity << ui->spinLightDecayConst << ui->spinLightDecayLinear << ui->spinLightDecayQuadratic - << ui->spinLightAngleStart << ui->spinLightAngleEnd << ui->spinAimDist; + << ui->spinLightAngleStart << ui->spinLightAngleEnd << ui->spinAimDist << ui->spinLightSize; foreach(QObject * o, ol) connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinLightChanged(double))); @@ -153,6 +153,7 @@ void ObjectEditor::setObject(ObjectBase * o) { ui->spinLightDecayQuadratic->setValue(l->decay_quadratic); ui->spinLightAngleStart->setValue(l->angle_start); ui->spinLightAngleEnd->setValue(l->angle_end); + ui->spinLightSize->setValue(l->size); ui->spinAimDist->setValue(l->distance()); on_comboLightType_currentIndexChanged(ui->comboLightType->currentIndex()); } @@ -253,6 +254,7 @@ void ObjectEditor::spinLightChanged(double v) { if (s == ui->spinLightAngleStart) o->angle_start = v; if (s == ui->spinLightAngleEnd) o->angle_end = v; if (s == ui->spinAimDist) o->setDistance(v); + if (s == ui->spinLightSize) o->size = v; o->apply(); } ignore_next = true; diff --git a/src/widgets/object_editor.ui b/src/widgets/object_editor.ui index f2eec89..e70961a 100644 --- a/src/widgets/object_editor.ui +++ b/src/widgets/object_editor.ui @@ -60,9 +60,9 @@ 0 - 0 + -287 444 - 1047 + 1081 @@ -700,13 +700,48 @@ + + + Size: + + + + + + + 0.000000000000000 + + + 999.000000000000000 + + + 0.100000000000000 + + + 3 + + + 0.100000000000000 + + + 1.000000000000000 + + + true + + + 999.000000000000000 + + + + Angle: - + diff --git a/src/widgets/view_editor.cpp b/src/widgets/view_editor.cpp index 3c5931d..0b85165 100644 --- a/src/widgets/view_editor.cpp +++ b/src/widgets/view_editor.cpp @@ -30,12 +30,15 @@ ViewEditor::ViewEditor(QWidget * parent): QWidget(parent) { ui->setupUi(this); ui->scrollArea->viewport()->setAutoFillBackground(false); ui->scrollAreaWidgetContents->setAutoFillBackground(false); - view = nullptr; - active = true; ui->checkCameraLight->setCheckState(Qt::PartiallyChecked); #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) ui->spinDepthStart->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType); #endif + for (int i = 6; i <= 13; ++i) { + QSize sz(pow2(i), pow2(i)); + ui->comboMapSizeTexture->addItem(QString::number(sz.width()), sz); + ui->comboMapSizeShadow->addItem(QString::number(sz.width()), sz); + } } @@ -45,8 +48,8 @@ void ViewEditor::assignQGLView(QGLView * v) { active = false; ui->spinFOV->setValue(view->FOV()); ui->spinDepthStart->setValue(view->depthStart()); - ui->groupHoverHalo->setChecked(view->isHoverHaloEnabled()); - ui->groupSelectionHalo->setChecked(view->isSelectionHaloEnabled()); + ui->checkHoverHalo->setChecked(view->isHoverHaloEnabled()); + ui->checkSelectionHalo->setChecked(view->isSelectionHaloEnabled()); ui->spinHoverHaloFill->setValue(view->hoverHaloFillAlpha()); ui->spinSelectionHaloFill->setValue(view->selectionHaloFillAlpha()); ui->colorHoverHalo->setColor(view->hoverHaloColor()); @@ -61,6 +64,18 @@ void ViewEditor::assignQGLView(QGLView * v) { ui->colorFogBack->setColor(view->fogColor()); ui->spinFogDecay->setValue(view->fogDecay()); ui->spinFogDensity->setValue(view->fogDensity()); + ui->checkSoftShadows->setChecked(view->softShadows()); + ui->spinSoftShadowSamples->setValue(view->softShadowsSamples()); + auto setMapSize = [](QComboBox * combo, QSize sz) { + for (int i = 0; i < combo->count(); ++i) { + if (combo->itemData(i).toSize() == sz) { + combo->setCurrentIndex(i); + break; + } + } + }; + setMapSize(ui->comboMapSizeTexture, view->textureMapSize()); + setMapSize(ui->comboMapSizeShadow, view->shadowMapSize()); active = true; } @@ -99,13 +114,20 @@ void ViewEditor::on_comboViewRenderMode_currentIndexChanged(int val) { } -void ViewEditor::on_groupHoverHalo_clicked(bool val) { +void ViewEditor::on_groupHalos_clicked(bool val) { + if (!view || !active) return; + view->setHoverHaloEnabled(val && ui->checkHoverHalo->isChecked()); + view->setSelectionHaloEnabled(val && ui->checkSelectionHalo->isChecked()); +} + + +void ViewEditor::on_checkHoverHalo_clicked(bool val) { if (!view || !active) return; view->setHoverHaloEnabled(val); } -void ViewEditor::on_groupSelectionHalo_clicked(bool val) { +void ViewEditor::on_checkSelectionHalo_clicked(bool val) { if (!view || !active) return; view->setSelectionHaloEnabled(val); } @@ -201,6 +223,30 @@ void ViewEditor::on_spinFogDecay_valueChanged(double arg1) { } +void ViewEditor::on_comboMapSizeTexture_currentIndexChanged(int index) { + if (!view || !active) return; + view->setTextureMapSize(ui->comboMapSizeTexture->itemData(index).toSize()); +} + + +void ViewEditor::on_comboMapSizeShadow_currentIndexChanged(int index) { + if (!view || !active) return; + view->setShadowMapSize(ui->comboMapSizeShadow->itemData(index).toSize()); +} + + +void ViewEditor::on_checkSoftShadows_clicked(bool arg1) { + if (!view || !active) return; + view->setSoftShadows(arg1); +} + + +void ViewEditor::on_spinSoftShadowSamples_valueChanged(double arg1) { + if (!view || !active) return; + view->setSoftShadowsSamples(arg1); +} + + void ViewEditor::on_checkVSync_clicked(bool val) { if (!view || !active) return; view->setVSync(val); diff --git a/src/widgets/view_editor.h b/src/widgets/view_editor.h index 6d8c1f9..75b9ce9 100644 --- a/src/widgets/view_editor.h +++ b/src/widgets/view_editor.h @@ -39,16 +39,17 @@ protected: void changeEvent(QEvent * e); Ui::ViewEditor * ui; - QGLView * view; - bool active; + QGLView * view = nullptr; + bool active = true; private slots: void on_spinFOV_valueChanged(double val); void on_spinDepthStart_valueChanged(double val); void on_spinViewGamma_valueChanged(double val); void on_comboViewRenderMode_currentIndexChanged(int val); - void on_groupHoverHalo_clicked(bool val); - void on_groupSelectionHalo_clicked(bool val); + void on_groupHalos_clicked(bool val); + void on_checkHoverHalo_clicked(bool val); + void on_checkSelectionHalo_clicked(bool val); void on_spinHoverHaloFill_valueChanged(double val); void on_spinSelectionHaloFill_valueChanged(double val); void on_colorHoverHalo_colorChanged(QColor color); @@ -64,6 +65,10 @@ private slots: void on_colorFogBack_colorChanged(const QColor & color); void on_spinFogDensity_valueChanged(double arg1); void on_spinFogDecay_valueChanged(double arg1); + void on_comboMapSizeTexture_currentIndexChanged(int index); + void on_comboMapSizeShadow_currentIndexChanged(int index); + void on_checkSoftShadows_clicked(bool arg1); + void on_spinSoftShadowSamples_valueChanged(double arg1); }; #endif // VIEW_EDITOR_H diff --git a/src/widgets/view_editor.ui b/src/widgets/view_editor.ui index 011de44..85a250b 100644 --- a/src/widgets/view_editor.ui +++ b/src/widgets/view_editor.ui @@ -36,8 +36,8 @@ 0 0 - 479 - 737 + 453 + 773 @@ -205,6 +205,43 @@ + + + + Soft shadows + + + true + + + + + + + + + + + Soft shadow samples: + + + + + + + 1.000000000000000 + + + 128.000000000000000 + + + 16.000000000000000 + + + 0 + + + @@ -291,22 +328,25 @@ - + - Hover halo + Halos true - - - + + + - Fill: + Hover: + + + true - + 0.000000000000000 @@ -328,7 +368,7 @@ - + @@ -342,26 +382,17 @@ - - - - - - - Selection halo - - - true - - - - + + - Fill: + Selection: + + + true - + 0.000000000000000 @@ -383,7 +414,7 @@ - + @@ -417,6 +448,9 @@ QFormLayout::AllNonFixedFieldsGrow + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + @@ -499,7 +533,7 @@ - Color + Color: @@ -508,6 +542,43 @@ + + + + Map sizes + + + + + + Textures: + + + + + + + -1 + + + + + + + Shadows: + + + + + + + -1 + + + + + +