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