Also fixes the shading on web entities using that program
Showing the changes to libraries/render-utils/src/DeferredLightingEffect.cpp (1 of 4 files). Show all
Unified · Split
| @@ -27,8 +27,8 @@ · 26 unmodified lines | |||
| 27 | #include "gpu/GLBackend.h" | 27 | #include "gpu/GLBackend.h" |
| 28 | 28 | ||
| 29 | #include "simple_vert.h" | 29 | #include "simple_vert.h" |
| 30 | #include "simple_frag.h" | ||
| 31 | #include "simple_textured_frag.h" | 30 | #include "simple_textured_frag.h" |
| 31 | #include "simple_textured_emisive_frag.h" | ||
| 32 | 32 | ||
| 33 | #include "deferred_light_vert.h" | 33 | #include "deferred_light_vert.h" |
| 34 | #include "deferred_light_limited_vert.h" | 34 | #include "deferred_light_limited_vert.h" |
| @@ -52,15 +52,15 @@ static const std::string glowIntensityShaderHandle = "glowIntensity"; · 17 unmodified lines | |||
| 52 | 52 | ||
| 53 | void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { | 53 | void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { |
| 54 | auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(simple_vert))); | 54 | auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(simple_vert))); |
| 55 | auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_frag))); | 55 | auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_textured_frag))); |
| 56 | auto PSTextured = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_textured_frag))); | 56 | auto PSEmissive = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_textured_emisive_frag))); |
| 57 | 57 | ||
| 58 | gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PS)); | 58 | gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PS)); |
| 59 | gpu::ShaderPointer programTextured = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PSTextured)); | 59 | gpu::ShaderPointer programEmissive = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PSEmissive)); |
| 60 | 60 | ||
| 61 | gpu::Shader::BindingSet slotBindings; | 61 | gpu::Shader::BindingSet slotBindings; |
| 62 | gpu::Shader::makeProgram(*program, slotBindings); | 62 | gpu::Shader::makeProgram(*program, slotBindings); |
| 63 | gpu::Shader::makeProgram(*programTextured, slotBindings); | 63 | gpu::Shader::makeProgram(*programEmissive, slotBindings); |
| 64 | 64 | ||
| 65 | gpu::StatePointer state = gpu::StatePointer(new gpu::State()); | 65 | gpu::StatePointer state = gpu::StatePointer(new gpu::State()); |
| 66 | state->setCullMode(gpu::State::CULL_BACK); | 66 | state->setCullMode(gpu::State::CULL_BACK); |
| @@ -79,8 +79,8 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { · 12 unmodified lines | |||
| 79 | 79 | ||
| 80 | _simpleProgram = gpu::PipelinePointer(gpu::Pipeline::create(program, state)); | 80 | _simpleProgram = gpu::PipelinePointer(gpu::Pipeline::create(program, state)); |
| 81 | _simpleProgramCullNone = gpu::PipelinePointer(gpu::Pipeline::create(program, stateCullNone)); | 81 | _simpleProgramCullNone = gpu::PipelinePointer(gpu::Pipeline::create(program, stateCullNone)); |
| 82 | _simpleProgramTextured = gpu::PipelinePointer(gpu::Pipeline::create(programTextured, state)); | 82 | _simpleProgramEmissive = gpu::PipelinePointer(gpu::Pipeline::create(programEmissive, state)); |
| 83 | _simpleProgramTexturedCullNone = gpu::PipelinePointer(gpu::Pipeline::create(programTextured, stateCullNone)); | 83 | _simpleProgramEmissiveCullNone = gpu::PipelinePointer(gpu::Pipeline::create(programEmissive, stateCullNone)); |
| 84 | 84 | ||
| 85 | _viewState = viewState; | 85 | _viewState = viewState; |
| 86 | loadLightProgram(directional_light_frag, false, _directionalLight, _directionalLightLocations); | 86 | loadLightProgram(directional_light_frag, false, _directionalLight, _directionalLightLocations); |
| @@ -117,14 +117,12 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { · 30 unmodified lines | |||
| 117 | lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset(_ambientLightMode % gpu::SphericalHarmonics::NUM_PRESET)); | 117 | lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset(_ambientLightMode % gpu::SphericalHarmonics::NUM_PRESET)); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled) { | 120 | void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, bool emmisive) { |
| 121 | // DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(batch, true, true, true); | 121 | if (emmisive) { |
| 122 | |||
| 123 | if (textured) { | ||
| 124 | if (culled) { | 122 | if (culled) { |
| 125 | batch.setPipeline(_simpleProgramTextured); | 123 | batch.setPipeline(_simpleProgramEmissive); |
| 126 | } else { | 124 | } else { |
| 127 | batch.setPipeline(_simpleProgramTexturedCullNone); | 125 | batch.setPipeline(_simpleProgramEmissiveCullNone); |
| 128 | } | 126 | } |
| 129 | } else { | 127 | } else { |
| 130 | if (culled) { | 128 | if (culled) { |
| @@ -133,48 +131,42 @@ void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured, · 2 unmodified lines | |||
| 133 | batch.setPipeline(_simpleProgramCullNone); | 131 | batch.setPipeline(_simpleProgramCullNone); |
| 134 | } | 132 | } |
| 135 | } | 133 | } |
| 136 | } | 134 | if (!textured) { |
| 137 | 135 | // If it is not textured, bind white texture and keep using textured pipeline | |
| 138 | void DeferredLightingEffect::releaseSimpleProgram(gpu::Batch& batch) { | 136 | batch.setUniformTexture(0, DependencyManager::get<TextureCache>()->getWhiteTexture()); |
| 139 | // DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(batch, true, false, false); | 137 | } |
| 140 | } | 138 | } |
| 141 | 139 | ||
| 142 | void DeferredLightingEffect::renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { | 140 | void DeferredLightingEffect::renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { |
| 143 | bindSimpleProgram(batch); | 141 | bindSimpleProgram(batch); |
| 144 | DependencyManager::get<GeometryCache>()->renderSphere(batch, radius, slices, stacks, color); | 142 | DependencyManager::get<GeometryCache>()->renderSphere(batch, radius, slices, stacks, color); |
| 145 | releaseSimpleProgram(batch); | ||
| 146 | } | 143 | } |
| 147 | 144 | ||
| 148 | void DeferredLightingEffect::renderWireSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { | 145 | void DeferredLightingEffect::renderWireSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { |
| 149 | bindSimpleProgram(batch); | 146 | bindSimpleProgram(batch); |
| 150 | DependencyManager::get<GeometryCache>()->renderSphere(batch, radius, slices, stacks, color, false); | 147 | DependencyManager::get<GeometryCache>()->renderSphere(batch, radius, slices, stacks, color, false); |
| 151 | releaseSimpleProgram(batch); | ||
| 152 | } | 148 | } |
| 153 | 149 | ||
| 154 | void DeferredLightingEffect::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) { | 150 | void DeferredLightingEffect::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) { |
| 155 | bindSimpleProgram(batch); | 151 | bindSimpleProgram(batch); |
| 156 | DependencyManager::get<GeometryCache>()->renderSolidCube(batch, size, color); | 152 | DependencyManager::get<GeometryCache>()->renderSolidCube(batch, size, color); |
| 157 | releaseSimpleProgram(batch); | ||
| 158 | } | 153 | } |
| 159 | 154 | ||
| 160 | void DeferredLightingEffect::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) { | 155 | void DeferredLightingEffect::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) { |
| 161 | bindSimpleProgram(batch); | 156 | bindSimpleProgram(batch); |
| 162 | DependencyManager::get<GeometryCache>()->renderWireCube(batch, size, color); | 157 | DependencyManager::get<GeometryCache>()->renderWireCube(batch, size, color); |
| 163 | releaseSimpleProgram(batch); | ||
| 164 | } | 158 | } |
| 165 | 159 | ||
| 166 | void DeferredLightingEffect::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner, | 160 | void DeferredLightingEffect::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner, |
| 167 | const glm::vec4& color) { | 161 | const glm::vec4& color) { |
| 168 | bindSimpleProgram(batch); | 162 | bindSimpleProgram(batch); |
| 169 | DependencyManager::get<GeometryCache>()->renderQuad(batch, minCorner, maxCorner, color); | 163 | DependencyManager::get<GeometryCache>()->renderQuad(batch, minCorner, maxCorner, color); |
| 170 | releaseSimpleProgram(batch); | ||
| 171 | } | 164 | } |
| 172 | 165 | ||
| 173 | void DeferredLightingEffect::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, | 166 | void DeferredLightingEffect::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, |
| 174 | const glm::vec4& color1, const glm::vec4& color2) { | 167 | const glm::vec4& color1, const glm::vec4& color2) { |
| 175 | bindSimpleProgram(batch); | 168 | bindSimpleProgram(batch); |
| 176 | DependencyManager::get<GeometryCache>()->renderLine(batch, p1, p2, color1, color2); | 169 | DependencyManager::get<GeometryCache>()->renderLine(batch, p1, p2, color1, color2); |
| 177 | releaseSimpleProgram(batch); | ||
| 178 | } | 170 | } |
| 179 | 171 | ||
| 180 | void DeferredLightingEffect::addPointLight(const glm::vec3& position, float radius, const glm::vec3& color, | 172 | void DeferredLightingEffect::addPointLight(const glm::vec3& position, float radius, const glm::vec3& color, |