Add simple textured pipeline

This commit is contained in:
Atlante45 2015-05-29 16:49:31 +02:00
parent 34072c55e3
commit 51570aac68
5 changed files with 64 additions and 8 deletions

View file

@ -28,6 +28,7 @@
#include "simple_vert.h"
#include "simple_frag.h"
#include "simple_textured_frag.h"
#include "deferred_light_vert.h"
#include "deferred_light_limited_vert.h"
@ -50,13 +51,16 @@
static const std::string glowIntensityShaderHandle = "glowIntensity";
void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
auto vertexShader = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(simple_vert)));
auto pixelShader = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_frag)));
auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(simple_vert)));
auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_frag)));
auto PSTextured = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_textured_frag)));
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PS));
gpu::ShaderPointer programTextured = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PSTextured));
gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(glowIntensityShaderHandle, 0));
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vertexShader, pixelShader));
gpu::Shader::makeProgram(*program, slotBindings);
gpu::Shader::makeProgram(*programTextured, slotBindings);
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
state->setCullMode(gpu::State::CULL_BACK);
@ -65,6 +69,7 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
_simpleProgram = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
_simpleProgramTextured = gpu::PipelinePointer(gpu::Pipeline::create(programTextured, state));
_viewState = viewState;
loadLightProgram(directional_light_frag, false, _directionalLight, _directionalLightLocations);
@ -101,9 +106,14 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset(_ambientLightMode % gpu::SphericalHarmonics::NUM_PRESET));
}
void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch) {
void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured) {
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(batch, true, true, true);
batch.setPipeline(_simpleProgram);
if (textured) {
batch.setPipeline(_simpleProgramTextured);
} else {
batch.setPipeline(_simpleProgram);
}
}
void DeferredLightingEffect::releaseSimpleProgram(gpu::Batch& batch) {

View file

@ -34,7 +34,7 @@ public:
void init(AbstractViewStateInterface* viewState);
/// Sets up the state necessary to render static untextured geometry with the simple program.
void bindSimpleProgram(gpu::Batch& batch);
void bindSimpleProgram(gpu::Batch& batch, bool textured = false);
/// Tears down the state necessary to render static untextured geometry with the simple program.
void releaseSimpleProgram(gpu::Batch& batch);
@ -100,6 +100,7 @@ private:
static void loadLightProgram(const char* fragSource, bool limited, ProgramObject& program, LightLocations& locations);
gpu::PipelinePointer _simpleProgram;
gpu::PipelinePointer _simpleProgramTextured;
ProgramObject _directionalSkyboxLight;
LightLocations _directionalSkyboxLightLocations;

View file

@ -14,6 +14,8 @@
<@include DeferredBufferWrite.slh@>
uniform float glowIntensity;
// the interpolated normal
varying vec4 interpolatedNormal;

View file

@ -20,6 +20,8 @@
varying vec4 interpolatedNormal;
void main(void) {
gl_TexCoord[0] = gl_MultiTexCoord0;
// pass along the diffuse color
gl_FrontColor = gl_Color;

View file

@ -0,0 +1,41 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// simple.frag
// fragment shader
//
// Created by Clément Brisset on 5/29/15.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include DeferredBufferWrite.slh@>
// the diffuse texture
uniform sampler2D originalTexture;
// the interpolated normal
varying vec4 interpolatedNormal;
// the glow intensity
//uniform float glowIntensity;
void main(void) {
/* // set the diffuse, normal, specular data
gl_FragData[0] = vec4(gl_Color.rgb, glowIntensity);
gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0);
*/
vec4 texel = texture2D(originalTexture, gl_TexCoord[0].st);
packDeferredFragment(
normalize(interpolatedNormal.xyz),
glowIntensity * texel.a,
gl_Color.rgb * texel.rgb,
gl_FrontMaterial.specular.rgb,
gl_FrontMaterial.shininess);
}