shadows flag in Renderer #2
@@ -16,20 +16,23 @@ void main(void) {
|
|||||||
|
|
||||||
in vec3 view_dir, world_dir;
|
in vec3 view_dir, world_dir;
|
||||||
|
|
||||||
uniform vec2 dt, shadow_size;
|
uniform vec2 dt;
|
||||||
uniform float z_near;
|
uniform float z_near;
|
||||||
uniform sampler2D tex_coeff_brdf, tex_noise;
|
uniform sampler2D tex_coeff_brdf, tex_noise;
|
||||||
uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4, tex_5, tex_sh;
|
uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4, tex_5, tex_sh;
|
||||||
//uniform sampler2DShadow tex_shadow[16];
|
//uniform sampler2DShadow tex_shadow[16];
|
||||||
|
#ifdef SHADOWS
|
||||||
|
uniform vec2 shadow_size;
|
||||||
uniform sampler2DArrayShadow tex_shadows_cone;
|
uniform sampler2DArrayShadow tex_shadows_cone;
|
||||||
uniform sampler2DArray tex_depths_cone;
|
uniform sampler2DArray tex_depths_cone;
|
||||||
uniform samplerCubeArrayShadow tex_shadows_omni;
|
uniform samplerCubeArrayShadow tex_shadows_omni;
|
||||||
uniform samplerCubeArray tex_depths_omni;
|
uniform samplerCubeArray tex_depths_omni;
|
||||||
uniform samplerCube tex_env;
|
|
||||||
uniform int lights_start, lights_count, soft_shadows_samples = 16, noise_size = 64;
|
|
||||||
uniform bool soft_shadows_enabled = false;
|
uniform bool soft_shadows_enabled = false;
|
||||||
uniform float soft_shadows_quality = 1.;
|
uniform float soft_shadows_quality = 1.;
|
||||||
|
uniform int soft_shadows_samples = 16, noise_size = 64;
|
||||||
|
#endif
|
||||||
|
uniform samplerCube tex_env;
|
||||||
|
uniform int lights_start, lights_count;
|
||||||
uniform vec4 fog_color = vec4(0.5, 0.5, 0.5, 1.);
|
uniform vec4 fog_color = vec4(0.5, 0.5, 0.5, 1.);
|
||||||
uniform float fog_decay = 10., fog_density = 0.;
|
uniform float fog_decay = 10., fog_density = 0.;
|
||||||
uniform mat3 view_mat;
|
uniform mat3 view_mat;
|
||||||
@@ -43,7 +46,7 @@ ivec2 tc;
|
|||||||
vec4 pos, lpos, shp;
|
vec4 pos, lpos, shp;
|
||||||
vec3 li, si, ldir, halfV, bn, bn2, lwdir;
|
vec3 li, si, ldir, halfV, bn, bn2, lwdir;
|
||||||
vec3 normal, geom_normal, vds, vds2;
|
vec3 normal, geom_normal, vds, vds2;
|
||||||
float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist, shadow, shadow_dz;
|
float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist;
|
||||||
uint flags;
|
uint flags;
|
||||||
|
|
||||||
|
|
||||||
@@ -54,6 +57,7 @@ vec4 mapScreenToShadow(in int light_index, in vec3 offset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SHADOWS
|
||||||
#ifdef SPOT
|
#ifdef SPOT
|
||||||
|
|
||||||
float getShadowCone(in vec3 uvz, in int layer) {
|
float getShadowCone(in vec3 uvz, in int layer) {
|
||||||
@@ -141,6 +145,7 @@ float rand(vec2 co) {
|
|||||||
float e = sin(mod(d, 3.14)) * c;
|
float e = sin(mod(d, 3.14)) * c;
|
||||||
return fract(e) - 0.5;
|
return fract(e) - 0.5;
|
||||||
}
|
}
|
||||||
|
#endif // SHADOWS
|
||||||
|
|
||||||
vec4 qgl_lightTexture(int index, vec2 coord, vec4 tex_shift) {
|
vec4 qgl_lightTexture(int index, vec2 coord, vec4 tex_shift) {
|
||||||
coord *= qgl_light_parameter[index].map.scale;
|
coord *= qgl_light_parameter[index].map.scale;
|
||||||
@@ -173,6 +178,7 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
|||||||
spot *= light_map_pix.a;
|
spot *= light_map_pix.a;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SHADOWS
|
||||||
if (int(round(qgl_light_parameter[index].flags)) == 1 && bitfieldExtract(flags, 3, 1) == 1 && (spot > 1E-4)) {
|
if (int(round(qgl_light_parameter[index].flags)) == 1 && bitfieldExtract(flags, 3, 1) == 1 && (spot > 1E-4)) {
|
||||||
#ifndef SPOT
|
#ifndef SPOT
|
||||||
vec3 odir = -(view_mat * ldir);
|
vec3 odir = -(view_mat * ldir);
|
||||||
@@ -260,6 +266,7 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
|||||||
//shadow += getShadowCone(shp.xyz, layer, vec2(0));
|
//shadow += getShadowCone(shp.xyz, layer, vec2(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif // SHADOWS
|
||||||
|
|
||||||
vec3 dist_decay = vec3(1., ldist, ldist*ldist);
|
vec3 dist_decay = vec3(1., ldist, ldist*ldist);
|
||||||
spot /= dot(qgl_light_parameter[index].decay_intensity.xyz, dist_decay);
|
spot /= dot(qgl_light_parameter[index].decay_intensity.xyz, dist_decay);
|
||||||
|
|||||||
@@ -99,6 +99,8 @@ Renderer::Renderer(QGLView * view_)
|
|||||||
shader_defines[srGeometrySolidPass] << "SOLID";
|
shader_defines[srGeometrySolidPass] << "SOLID";
|
||||||
shader_defines[srLightSpotPass] << "SPOT";
|
shader_defines[srLightSpotPass] << "SPOT";
|
||||||
shader_defines[srShadowOmniPass] << "OMNI";
|
shader_defines[srShadowOmniPass] << "OMNI";
|
||||||
|
shader_defines[srLightSpotPass] << "SHADOWS";
|
||||||
|
shader_defines[srLightOmniPass] << "SHADOWS";
|
||||||
|
|
||||||
PICodeInfo::EnumInfo * obre = PICodeInfo::enumsInfo->value("Renderer::DeferredBufferRole");
|
PICodeInfo::EnumInfo * obre = PICodeInfo::enumsInfo->value("Renderer::DeferredBufferRole");
|
||||||
if (obre) {
|
if (obre) {
|
||||||
@@ -352,6 +354,7 @@ void Renderer::renderLight(int first_wr_buff, bool clear_only) {
|
|||||||
prog->setUniformValue("fog_decay", qMax(view->fogDecay(), 0.001f));
|
prog->setUniformValue("fog_decay", qMax(view->fogDecay(), 0.001f));
|
||||||
prog->setUniformValue("fog_density", view->fogDensity());
|
prog->setUniformValue("fog_density", view->fogDensity());
|
||||||
prog->setUniformValue("view_mat", cam->viewMatrix().inverted().toGenericMatrix<3, 3>());
|
prog->setUniformValue("view_mat", cam->viewMatrix().inverted().toGenericMatrix<3, 3>());
|
||||||
|
if (shadows_enabled) {
|
||||||
prog->setUniformValue("shadow_size", view->shadow_map_size);
|
prog->setUniformValue("shadow_size", view->shadow_map_size);
|
||||||
prog->setUniformValue("noise_size", noise_size);
|
prog->setUniformValue("noise_size", noise_size);
|
||||||
prog->setUniformValue("soft_shadows_enabled", view->soft_shadows);
|
prog->setUniformValue("soft_shadows_enabled", view->soft_shadows);
|
||||||
@@ -370,6 +373,7 @@ void Renderer::renderLight(int first_wr_buff, bool clear_only) {
|
|||||||
view->glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, filter);
|
view->glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, filter);
|
||||||
depth_maps_cone.bind(view, tarDepthsCone);
|
depth_maps_cone.bind(view, tarDepthsCone);
|
||||||
depth_maps_omni.bind(view, tarDepthsOmni);
|
depth_maps_omni.bind(view, tarDepthsOmni);
|
||||||
|
}
|
||||||
renderQuad(prog, quad, cam);
|
renderQuad(prog, quad, cam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -522,6 +526,7 @@ void Renderer::renderScene() {
|
|||||||
}
|
}
|
||||||
phase.end();
|
phase.end();
|
||||||
|
|
||||||
|
if (shadows_enabled) {
|
||||||
/// cone shadows and shadow matrix
|
/// cone shadows and shadow matrix
|
||||||
phase.begin("shadows cone");
|
phase.begin("shadows cone");
|
||||||
renderConeShadows();
|
renderConeShadows();
|
||||||
@@ -531,6 +536,7 @@ void Renderer::renderScene() {
|
|||||||
phase.begin("shadows omni");
|
phase.begin("shadows omni");
|
||||||
renderOmniShadows();
|
renderOmniShadows();
|
||||||
phase.end();
|
phase.end();
|
||||||
|
}
|
||||||
|
|
||||||
/// lights
|
/// lights
|
||||||
phase.begin("lights prepare");
|
phase.begin("lights prepare");
|
||||||
@@ -729,3 +735,14 @@ void Renderer::addFramebufferEffect(FramebufferEffectBase * e) {
|
|||||||
e->r = this;
|
e->r = this;
|
||||||
fb_effects << e;
|
fb_effects << e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::setSadowsEnabled(bool on) {
|
||||||
|
shader_defines[srLightSpotPass].removeAll("SHADOWS");
|
||||||
|
shader_defines[srLightOmniPass].removeAll("SHADOWS");
|
||||||
|
if (on) {
|
||||||
|
shader_defines[srLightSpotPass] << "SHADOWS";
|
||||||
|
shader_defines[srLightOmniPass] << "SHADOWS";
|
||||||
|
}
|
||||||
|
shadows_enabled = on;
|
||||||
|
reloadShaders();
|
||||||
|
}
|
||||||
|
|||||||
@@ -110,6 +110,9 @@ public:
|
|||||||
QImage materialThumbnail(Material * m) { return rend_mat.materialThumbnail(m); }
|
QImage materialThumbnail(Material * m) { return rend_mat.materialThumbnail(m); }
|
||||||
void recreateMaterialThumbnails(bool force_all = false) { rend_mat.recreateMaterialThumbnails(force_all); }
|
void recreateMaterialThumbnails(bool force_all = false) { rend_mat.recreateMaterialThumbnails(force_all); }
|
||||||
|
|
||||||
|
void setSadowsEnabled(bool on);
|
||||||
|
bool isShadowsEnabled() const { return shadows_enabled; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass);
|
void fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass);
|
||||||
void renderObjects(Scene & scene, RenderPass pass);
|
void renderObjects(Scene & scene, RenderPass pass);
|
||||||
@@ -157,6 +160,7 @@ private:
|
|||||||
QVector<FramebufferEffectBase *> fb_effects;
|
QVector<FramebufferEffectBase *> fb_effects;
|
||||||
QImage last_img;
|
QImage last_img;
|
||||||
QString obr_defines, timings;
|
QString obr_defines, timings;
|
||||||
|
bool shadows_enabled = true;
|
||||||
bool is_grabbing = false;
|
bool is_grabbing = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user