History

Introduce new emissive simple program

Also fixes the shading on web entities using that program

Atlante45 committed 11 years ago

Commit efd805b1 parent 017b4044 files · +53 −33Browse files

Showing the changes to libraries/render-utils/src/DeferredLightingEffect.cpp (1 of 4 files). Show all

Unified · Split

libraries/render-utils/src/DeferredLightingEffect.cpp+15−23
@@ -27,8 +27,8 @@ · 26 unmodified lines
2727 #include "gpu/GLBackend.h"
2828
2929 #include "simple_vert.h"
30−#include "simple_frag.h"
3130 #include "simple_textured_frag.h"
31+#include "simple_textured_emisive_frag.h"
3232
3333 #include "deferred_light_vert.h"
3434 #include "deferred_light_limited_vert.h"
@@ -52,15 +52,15 @@ static const std::string glowIntensityShaderHandle = "glowIntensity"; · 17 unmodified lines
5252
5353 void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
5454 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)));
5757
5858 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));
6060
6161 gpu::Shader::BindingSet slotBindings;
6262 gpu::Shader::makeProgram(*program, slotBindings);
63− gpu::Shader::makeProgram(*programTextured, slotBindings);
63+ gpu::Shader::makeProgram(*programEmissive, slotBindings);
6464
6565 gpu::StatePointer state = gpu::StatePointer(new gpu::State());
6666 state->setCullMode(gpu::State::CULL_BACK);
@@ -79,8 +79,8 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { · 12 unmodified lines
7979
8080 _simpleProgram = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
8181 _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));
8484
8585 _viewState = viewState;
8686 loadLightProgram(directional_light_frag, false, _directionalLight, _directionalLightLocations);
@@ -117,14 +117,12 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { · 30 unmodified lines
117117 lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset(_ambientLightMode % gpu::SphericalHarmonics::NUM_PRESET));
118118 }
119119
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) {
124122 if (culled) {
125− batch.setPipeline(_simpleProgramTextured);
123+ batch.setPipeline(_simpleProgramEmissive);
126124 } else {
127− batch.setPipeline(_simpleProgramTexturedCullNone);
125+ batch.setPipeline(_simpleProgramEmissiveCullNone);
128126 }
129127 } else {
130128 if (culled) {
@@ -133,48 +131,42 @@ void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured, · 2 unmodified lines
133131 batch.setPipeline(_simpleProgramCullNone);
134132 }
135133 }
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+ }
140138 }
141139
142140 void DeferredLightingEffect::renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) {
143141 bindSimpleProgram(batch);
144142 DependencyManager::get<GeometryCache>()->renderSphere(batch, radius, slices, stacks, color);
145− releaseSimpleProgram(batch);
146143 }
147144
148145 void DeferredLightingEffect::renderWireSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) {
149146 bindSimpleProgram(batch);
150147 DependencyManager::get<GeometryCache>()->renderSphere(batch, radius, slices, stacks, color, false);
151− releaseSimpleProgram(batch);
152148 }
153149
154150 void DeferredLightingEffect::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) {
155151 bindSimpleProgram(batch);
156152 DependencyManager::get<GeometryCache>()->renderSolidCube(batch, size, color);
157− releaseSimpleProgram(batch);
158153 }
159154
160155 void DeferredLightingEffect::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) {
161156 bindSimpleProgram(batch);
162157 DependencyManager::get<GeometryCache>()->renderWireCube(batch, size, color);
163− releaseSimpleProgram(batch);
164158 }
165159
166160 void DeferredLightingEffect::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner,
167161 const glm::vec4& color) {
168162 bindSimpleProgram(batch);
169163 DependencyManager::get<GeometryCache>()->renderQuad(batch, minCorner, maxCorner, color);
170− releaseSimpleProgram(batch);
171164 }
172165
173166 void DeferredLightingEffect::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2,
174167 const glm::vec4& color1, const glm::vec4& color2) {
175168 bindSimpleProgram(batch);
176169 DependencyManager::get<GeometryCache>()->renderLine(batch, p1, p2, color1, color2);
177− releaseSimpleProgram(batch);
178170 }
179171
180172 void DeferredLightingEffect::addPointLight(const glm::vec3& position, float radius, const glm::vec3& color,