fix deferred rendering on macbook air

This commit is contained in:
SamGondelman 2019-06-18 17:17:21 -07:00
parent 99feabd4c9
commit 3ff81607ab
4 changed files with 14 additions and 55 deletions

View file

@ -37,7 +37,6 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness
_fragColor0 = vec4(albedo, mix(packShadedMetallic(metallic), packScatteringMetallic(metallic), check));
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
_fragColor2 = vec4(mix(emissive, vec3(scattering), check), occlusion);
_fragColor3 = vec4(isEmissiveEnabled() * emissive, 1.0);
}
@ -49,7 +48,6 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float r
_fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
_fragColor2 = vec4(isLightmapEnabled() * lightmap, 1.0);
_fragColor3 = vec4(isLightmapEnabled() * lightmap * albedo, 1.0);
}
@ -59,7 +57,7 @@ void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {
}
_fragColor0 = vec4(color, packUnlit());
_fragColor1 = vec4(packNormal(normal), 1.0);
// _fragColor2 = vec4(vec3(0.0), 1.0);
_fragColor2 = vec4(vec3(0.0), 1.0);
_fragColor3 = vec4(color, 1.0);
}
@ -69,7 +67,8 @@ void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, floa
}
_fragColor0 = vec4(albedo.rgb, alpha);
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
_fragColor2 = vec4(vec3(0.0), 1.0);
_fragColor3 = vec4(0.0);
}
<@endif@>

View file

@ -41,33 +41,17 @@ namespace gr {
using namespace render;
struct LightLocations {
bool shadowTransform{ false };
void initialize(const gpu::ShaderPointer& program) {
shadowTransform = program->getReflection().validUniformBuffer(ru::Buffer::ShadowParams);
}
};
static void loadLightProgram(int programId, bool lightVolume, gpu::PipelinePointer& program, LightLocationsPtr& locations);
static void loadLightProgram(int programId, bool lightVolume, gpu::PipelinePointer& program);
void DeferredLightingEffect::init() {
_directionalAmbientSphereLightLocations = std::make_shared<LightLocations>();
_directionalSkyboxLightLocations = std::make_shared<LightLocations>();
loadLightProgram(shader::render_utils::program::directional_ambient_light, false, _directionalAmbientSphereLight);
loadLightProgram(shader::render_utils::program::directional_skybox_light, false, _directionalSkyboxLight);
_directionalAmbientSphereLightShadowLocations = std::make_shared<LightLocations>();
_directionalSkyboxLightShadowLocations = std::make_shared<LightLocations>();
loadLightProgram(shader::render_utils::program::directional_ambient_light_shadow, false, _directionalAmbientSphereLightShadow);
loadLightProgram(shader::render_utils::program::directional_skybox_light_shadow, false, _directionalSkyboxLightShadow);
_localLightLocations = std::make_shared<LightLocations>();
_localLightOutlineLocations = std::make_shared<LightLocations>();
loadLightProgram(shader::render_utils::program::directional_ambient_light, false, _directionalAmbientSphereLight, _directionalAmbientSphereLightLocations);
loadLightProgram(shader::render_utils::program::directional_skybox_light, false, _directionalSkyboxLight, _directionalSkyboxLightLocations);
loadLightProgram(shader::render_utils::program::directional_ambient_light_shadow, false, _directionalAmbientSphereLightShadow, _directionalAmbientSphereLightShadowLocations);
loadLightProgram(shader::render_utils::program::directional_skybox_light_shadow, false, _directionalSkyboxLightShadow, _directionalSkyboxLightShadowLocations);
loadLightProgram(shader::render_utils::program::local_lights_shading, true, _localLight, _localLightLocations);
loadLightProgram(shader::render_utils::program::local_lights_drawOutline, true, _localLightOutline, _localLightOutlineLocations);
loadLightProgram(shader::render_utils::program::local_lights_shading, true, _localLight);
loadLightProgram(shader::render_utils::program::local_lights_drawOutline, true, _localLightOutline);
}
// FIXME: figure out how to move lightFrame into a varying in GeometryCache and RenderPipelines
@ -123,15 +107,9 @@ void DeferredLightingEffect::unsetLocalLightsBatch(gpu::Batch& batch) {
batch.setUniformBuffer(ru::Buffer::LightClusterFrustumGrid, nullptr);
}
static gpu::ShaderPointer makeLightProgram(int programId, LightLocationsPtr& locations) {
static void loadLightProgram(int programId, bool lightVolume, gpu::PipelinePointer& pipeline) {
gpu::ShaderPointer program = gpu::Shader::createProgram(programId);
locations->initialize(program);
return program;
}
static void loadLightProgram(int programId, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) {
gpu::ShaderPointer program = makeLightProgram(programId, locations);
auto state = std::make_shared<gpu::State>();
state->setColorWriteMask(true, true, true, false);
@ -456,7 +434,6 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext,
// Setup the global directional pass pipeline
auto program = deferredLightingEffect->_directionalSkyboxLight;
LightLocationsPtr locations = deferredLightingEffect->_directionalSkyboxLightLocations;
{
if (keyLightCastShadows) {
@ -464,20 +441,16 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext,
// otherwise use the ambient sphere version
if (hasAmbientMap) {
program = deferredLightingEffect->_directionalSkyboxLightShadow;
locations = deferredLightingEffect->_directionalSkyboxLightShadowLocations;
} else {
program = deferredLightingEffect->_directionalAmbientSphereLightShadow;
locations = deferredLightingEffect->_directionalAmbientSphereLightShadowLocations;
}
} else {
// If the keylight has an ambient Map then use the Skybox version of the pass
// otherwise use the ambient sphere version
if (hasAmbientMap) {
program = deferredLightingEffect->_directionalSkyboxLight;
locations = deferredLightingEffect->_directionalSkyboxLightLocations;
} else {
program = deferredLightingEffect->_directionalAmbientSphereLight;
locations = deferredLightingEffect->_directionalAmbientSphereLightLocations;
}
}

View file

@ -37,10 +37,6 @@
#include "SubsurfaceScattering.h"
#include "AmbientOcclusionEffect.h"
struct LightLocations;
using LightLocationsPtr = std::shared_ptr<LightLocations>;
// THis is where we currently accumulate the local lights, let s change that sooner than later
class DeferredLightingEffect : public Dependency {
SINGLETON_DEPENDENCY
@ -72,15 +68,6 @@ private:
gpu::PipelinePointer _localLight;
gpu::PipelinePointer _localLightOutline;
LightLocationsPtr _directionalSkyboxLightLocations;
LightLocationsPtr _directionalAmbientSphereLightLocations;
LightLocationsPtr _directionalSkyboxLightShadowLocations;
LightLocationsPtr _directionalAmbientSphereLightShadowLocations;
LightLocationsPtr _localLightLocations;
LightLocationsPtr _localLightOutlineLocations;
friend class LightClusteringPass;
friend class RenderDeferredSetup;
friend class RenderDeferredLocals;

View file

@ -18,7 +18,7 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) out vec4 _texCoord01;
void main(void) {
const float depth = 1.0;
const vec4 UNIT_QUAD[4] = vec4[4](
const mat4 UNIT_QUAD = mat4(
vec4(-1.0, -1.0, depth, 1.0),
vec4(1.0, -1.0, depth, 1.0),
vec4(-1.0, 1.0, depth, 1.0),
@ -26,7 +26,7 @@ void main(void) {
);
vec4 pos = UNIT_QUAD[gl_VertexID];
_texCoord01.xy = (pos.xy + 1.0) * 0.5;
_texCoord01 = vec4((pos.xy + 1.0) * 0.5, 0.0, 0.0);
gl_Position = pos;
}