nvidia fix, soft shadows

This commit is contained in:
2023-02-13 18:35:25 +03:00
parent c8dcd5e9c0
commit 36540468dc
17 changed files with 358 additions and 107 deletions

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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"

View File

@@ -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); }

View File

@@ -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<Renderer::ShaderRole, Light::Type> PassPair;
QVector<PassPair> 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());
}*/
}
*/
}

View File

@@ -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<int, QList<Light *>> & 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();

View File

@@ -43,6 +43,7 @@ protected:
void reloadLightsParameters(const QMap<int, QList<Light *>> & 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);

View File

@@ -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);
}

View File

@@ -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<double>());
break;
case 112:
if (l) l->size = cs.getData<double>();
break;
case 200:
if (c) c->setAim(cs.getData<QVector3D>());
break;

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -60,9 +60,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-287</y>
<width>444</width>
<height>1047</height>
<height>1081</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -700,13 +700,48 @@
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="SpinSlider" name="spinLightSize">
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>999.000000000000000</double>
</property>
<property name="value">
<double>0.100000000000000</double>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="pageStep">
<double>1.000000000000000</double>
</property>
<property name="squareScale">
<bool>true</bool>
</property>
<property name="spinMaximum">
<double>999.000000000000000</double>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelLightAngle">
<property name="text">
<string>Angle:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">

View File

@@ -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);

View File

@@ -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

View File

@@ -36,8 +36,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>479</width>
<height>737</height>
<width>453</width>
<height>773</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -205,6 +205,43 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkSoftShadows">
<property name="text">
<string>Soft shadows</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>Soft shadow samples:</string>
</property>
</widget>
</item>
<item>
<widget class="SpinSlider" name="spinSoftShadowSamples">
<property name="minimum">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>128.000000000000000</double>
</property>
<property name="value">
<double>16.000000000000000</double>
</property>
<property name="decimals">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -291,22 +328,25 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupHoverHalo">
<widget class="QGroupBox" name="groupHalos">
<property name="title">
<string>Hover halo</string>
<string>Halos</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_11">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QCheckBox" name="checkHoverHalo">
<property name="text">
<string>Fill:</string>
<string>Hover:</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<widget class="SpinSlider" name="spinHoverHaloFill">
<property name="minimum">
<double>0.000000000000000</double>
@@ -328,7 +368,7 @@
</property>
</widget>
</item>
<item>
<item row="0" column="2">
<widget class="ColorButton" name="colorHoverHalo">
<property name="color">
<color>
@@ -342,26 +382,17 @@
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupSelectionHalo">
<property name="title">
<string>Selection halo</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_20">
<item row="1" column="0">
<widget class="QCheckBox" name="checkSelectionHalo">
<property name="text">
<string>Fill:</string>
<string>Selection:</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<item row="1" column="1">
<widget class="SpinSlider" name="spinSelectionHaloFill">
<property name="minimum">
<double>0.000000000000000</double>
@@ -383,7 +414,7 @@
</property>
</widget>
</item>
<item>
<item row="1" column="2">
<widget class="ColorButton" name="colorSelectionHalo">
<property name="color">
<color>
@@ -417,6 +448,9 @@
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
@@ -499,7 +533,7 @@
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Color</string>
<string>Color:</string>
</property>
</widget>
</item>
@@ -508,6 +542,43 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Map sizes</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Textures:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboMapSizeTexture">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Shadows:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboMapSizeShadow">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">