mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 04:28:12 +02:00
Merge branch 'team-teaching' of https://github.com/highfidelity/hifi into team-teaching
This commit is contained in:
commit
ab13bc41a4
11 changed files with 92 additions and 49 deletions
|
@ -148,36 +148,23 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
|
||||||
currentContext->makeCurrent(currentSurface);
|
currentContext->makeCurrent(currentSurface);
|
||||||
|
|
||||||
PerformanceTimer perfTimer("RenderableWebEntityItem::render");
|
PerformanceTimer perfTimer("RenderableWebEntityItem::render");
|
||||||
assert(getType() == EntityTypes::Web);
|
Q_ASSERT(getType() == EntityTypes::Web);
|
||||||
glm::vec3 position = getPosition();
|
static const glm::vec2 texMin(0.0f);
|
||||||
glm::vec3 dimensions = getDimensions();
|
static const glm::vec2 texMax(1.0f);
|
||||||
glm::vec3 halfDimensions = dimensions / 2.0f;
|
glm::vec2 topLeft(-0.5f -0.5f);
|
||||||
glm::quat rotation = getRotation();
|
glm::vec2 bottomRight(0.5f, 0.5f);
|
||||||
|
|
||||||
glPushMatrix();
|
Q_ASSERT(args->_batch);
|
||||||
{
|
gpu::Batch& batch = *args->_batch;
|
||||||
glTranslatef(position.x, position.y, position.z);
|
batch.setModelTransform(getTransformToCenter());
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
if (_texture) {
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
batch._glBindTexture(GL_TEXTURE_2D, _texture);
|
||||||
|
batch._glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
static const glm::vec2 texMin(0);
|
batch._glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
static const glm::vec2 texMax(1);
|
|
||||||
glm::vec2 topLeft(-halfDimensions.x, -halfDimensions.y);
|
|
||||||
glm::vec2 bottomRight(halfDimensions.x, halfDimensions.y);
|
|
||||||
if (_texture) {
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _texture);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
}
|
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(
|
|
||||||
topLeft, bottomRight, texMin, texMax, glm::vec4(1));
|
|
||||||
if (_texture) {
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
DependencyManager::get<DeferredLightingEffect>()->bindSimpleProgram(batch, true);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f));
|
||||||
|
DependencyManager::get<DeferredLightingEffect>()->releaseSimpleProgram(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::setSourceUrl(const QString& value) {
|
void RenderableWebEntityItem::setSourceUrl(const QString& value) {
|
||||||
|
|
|
@ -1014,7 +1014,7 @@ void EntityItem::setTranformToCenter(const Transform& transform) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::setDimensions(const glm::vec3& value) {
|
void EntityItem::setDimensions(const glm::vec3& value) {
|
||||||
if (value.x == 0.0f || value.y == 0.0f || value.z == 0.0f) {
|
if (value.x <= 0.0f || value.y <= 0.0f || value.z <= 0.0f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_transform.setScale(value);
|
_transform.setScale(value);
|
||||||
|
|
|
@ -143,7 +143,8 @@ public:
|
||||||
|
|
||||||
void _glBindTexture(GLenum target, GLuint texture);
|
void _glBindTexture(GLenum target, GLuint texture);
|
||||||
void _glActiveTexture(GLenum texture);
|
void _glActiveTexture(GLenum texture);
|
||||||
|
void _glTexParameteri(GLenum target, GLenum pname, GLint param);
|
||||||
|
|
||||||
void _glDrawBuffers(GLsizei n, const GLenum* bufs);
|
void _glDrawBuffers(GLsizei n, const GLenum* bufs);
|
||||||
|
|
||||||
void _glUseProgram(GLuint program);
|
void _glUseProgram(GLuint program);
|
||||||
|
@ -201,6 +202,7 @@ public:
|
||||||
|
|
||||||
COMMAND_glBindTexture,
|
COMMAND_glBindTexture,
|
||||||
COMMAND_glActiveTexture,
|
COMMAND_glActiveTexture,
|
||||||
|
COMMAND_glTexParameteri,
|
||||||
|
|
||||||
COMMAND_glDrawBuffers,
|
COMMAND_glDrawBuffers,
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
|
||||||
|
|
||||||
(&::gpu::GLBackend::do_glBindTexture),
|
(&::gpu::GLBackend::do_glBindTexture),
|
||||||
(&::gpu::GLBackend::do_glActiveTexture),
|
(&::gpu::GLBackend::do_glActiveTexture),
|
||||||
|
(&::gpu::GLBackend::do_glTexParameteri),
|
||||||
|
|
||||||
(&::gpu::GLBackend::do_glDrawBuffers),
|
(&::gpu::GLBackend::do_glDrawBuffers),
|
||||||
|
|
||||||
|
@ -381,6 +382,22 @@ void GLBackend::do_glActiveTexture(Batch& batch, uint32 paramOffset) {
|
||||||
(void) CHECK_GL_ERROR();
|
(void) CHECK_GL_ERROR();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Batch::_glTexParameteri(GLenum target, GLenum pname, GLint param) {
|
||||||
|
ADD_COMMAND_GL(glTexParameteri);
|
||||||
|
|
||||||
|
_params.push_back(param);
|
||||||
|
_params.push_back(pname);
|
||||||
|
_params.push_back(target);
|
||||||
|
|
||||||
|
DO_IT_NOW(glTexParameteri, 3);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glTexParameteri(Batch& batch, uint32 paramOffset) {
|
||||||
|
glTexParameteri(batch._params[paramOffset + 2]._uint,
|
||||||
|
batch._params[paramOffset + 1]._uint,
|
||||||
|
batch._params[paramOffset + 0]._int);
|
||||||
|
(void) CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
void Batch::_glDrawBuffers(GLsizei n, const GLenum* bufs) {
|
void Batch::_glDrawBuffers(GLsizei n, const GLenum* bufs) {
|
||||||
ADD_COMMAND_GL(glDrawBuffers);
|
ADD_COMMAND_GL(glDrawBuffers);
|
||||||
|
|
||||||
|
|
|
@ -358,6 +358,7 @@ protected:
|
||||||
|
|
||||||
void do_glBindTexture(Batch& batch, uint32 paramOffset);
|
void do_glBindTexture(Batch& batch, uint32 paramOffset);
|
||||||
void do_glActiveTexture(Batch& batch, uint32 paramOffset);
|
void do_glActiveTexture(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glTexParameteri(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
void do_glDrawBuffers(Batch& batch, uint32 paramOffset);
|
void do_glDrawBuffers(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "simple_vert.h"
|
#include "simple_vert.h"
|
||||||
#include "simple_frag.h"
|
#include "simple_frag.h"
|
||||||
|
#include "simple_textured_frag.h"
|
||||||
|
|
||||||
#include "deferred_light_vert.h"
|
#include "deferred_light_vert.h"
|
||||||
#include "deferred_light_limited_vert.h"
|
#include "deferred_light_limited_vert.h"
|
||||||
|
@ -50,13 +51,16 @@
|
||||||
static const std::string glowIntensityShaderHandle = "glowIntensity";
|
static const std::string glowIntensityShaderHandle = "glowIntensity";
|
||||||
|
|
||||||
void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
|
void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
|
||||||
auto vertexShader = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(simple_vert)));
|
auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(simple_vert)));
|
||||||
auto pixelShader = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_frag)));
|
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;
|
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(*program, slotBindings);
|
||||||
|
gpu::Shader::makeProgram(*programTextured, slotBindings);
|
||||||
|
|
||||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||||
state->setCullMode(gpu::State::CULL_BACK);
|
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::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
||||||
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||||
_simpleProgram = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
_simpleProgram = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
||||||
|
_simpleProgramTextured = gpu::PipelinePointer(gpu::Pipeline::create(programTextured, state));
|
||||||
|
|
||||||
_viewState = viewState;
|
_viewState = viewState;
|
||||||
loadLightProgram(directional_light_frag, false, _directionalLight, _directionalLightLocations);
|
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));
|
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);
|
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) {
|
void DeferredLightingEffect::releaseSimpleProgram(gpu::Batch& batch) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
void init(AbstractViewStateInterface* viewState);
|
void init(AbstractViewStateInterface* viewState);
|
||||||
|
|
||||||
/// Sets up the state necessary to render static untextured geometry with the simple program.
|
/// 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.
|
/// Tears down the state necessary to render static untextured geometry with the simple program.
|
||||||
void releaseSimpleProgram(gpu::Batch& batch);
|
void releaseSimpleProgram(gpu::Batch& batch);
|
||||||
|
@ -100,6 +100,7 @@ private:
|
||||||
static void loadLightProgram(const char* fragSource, bool limited, ProgramObject& program, LightLocations& locations);
|
static void loadLightProgram(const char* fragSource, bool limited, ProgramObject& program, LightLocations& locations);
|
||||||
|
|
||||||
gpu::PipelinePointer _simpleProgram;
|
gpu::PipelinePointer _simpleProgram;
|
||||||
|
gpu::PipelinePointer _simpleProgramTextured;
|
||||||
|
|
||||||
ProgramObject _directionalSkyboxLight;
|
ProgramObject _directionalSkyboxLight;
|
||||||
LightLocations _directionalSkyboxLightLocations;
|
LightLocations _directionalSkyboxLightLocations;
|
||||||
|
|
|
@ -17,16 +17,7 @@
|
||||||
// the interpolated normal
|
// the interpolated normal
|
||||||
varying vec4 interpolatedNormal;
|
varying vec4 interpolatedNormal;
|
||||||
|
|
||||||
// the glow intensity
|
|
||||||
//uniform float glowIntensity;
|
|
||||||
|
|
||||||
void main(void) {
|
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);
|
|
||||||
*/
|
|
||||||
|
|
||||||
packDeferredFragment(
|
packDeferredFragment(
|
||||||
normalize(interpolatedNormal.xyz),
|
normalize(interpolatedNormal.xyz),
|
||||||
glowIntensity,
|
glowIntensity,
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
varying vec4 interpolatedNormal;
|
varying vec4 interpolatedNormal;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
|
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||||
|
|
||||||
// pass along the diffuse color
|
// pass along the diffuse color
|
||||||
gl_FrontColor = gl_Color;
|
gl_FrontColor = gl_Color;
|
||||||
|
|
||||||
|
|
32
libraries/render-utils/src/simple_textured.slf
Normal file
32
libraries/render-utils/src/simple_textured.slf
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<@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;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
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);
|
||||||
|
}
|
|
@ -24,13 +24,13 @@
|
||||||
|
|
||||||
inline bool isValidScale(glm::vec3 scale) {
|
inline bool isValidScale(glm::vec3 scale) {
|
||||||
bool result = scale.x != 0.0f && scale.y != 0.0f && scale.z != 0.0f;
|
bool result = scale.x != 0.0f && scale.y != 0.0f && scale.z != 0.0f;
|
||||||
// assert(result);
|
assert(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool isValidScale(float scale) {
|
inline bool isValidScale(float scale) {
|
||||||
bool result = scale != 0.0f;
|
bool result = scale != 0.0f;
|
||||||
// assert(result);
|
assert(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue