git-svn-id: svn://db.shs.com.ru/libs@555 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2019-06-19 10:50:20 +00:00
parent 246e3e258c
commit 7eb0919657
16 changed files with 396 additions and 94 deletions

View File

@@ -3,8 +3,7 @@
#include <QVBoxLayout>
GLWidget::GLWidget(QWidget *parent) : QWidget(parent)
{
GLWidget::GLWidget(QWidget *parent) : QWidget(parent) {
view_ = new QGLView();
view_->setFlag(Qt::FramelessWindowHint);
container = QWidget::createWindowContainer(view_, this);
@@ -18,6 +17,187 @@ GLWidget::GLWidget(QWidget *parent) : QWidget(parent)
}
QColor GLWidget::backColor() const {
return view_->backColor();
}
float GLWidget::lineWidth() const {
return view_->lineWidth();
}
float GLWidget::FOV() const {
return view_->FOV();
}
float GLWidget::depthStart() const {
return view_->depthStart();
}
float GLWidget::depthEnd() const {
return view_->depthEnd();
}
QColor GLWidget::ambientColor() const {
return view_->ambientColor();
}
bool GLWidget::isLightEnabled() const {
return view_->isLightEnabled();
}
bool GLWidget::isGrabMouseEnabled() const {
return view_->isGrabMouseEnabled();
}
bool GLWidget::isMouseRotateEnabled() const {
return view_->isMouseRotateEnabled();
}
bool GLWidget::isMouseSelectionEnabled() const {
return view_->isMouseSelectionEnabled();
}
bool GLWidget::isCameraOrbit() const
{
return view_->isCameraOrbit();
}
bool GLWidget::isHoverHaloEnabled() const {
return view_->isHoverHaloEnabled();
}
QColor GLWidget::hoverHaloColor() const {
return view_->hoverHaloColor();
}
float GLWidget::hoverHaloFillAlpha() const {
return view_->hoverHaloFillAlpha();
}
bool GLWidget::isSelectionHaloEnabled() const {
return view_->isSelectionHaloEnabled();
}
QColor GLWidget::selectionHaloColor() const {
return view_->selectionHaloColor();
}
float GLWidget::selectionHaloFillAlpha() const {
return view_->selectionHaloFillAlpha();
}
void GLWidget::stop() {
return view_->stop();
}
void GLWidget::start(float freq) {
return view_->start(freq);
}
void GLWidget::setBackColor(const QColor & c) {
view_->setBackColor(c);
}
void GLWidget::setLineWidth(const float & arg) {
view_->setLineWidth(arg);
}
void GLWidget::setFOV(const float & arg) {
view_->setFOV(arg);
}
void GLWidget::setDepthStart(const float & arg) {
view_->setDepthStart(arg);
}
void GLWidget::setDepthEnd(const float & arg) {
view_->setDepthEnd(arg);
}
void GLWidget::setAmbientColor(const QColor & arg) {
view_->setAmbientColor(arg);
}
void GLWidget::setLightEnabled(const bool & arg) {
view_->setLightEnabled(arg);
}
void GLWidget::setGrabMouseEnabled(const bool & arg) {
view_->setGrabMouseEnabled(arg);
}
void GLWidget::setMouseRotateEnabled(const bool & arg) {
view_->setMouseRotateEnabled(arg);
}
void GLWidget::setMouseSelectionEnabled(const bool & arg) {
view_->setMouseSelectionEnabled(arg);
}
void GLWidget::setCameraOrbit(const bool & arg) {
view_->setCameraOrbit(arg);
}
void GLWidget::setHoverHaloEnabled(const bool & arg) {
view_->setHoverHaloEnabled(arg);
}
void GLWidget::setHoverHaloColor(const QColor & arg) {
view_->setHoverHaloColor(arg);
}
void GLWidget::setHoverHaloFillAlpha(const float & arg) {
view_->setHoverHaloFillAlpha(arg);
}
void GLWidget::setSelectionHaloEnabled(const bool & arg) {
view_->setSelectionHaloEnabled(arg);
}
void GLWidget::setSelectionHaloColor(const QColor & arg) {
view_->setSelectionHaloColor(arg);
}
void GLWidget::setSelectionHaloFillAlpha(const float & arg) {
view_->setSelectionHaloFillAlpha(arg);
}
void GLWidget::viewDoubleClicked() {
// qDebug() << "click widget!!";
if (view_->windowState() == Qt::WindowFullScreen) {

View File

@@ -9,11 +9,64 @@ class QGLView;
class GLWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor)
Q_PROPERTY (float lineWidth READ lineWidth WRITE setLineWidth)
Q_PROPERTY (float FOV READ FOV WRITE setFOV)
Q_PROPERTY (float depthStart READ depthStart WRITE setDepthStart)
Q_PROPERTY (float depthEnd READ depthEnd WRITE setDepthEnd)
Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor)
Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled)
Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled)
Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled)
Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit)
Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled)
Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor)
Q_PROPERTY (float hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha)
Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled)
Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor)
Q_PROPERTY (float selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
public:
explicit GLWidget(QWidget *parent = nullptr);
QGLView * view() {return view_;}
QColor backColor() const;
float lineWidth() const;
float FOV() const;
float depthStart() const;
float depthEnd() const;
QColor ambientColor() const;
bool isLightEnabled() const;
bool isGrabMouseEnabled() const;
bool isMouseRotateEnabled() const;
bool isMouseSelectionEnabled() const;
bool isCameraOrbit() const;
bool isHoverHaloEnabled() const;
QColor hoverHaloColor() const;
float hoverHaloFillAlpha() const;
bool isSelectionHaloEnabled() const;
QColor selectionHaloColor() const;
float selectionHaloFillAlpha() const;
public slots:
void stop();
void start(float freq = 60.);
void setBackColor(const QColor & c);
void setLineWidth(const float & arg);
void setFOV(const float & arg);
void setDepthStart(const float & arg);
void setDepthEnd(const float & arg);
void setAmbientColor(const QColor & arg);
void setLightEnabled(const bool & arg);
void setGrabMouseEnabled(const bool & arg);
void setMouseRotateEnabled(const bool & arg);
void setMouseSelectionEnabled(const bool & arg);
void setCameraOrbit(const bool & arg);
void setHoverHaloEnabled(const bool & arg);
void setHoverHaloColor(const QColor & arg);
void setHoverHaloFillAlpha(const float & arg);
void setSelectionHaloEnabled(const bool & arg);
void setSelectionHaloColor(const QColor & arg);
void setSelectionHaloFillAlpha(const float & arg);
private slots:
void viewDoubleClicked();

View File

@@ -24,12 +24,14 @@ bool QGLViewPlugin::isInitialized() const {
QWidget * QGLViewPlugin::createWidget(QWidget * parent) {
return new GLWidget(parent);
GLWidget * w = new GLWidget(parent);
//if (m_initialized) w->start();
return w;
}
QString QGLViewPlugin::name() const {
return QLatin1String("QGLView");
return QLatin1String("GLWidget");
}

View File

@@ -589,9 +589,9 @@ void QGLView::checkCaps() {
void QGLView::reloadThisShaders() {
if (!shaders_supported) return;
loadShaders(shader_select, "selection", "shaders");
loadShaders(shader_halo, "selection_halo", "shaders");
//loadShaders(shader_rope, "rope", "shaders");
loadShaders(shader_select, "selection", "://shaders");
loadShaders(shader_halo, "selection_halo", "://shaders");
//loadShaders(shader_rope, "rope", "://shaders");
}
void QGLView::glReleaseTextures(int channels) {

View File

@@ -26,5 +26,51 @@
<file>icons/edit-copy.png</file>
<file>icons/edit-paste.png</file>
<file>icons/qglview.png</file>
<file>shaders/bloom_0.frag</file>
<file>shaders/bloom_1.frag</file>
<file>shaders/bloom_pass_0.frag</file>
<file>shaders/bloom_pass_0.vert</file>
<file>shaders/bloom_pass_1.frag</file>
<file>shaders/bloom_pass_1.vert</file>
<file>shaders/downscale.frag</file>
<file>shaders/downscale.vert</file>
<file>shaders/dsl_pass_0.frag</file>
<file>shaders/dsl_pass_0.vert</file>
<file>shaders/dsl_pass_1.frag</file>
<file>shaders/dsl_pass_1.vert</file>
<file>shaders/dsl_pass_2.frag</file>
<file>shaders/dsl_pass_2.vert</file>
<file>shaders/fbo_add.frag</file>
<file>shaders/fbo_add.vert</file>
<file>shaders/FXAA.frag</file>
<file>shaders/FXAA.vert</file>
<file>shaders/hdr.frag</file>
<file>shaders/hdr.vert</file>
<file>shaders/hdr_scale_0.frag</file>
<file>shaders/hdr_scale_1.frag</file>
<file>shaders/light_models.frag</file>
<file>shaders/motion_blur.frag</file>
<file>shaders/motion_blur.vert</file>
<file>shaders/post.frag</file>
<file>shaders/ppl.frag</file>
<file>shaders/ppl.vert</file>
<file>shaders/selection.frag</file>
<file>shaders/selection.vert</file>
<file>shaders/selection_halo.frag</file>
<file>shaders/selection_halo.vert</file>
<file>shaders/shadow.frag</file>
<file>shaders/shadow.vert</file>
<file>shaders/ssao_blur.frag</file>
<file>shaders/ssao_blur.vert</file>
<file>shaders/ssao_merge.frag</file>
<file>shaders/ssao_merge.vert</file>
<file>shaders/ssr.frag</file>
<file>shaders/ssr.vert</file>
<file>shaders/ssr_blur.frag</file>
<file>shaders/ssr_blur.vert</file>
<file>shaders/ssr_merge.frag</file>
<file>shaders/ssr_merge.vert</file>
<file>shaders/dof.frag</file>
<file>shaders/dof.vert</file>
</qresource>
</RCC>

View File

@@ -539,7 +539,7 @@ void RendererDeferredShading::reloadShaders() {
for (int i = 0; i < shaders.size(); ++i) {
QOpenGLShaderProgram * p(*(shaders[i].second));
if (!p) p = new QOpenGLShaderProgram(view.context());
loadShaders(p, shaders[i].first, "shaders");
loadShaders(p, shaders[i].first, "://shaders");
*(shaders[i].second) = p;
}
}

View File

@@ -30,7 +30,7 @@ RendererSimple::RendererSimple(QGLView * view_): GLRendererBase(view_), fbo(2)
void RendererSimple::reloadShaders() {
if (shader_fxaa == 0) {
shader_fxaa = new QOpenGLShaderProgram(view.context());
loadShaders(shader_fxaa, "FXAA", "shaders");
loadShaders(shader_fxaa, "FXAA", "://shaders");
}
/*if (shader == 0) {
shader = new QOpenGLShaderProgram(view.context()); /// WARNING

47
qglview/shaders/dof.frag Normal file
View File

@@ -0,0 +1,47 @@
#version 150
uniform float z_near, z_far;
uniform sampler2D t0, td;
uniform vec2 dt;
uniform float radius, focus, diaphragm;
float w, sum;
const float _pe = 2.4e-7;
vec4 getTexel(vec2 c, float coeff) {
vec4 ret = texture(t0, c);
float cw = texture(td, c).r;
cw = clamp(1. - abs(cw - w) * 1000, 0., 1.) * coeff;
sum += cw;
return ret * cw;
}
void main(void) {
vec2 tc = qgl_FragTexture.xy;
vec4 scol = texture(t0, tc);
w = texture(td, tc).r;
float z = w + w - 1;
z = ((_pe - 2.) * z_near) / (z + _pe - 1.); // infinite depth
z = 1./(z + 1);
float cf = 1./(focus + 1);
float factor = clamp(abs(z - cf) * diaphragm, 0, 100);
factor = 1. - 1. / (factor + 1.);
factor *= factor;
factor *= factor;
//factor *= factor;
factor *= radius;
vec2 cdt = factor * dt;
sum = 1.;
scol += getTexel(tc + (cdt * 1), 2.5);
scol += getTexel(tc + (cdt * 2), 2.0);
scol += getTexel(tc + (cdt * 3), 1.5);
scol += getTexel(tc + (cdt * 4), 1.0);
scol += getTexel(tc + (cdt * 5), 0.5);
scol += getTexel(tc + (cdt * -1), 2.5);
scol += getTexel(tc + (cdt * -2), 2.0);
scol += getTexel(tc + (cdt * -3), 1.5);
scol += getTexel(tc + (cdt * -4), 1.0);
scol += getTexel(tc + (cdt * -5), 0.5);
scol /= sum;
qgl_FragData[0].rgba = scol;
}

6
qglview/shaders/dof.vert Normal file
View File

@@ -0,0 +1,6 @@
#version 150
void main(void) {
qgl_FragTexture = qgl_Texture;
gl_Position = qgl_ftransform();
}

View File

@@ -22,9 +22,11 @@ void main(void) {
float hei = dot(texture(qgl_Material.map_relief.map, tc).rgb, luma) * qgl_Material.map_relief.amount + qgl_Material.map_relief.offset;
vec3 n, dn, bn;
dn = (texture(qgl_Material.map_normal.map, tc).rgb - vec3(0.5, 0.5, 1.)) * qgl_Material.map_normal.amount + qgl_Material.map_normal.offset;
dn = texture(qgl_Material.map_normal.map, tc).rgb - vec3(0.5, 0.5, 1.);
dn = dn * qgl_Material.map_normal.amount + qgl_Material.map_normal.offset;
dn.y = -dn.y;
dn = TBN * dn;
//dn.z = 0;
n = normalize(qgl_NormalMatrix * (normal + dn));
bn = normalize(qgl_NormalMatrix * binormal);
//n = dn;

View File

@@ -34,57 +34,55 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
ldist = length(ldir);
ldir = normalize(ldir);
halfV = normalize(ldir + v);
NdotL = max(dot(n, ldir), 0.);
NdotH = max(dot(n, halfV), 0.);
NdotL = max(dot(n, ldir), 0.0001);
NdotH = max(dot(n, halfV), 0.0001);
spot = step(0., NdotL) * qgl_Light[index].intensity;
if (NdotL > 0.) {
if (qgl_Light[index].endAngle <= 90.) {
float scos = max(dot(-ldir, qgl_Light[index].direction.xyz), 0.);
spot *= scos * step(qgl_Light[index].endAngleCos, scos);
spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos);
lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz;
//bn = normalize(cross(lwdir, vec3(1, 0, 0)));
//bn2 = normalize(cross(lwdir, bn));
float ds = ldist/200.;//max(abs(sdist) / 5000, 0.02);
//spot *= clamp(1. - sdist, 0, 1);
vds = ds * bn.xyz;
vds2 = ds * bn2.xyz;
float shadow = getShadow(index, pos.xyz, vec3(0)) * 3. +
getShadow(index, pos.xyz, vds ) * 2. +
getShadow(index, pos.xyz, - vds ) * 2. +
getShadow(index, pos.xyz, - vds2 ) * 2. +
getShadow(index, pos.xyz, + vds2 ) * 2. +
getShadow(index, pos.xyz, vds - vds2 ) * 1.5 +
getShadow(index, pos.xyz, vds + vds2 ) * 1.5 +
getShadow(index, pos.xyz, - vds - vds2 ) * 1.5 +
getShadow(index, pos.xyz, - vds + vds2 ) * 1.5 +
getShadow(index, pos.xyz, vds + vds ) +
getShadow(index, pos.xyz, - vds - vds ) +
getShadow(index, pos.xyz, - vds2 - vds2) +
getShadow(index, pos.xyz, + vds2 + vds2) +
getShadow(index, pos.xyz, vds + vds - vds2 ) +
getShadow(index, pos.xyz, - vds - vds - vds2 ) +
getShadow(index, pos.xyz, vds + vds + vds2 ) +
getShadow(index, pos.xyz, - vds - vds + vds2 ) +
getShadow(index, pos.xyz, vds - vds2 - vds2) +
getShadow(index, pos.xyz, vds + vds2 + vds2) +
getShadow(index, pos.xyz, - vds - vds2 - vds2) +
getShadow(index, pos.xyz, - vds + vds2 + vds2);
spot *= mix(1., shadow / 29., shadow_on);
}
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
///li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n);
//si += spot * qgl_Light[index].color.rgb * sh_mul * light_specular(0, ldir, n, halfV, v, sh_pow);
float NdotLs = NdotL*NdotL;
float NdotHs = NdotH*NdotH;
float ndlc = (1. - NdotLs) / NdotLs;
float der = NdotLs * (sh_mul + ndlc);
diff = 2. / (1. + sqrt(1. + (1. - sh_mul) * ndlc));
li += spot * qgl_Light[index].color.rgb * diff;// * light_diffuse(0, ldir, n);
ndlc = (1. - NdotHs) / NdotHs;
der = NdotHs * (sh_mul + ndlc);
si += spot * qgl_Light[index].color.rgb * (sh_mul / (der*der) / 3.1416);
if (qgl_Light[index].endAngle <= 90.) {
float scos = max(dot(-ldir, qgl_Light[index].direction.xyz), 0.);
spot *= scos * step(qgl_Light[index].endAngleCos, scos);
spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos);
lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz;
//bn = normalize(cross(lwdir, vec3(1, 0, 0)));
//bn2 = normalize(cross(lwdir, bn));
float ds = ldist/200.;//max(abs(sdist) / 5000, 0.02);
//spot *= clamp(1. - sdist, 0, 1);
vds = ds * bn.xyz;
vds2 = ds * bn2.xyz;
float shadow = getShadow(index, pos.xyz, vec3(0)) * 3. +
getShadow(index, pos.xyz, vds ) * 2. +
getShadow(index, pos.xyz, - vds ) * 2. +
getShadow(index, pos.xyz, - vds2 ) * 2. +
getShadow(index, pos.xyz, + vds2 ) * 2. +
getShadow(index, pos.xyz, vds - vds2 ) * 1.5 +
getShadow(index, pos.xyz, vds + vds2 ) * 1.5 +
getShadow(index, pos.xyz, - vds - vds2 ) * 1.5 +
getShadow(index, pos.xyz, - vds + vds2 ) * 1.5 +
getShadow(index, pos.xyz, vds + vds ) +
getShadow(index, pos.xyz, - vds - vds ) +
getShadow(index, pos.xyz, - vds2 - vds2) +
getShadow(index, pos.xyz, + vds2 + vds2) +
getShadow(index, pos.xyz, vds + vds - vds2 ) +
getShadow(index, pos.xyz, - vds - vds - vds2 ) +
getShadow(index, pos.xyz, vds + vds + vds2 ) +
getShadow(index, pos.xyz, - vds - vds + vds2 ) +
getShadow(index, pos.xyz, vds - vds2 - vds2) +
getShadow(index, pos.xyz, vds + vds2 + vds2) +
getShadow(index, pos.xyz, - vds - vds2 - vds2) +
getShadow(index, pos.xyz, - vds + vds2 + vds2);
spot *= mix(1., shadow / 29., shadow_on);
}
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
///li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n);
//si += spot * qgl_Light[index].color.rgb * sh_mul * light_specular(0, ldir, n, halfV, v, sh_pow);
float NdotLs = NdotL*NdotL;
float NdotHs = NdotH*NdotH;
float ndlc = (1. - NdotLs) / NdotLs;
float der = NdotLs * (sh_mul + ndlc);
diff = 2. / (1. + sqrt(1. + (1. - sh_mul) * ndlc));
li += spot * qgl_Light[index].color.rgb * diff;// * light_diffuse(0, ldir, n);
ndlc = (1. - NdotHs) / NdotHs;
der = NdotHs * (sh_mul + ndlc);
si += spot * qgl_Light[index].color.rgb * (sh_mul / (der*der) / 3.1416);
}

View File

@@ -173,6 +173,7 @@ void main(void) {
}
if (acc_fog)
color.rgb = mix(color.rgb, gl_Fog.color.rgb, fogCoord);
color.r = 250;
gl_FragColor = color;
//gl_FragColor.rgb = mix(ldir, texture2D(t2, sp).rgb, 1. - alpha);
}

View File

@@ -13,8 +13,8 @@ void main(void) {
vec4 ds3 = abs(texelFetchOffset(t0, tc, 0, ivec2(0, 1)) - selected);
float d0 = dot(ds0, vec4(1., 1., 1., 1.)), d1 = dot(ds1, vec4(1., 1., 1., 1.)), d2 = dot(ds2, vec4(1., 1., 1., 1.)), d3 = dot(ds3, vec4(1., 1., 1., 1.));
float vs = step(1e-6, d0 + d1 + d2 + d3);
float vm = step(1e-3, (d0 * 255.) * (d1 * 255.) * (d2 * 255.) * (d3 * 255.));
float vm = step(1e-3, (d0 * 25.) * (d1 * 25.) * (d2 * 255.) * (d3 * 255.));
float v = mix(vs - vm, vs - vm - vm + 1, fill);
//qgl_FragData[0] = vec4(1,0,0,0.5);//vec4(color.rgb, v * color.a);
qgl_FragData[0] = vec4(color.rgb, v * color.a);
qgl_FragData[0] = vec4(color.bgr, v * color.a);
}

View File

@@ -1,9 +0,0 @@
#version 200
//in vec3 src_normal, normal, et;
in vec3 wpos;
void main(void) {
//vec2 tc = gl_TexCoord[0].xy;
gl_FragColor.xyz = wpos * 1E+6;
}

View File

@@ -1,13 +0,0 @@
#version 300 core
layout(triangles, invocations = 1) in;
//in vec3 normal[];
void main() {
for (int i = 0; i < gl_in.length(); i++ ) {
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}

View File

@@ -1,11 +0,0 @@
#version 300 core
//in vec3 src_normal, normal, et;
out vec3 wpos;
void main(void) {
//vec2 tc = gl_TexCoord[0].xy;
wpos = gl_Vertex.xyz;
//gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}