Still marinating how to represent the proxy values...

This commit is contained in:
samcake 2018-02-22 16:44:35 -08:00
parent 974ba6762d
commit 101872abce
4 changed files with 77 additions and 41 deletions

View file

@ -12,6 +12,8 @@
#include <cstring>
#include <gpu/Context.h>
#include <StencilMaskPass.h>
#include <GeometryCache.h>
#include "render-utils/drawWorkloadProxy_vert.h"
#include "render-utils/drawWorkloadProxy_frag.h"
@ -21,6 +23,14 @@ void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext,
if (!gameWorkloadContext) {
return;
}
auto space = gameWorkloadContext->_space;
if (!space) {
return;
}
std::vector<workload::Space::Proxy> proxies(space->getNumAllocatedProxies());
space->copyProxyValues(proxies.data(), (uint32_t)proxies.size());
auto scene = gameWorkloadContext->_scene;
@ -29,31 +39,20 @@ void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext,
if (!render::Item::isValidID(_spaceRenderItemID)) {
_spaceRenderItemID = scene->allocateID();
auto renderItem = std::make_shared<GameWorkloadRenderItem>();
renderItem->editBound().expandedContains(glm::vec3(0.0f), 32000.0f);
transaction.resetItem(_spaceRenderItemID, std::make_shared<GameWorkloadRenderItem::Payload>(std::make_shared<GameWorkloadRenderItem>()));
scene->enqueueTransaction(transaction);
renderItem->editBound().setBox(glm::vec3(-100.0f), 200.0f);
renderItem->setAllProxies(proxies);
transaction.resetItem(_spaceRenderItemID, std::make_shared<GameWorkloadRenderItem::Payload>(renderItem));
} else {
transaction.updateItem<GameWorkloadRenderItem>(_spaceRenderItemID, [proxies](GameWorkloadRenderItem& item) {
item.setAllProxies(proxies);
});
}
auto space = gameWorkloadContext->_space;
if (!space) {
return;
}
std::vector<workload::Space::Proxy> proxies(space->getNumAllocatedProxies());
space->copyProxyValues(proxies.data(), (uint32_t) proxies.size());
transaction.updateItem<GameWorkloadRenderItem>(_spaceRenderItemID, [proxies](GameWorkloadRenderItem& item) {
item.setAllProxies(proxies);
});
scene->enqueueTransaction(transaction);
}
namespace render {
template <> const ItemKey payloadGetKey(const GameWorkloadRenderItem::Pointer& payload) {
auto builder = ItemKey::Builder().transparentShape().withTagBits(ItemKey::TAG_BITS_0 | ItemKey::TAG_BITS_1);
return builder.build();
return ItemKey::Builder::opaqueShape().withTagBits(render::ItemKey::TAG_BITS_0 | render::ItemKey::TAG_BITS_1);
}
template <> const Item::Bound payloadGetBound(const GameWorkloadRenderItem::Pointer& payload) {
if (payload) {
@ -67,16 +66,18 @@ namespace render {
}
}
template <> const ShapeKey shapeGetShapeKey(const GameWorkloadRenderItem::Pointer& payload) {
if (payload) {
return ShapeKey::Builder::ownPipeline();
}
return ShapeKey::Builder::ownPipeline();
}
template <> int payloadGetLayer(const GameWorkloadRenderItem::Pointer& payloadData) {
return render::Item::LAYER_3D_FRONT;
}
}
void GameWorkloadRenderItem::setAllProxies(const std::vector<workload::Space::Proxy>& proxies) {
_myOwnProxies = proxies;
static const uint32_t sizeOfProxy = sizeof(workload::Space::Proxy);
if (!_allProxiesBuffer) {
_allProxiesBuffer = std::make_shared<gpu::Buffer>(sizeOfProxy);
@ -97,11 +98,13 @@ const gpu::PipelinePointer GameWorkloadRenderItem::getPipeline() {
gpu::Shader::makeProgram(*program, slotBindings);
auto state = std::make_shared<gpu::State>();
/* state->setDepthTest(true, false, gpu::LESS_EQUAL);
state->setBlendFunction(true,
state->setDepthTest(true, false, gpu::LESS_EQUAL);
/* state->setBlendFunction(true,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO);
*/
gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO);*/
PrepareStencil::testMaskDrawShape(*state);
state->setCullMode(gpu::State::CULL_NONE);
_drawAllProxiesPipeline = gpu::Pipeline::create(program, state);
}
return _drawAllProxiesPipeline;
@ -111,23 +114,39 @@ void GameWorkloadRenderItem::render(RenderArgs* args) {
gpu::Batch& batch = *(args->_batch);
// Setup projection
// glm::mat4 projMat;
// Transform viewMat;
// args->getViewFrustum().evalProjectionMatrix(projMat);
// args->getViewFrustum().evalViewTransform(viewMat);
// batch.setProjectionTransform(projMat);
// batch.setViewTransform(viewMat);
glm::mat4 projMat;
Transform viewMat;
args->getViewFrustum().evalProjectionMatrix(projMat);
args->getViewFrustum().evalViewTransform(viewMat);
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat);
batch.setModelTransform(Transform());
// Bind program
batch.setPipeline(getPipeline());
batch.setResourceBuffer(0, _allProxiesBuffer);
static const int NUM_VERTICES_PER_QUAD = 24;
batch.draw(gpu::LINES, NUM_VERTICES_PER_QUAD * _numAllProxies, 0);
static const int NUM_VERTICES_PER_QUAD = 6;
batch.draw(gpu::TRIANGLES, NUM_VERTICES_PER_QUAD * _numAllProxies, 0);
batch.setResourceBuffer(0, nullptr);
/*
auto geometryCache = DependencyManager::get<GeometryCache>();
GeometryCache::Shape geometryShape;
glm::vec4 outColor;
geometryShape = GeometryCache::Sphere;
// geometryCache->renderShape(batch, geometryShape, outColor);
auto pipeline = geometryCache->getOpaqueShapePipeline();
for (int i = 0; i < _numAllProxies; i++) {
auto sphere = _myOwnProxies[i].sphere;
batch.setModelTransform(Transform(glm::quat(), glm::vec3(1.0), glm::vec3(sphere.x, sphere.y, sphere.z)));
geometryCache->renderSolidShapeInstance(args, batch, geometryShape, outColor, pipeline);
}*/
}

View file

@ -45,6 +45,7 @@ public:
protected:
render::Item::Bound _bound;
std::vector<workload::Space::Proxy> _myOwnProxies;
gpu::BufferPointer _allProxiesBuffer;
uint32_t _numAllProxies{ 0 };
@ -60,6 +61,8 @@ namespace render {
template <> const Item::Bound payloadGetBound(const GameWorkloadRenderItem::Pointer& payload);
template <> void payloadRender(const GameWorkloadRenderItem::Pointer& payload, RenderArgs* args);
template <> const ShapeKey shapeGetShapeKey(const GameWorkloadRenderItem::Pointer& payload);
template <> int payloadGetLayer(const GameWorkloadRenderItem::Pointer& payloadData);
}

View file

@ -10,14 +10,15 @@
// 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@>
in vec4 varColor;
in vec2 varTexcoord;
out vec4 outFragColor;
//out vec4 outFragColor;
void main(void) {
outFragColor = vec4(1.0);
/*
/* outFragColor = vec4(1.0);
float var = step(fract(varTexcoord.x * varTexcoord.y * 1.0), 0.5);
if (varColor.a == 0.0) {
@ -27,4 +28,9 @@ void main(void) {
outFragColor = vec4(mix(vec3(1.0), varColor.xyz, var), varColor.a);
}*/
packDeferredFragmentUnlit(
vec3(0.0, 1.0, 0.0),
1.0,
vec3(1.0));
}

View file

@ -61,7 +61,7 @@ void main(void) {
vec4(0.0, 1.0, 1.0, 2.0),
vec4(1.0, 1.0, 1.0, 3.0)
);
const int UNIT_BOX_LINE_INDICES[24] = int[24](
/* const int UNIT_BOX_LINE_INDICES[24] = int[24](
0, 1,
1, 3,
3, 2,
@ -77,7 +77,15 @@ void main(void) {
);
int proxyID = gl_VertexID / 24;
int vertexID = gl_VertexID - proxyID * 24;
int vertexID = gl_VertexID - proxyID * 24;*/
const int UNIT_BOX_LINE_INDICES[6] = int[6](
0, 1, 2,
2, 1, 3
);
int proxyID = gl_VertexID / 6;
int vertexID = gl_VertexID - proxyID * 6;
vec4 cubeVec = UNIT_BOX[UNIT_BOX_LINE_INDICES[vertexID]];
@ -97,4 +105,4 @@ void main(void) {
varTexcoord = vec2(cubeVec.w, length(boundDim));
}
}