mirror of
https://github.com/overte-org/overte.git
synced 2025-04-29 18:02:35 +02:00
adding in screen space effect for getting hit
This commit is contained in:
parent
bad6aa8f0a
commit
1e34de1c51
6 changed files with 195 additions and 13 deletions
|
@ -67,23 +67,13 @@ void RenderablePolyLineEntityItem::createPipeline() {
|
|||
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||
_pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
||||
}
|
||||
int generateColor() {
|
||||
float c1 = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
float c2 = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
float c3 = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
return ((int(0.7 * 255.0f) & 0xFF)) |
|
||||
((int(0.3 * 255.0f) & 0xFF) << 8) |
|
||||
((int(0.6 * 255.0f) & 0xFF) << 16) |
|
||||
((int(255.0f) & 0xFF) << 24);
|
||||
}
|
||||
|
||||
void RenderablePolyLineEntityItem::updateGeometry() {
|
||||
int compactColor = generateColor();
|
||||
_numVertices = 0;
|
||||
_verticesBuffer.reset(new gpu::Buffer());
|
||||
int vertexIndex = 0;
|
||||
for (int i = 0; i < _normals.size(); i++) {
|
||||
compactColor = generateColor();
|
||||
|
||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex));
|
||||
vertexIndex++;
|
||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i));
|
||||
|
@ -119,7 +109,6 @@ void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
|||
if (_pointsChanged) {
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
|
||||
gpu::Batch& batch = *args->_batch;
|
||||
Transform transform = Transform();
|
||||
|
@ -127,7 +116,7 @@ void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
|||
transform.setRotation(getRotation());
|
||||
batch.setModelTransform(transform);
|
||||
|
||||
|
||||
batch.setResourceTexture(0, _texture);
|
||||
batch.setPipeline(_pipeline);
|
||||
|
||||
batch.setInputFormat(_format);
|
||||
|
|
105
libraries/render-utils/src/HitEffect.cpp
Normal file
105
libraries/render-utils/src/HitEffect.cpp
Normal file
|
@ -0,0 +1,105 @@
|
|||
//
|
||||
// HitEffect.cpp
|
||||
// interface/src/renderer
|
||||
//
|
||||
// Created by Andrzej Kapolka on 7/14/13.
|
||||
// Copyright 2013 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 this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL
|
||||
#include <gpu/GPUConfig.h>
|
||||
|
||||
#include <gpu/GLBackend.h>
|
||||
|
||||
#include <glm/gtc/random.hpp>
|
||||
|
||||
#include <PathUtils.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "AbstractViewStateInterface.h"
|
||||
#include "HitEffect.h"
|
||||
#include "ProgramObject.h"
|
||||
#include "RenderUtil.h"
|
||||
#include "TextureCache.h"
|
||||
#include "DependencyManager.h"
|
||||
#include "ViewFrustum.h"
|
||||
#include "GeometryCache.h"
|
||||
|
||||
#include "hit_effect_vert.h"
|
||||
#include "hit_effect_frag.h"
|
||||
|
||||
|
||||
HitEffect::HitEffect() {
|
||||
}
|
||||
|
||||
const gpu::PipelinePointer& HitEffect::getHitEffectPipeline() {
|
||||
if (!_hitEffectPipeline) {
|
||||
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(hit_effect_vert)));
|
||||
auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(hit_effect_frag)));
|
||||
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps));
|
||||
|
||||
|
||||
gpu::Shader::BindingSet slotBindings;
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
|
||||
_screenSizeLocation = program->getUniforms().findLocation("screenSize");
|
||||
|
||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||
|
||||
state->setDepthTest(false, false, gpu::LESS_EQUAL);
|
||||
|
||||
// Blend on transparent
|
||||
state->setBlendFunction(true,
|
||||
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA);
|
||||
|
||||
|
||||
// Good to go add the brand new pipeline
|
||||
_hitEffectPipeline.reset(gpu::Pipeline::create(program, state));
|
||||
}
|
||||
return _hitEffectPipeline;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void HitEffect::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) {
|
||||
|
||||
// create a simple pipeline that does:
|
||||
|
||||
assert(renderContext->args);
|
||||
assert(renderContext->args->_viewFrustum);
|
||||
RenderArgs* args = renderContext->args;
|
||||
|
||||
// Allright, something to render let's do it
|
||||
gpu::Batch batch;
|
||||
|
||||
glm::mat4 projMat;
|
||||
Transform viewMat;
|
||||
args->_viewFrustum->evalProjectionMatrix(projMat);
|
||||
args->_viewFrustum->evalViewTransform(viewMat);
|
||||
batch.setProjectionTransform(projMat);
|
||||
batch.setViewTransform(viewMat);
|
||||
batch.setModelTransform(Transform());
|
||||
|
||||
|
||||
|
||||
|
||||
// bind the first gpu::Pipeline we need - for calculating occlusion buffer
|
||||
batch.setPipeline(getHitEffectPipeline());
|
||||
|
||||
|
||||
glm::vec4 color(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glm::vec2 bottomLeft(-1.0f, -1.0f);
|
||||
glm::vec2 topRight(1.0f, 1.0f);
|
||||
DependencyManager::get<GeometryCache>()->renderQuad(batch, bottomLeft, topRight, color);
|
||||
|
||||
|
||||
// Ready to render
|
||||
renderContext->args->_context->syncCache();
|
||||
args->_context->render((batch));
|
||||
|
||||
}
|
||||
|
34
libraries/render-utils/src/HitEffect.h
Normal file
34
libraries/render-utils/src/HitEffect.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// hitEffect.h
|
||||
// hifi
|
||||
//
|
||||
// Created by eric levin on 7/17/15.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef hifi_hitEffect_h
|
||||
#define hifi_hitEffect_h
|
||||
|
||||
#include <DependencyManager.h>
|
||||
#include "render/DrawTask.h"
|
||||
|
||||
class AbstractViewStateInterface;
|
||||
class ProgramObject;
|
||||
|
||||
class HitEffect {
|
||||
public:
|
||||
|
||||
HitEffect();
|
||||
|
||||
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext);
|
||||
typedef render::Job::Model<HitEffect> JobModel;
|
||||
|
||||
const gpu::PipelinePointer& getHitEffectPipeline();
|
||||
|
||||
private:
|
||||
|
||||
gpu::PipelinePointer _hitEffectPipeline;
|
||||
GLuint _screenSizeLocation;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -16,6 +16,7 @@
|
|||
#include "ViewFrustum.h"
|
||||
#include "RenderArgs.h"
|
||||
#include "TextureCache.h"
|
||||
#include "HitEffect.h"
|
||||
|
||||
#include "render/DrawStatus.h"
|
||||
|
||||
|
@ -54,6 +55,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() {
|
|||
_jobs.push_back(Job(new DepthSortItems::JobModel("DepthSortOpaque", _jobs.back().getOutput())));
|
||||
auto& renderedOpaques = _jobs.back().getOutput();
|
||||
_jobs.push_back(Job(new DrawOpaqueDeferred::JobModel("DrawOpaqueDeferred", _jobs.back().getOutput())));
|
||||
|
||||
_jobs.push_back(Job(new DrawLight::JobModel("DrawLight")));
|
||||
_jobs.push_back(Job(new ResetGLState::JobModel()));
|
||||
_jobs.push_back(Job(new RenderDeferred::JobModel("RenderDeferred")));
|
||||
|
@ -75,7 +77,9 @@ RenderDeferredTask::RenderDeferredTask() : Task() {
|
|||
_drawStatusJobIndex = _jobs.size() - 1;
|
||||
|
||||
_jobs.push_back(Job(new DrawOverlay3D::JobModel("DrawOverlay3D")));
|
||||
_jobs.push_back(Job(new HitEffect::JobModel("HitEffect")));
|
||||
_jobs.push_back(Job(new ResetGLState::JobModel()));
|
||||
|
||||
|
||||
// Give ourselves 3 frmaes of timer queries
|
||||
_timerQueries.push_back(gpu::QueryPointer(new gpu::Query()));
|
||||
|
|
29
libraries/render-utils/src/hit_effect.slf
Normal file
29
libraries/render-utils/src/hit_effect.slf
Normal file
|
@ -0,0 +1,29 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// ambient_occlusion.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Eric Levin on 7/20
|
||||
// Copyright 2015 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 gpu/Transform.slh@>
|
||||
<$declareStandardTransform()$>
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
void main(void) {
|
||||
|
||||
TransformCamera cam = getTransformCamera();
|
||||
vec4 myViewport;
|
||||
<$transformCameraViewport(cam, myViewport)$>
|
||||
vec2 center = vec2(myViewport.z/2.0, myViewport.w/2.0);
|
||||
float distFromCenter = distance(center, gl_FragCoord.xy);
|
||||
//normalize
|
||||
distFromCenter = distFromCenter/myViewport.z;
|
||||
float alpha = mix(0.0, 1.0, distFromCenter);
|
||||
gl_FragColor = vec4(0.7, 0.0, 0.0, alpha);
|
||||
}
|
21
libraries/render-utils/src/hit_effect.slv
Normal file
21
libraries/render-utils/src/hit_effect.slv
Normal file
|
@ -0,0 +1,21 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// ambient_occlusion.vert
|
||||
// vertex shader
|
||||
//
|
||||
// Created by Niraj Venkat on 7/20/15.
|
||||
// Copyright 2015 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 gpu/Transform.slh@>
|
||||
|
||||
<$declareStandardTransform()$>
|
||||
|
||||
void main(void) {
|
||||
gl_Position = gl_Vertex;
|
||||
}
|
Loading…
Reference in a new issue