Representing the view spheres

This commit is contained in:
samcake 2018-03-02 18:22:51 -08:00
parent 7179a31d17
commit 660c4c30e9
6 changed files with 63 additions and 33 deletions

View file

@ -21,6 +21,7 @@
void GameSpaceToRender::configure(const Config& config) {
_freezeViews = config.freezeViews;
_showAllProxies = config.showProxies;
_showAllViews = config.showViews;
}
@ -38,6 +39,7 @@ void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext,
auto visible = _showAllProxies || _showAllViews;
auto showProxies = _showAllProxies;
auto showViews = _showAllViews;
auto freezeViews = _freezeViews;
render::Transaction transaction;
auto scene = gameWorkloadContext->_scene;
@ -57,7 +59,9 @@ void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext,
space->copyProxyValues(proxies.data(), (uint32_t)proxies.size());
std::vector<workload::Space::View> views(space->getNumViews());
space->copyViews(views);
if (!freezeViews) {
space->copyViews(views);
}
// Valid space, let's display its content
if (!render::Item::isValidID(_spaceRenderItemID)) {
@ -68,12 +72,14 @@ void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext,
transaction.resetItem(_spaceRenderItemID, std::make_shared<GameWorkloadRenderItem::Payload>(renderItem));
}
transaction.updateItem<GameWorkloadRenderItem>(_spaceRenderItemID, [visible, showProxies, proxies, showViews, views](GameWorkloadRenderItem& item) {
transaction.updateItem<GameWorkloadRenderItem>(_spaceRenderItemID, [visible, showProxies, proxies, freezeViews, showViews, views](GameWorkloadRenderItem& item) {
item.setVisible(visible);
item.showProxies(showProxies);
item.setAllProxies(proxies);
item.showViews(showViews);
item.setAllViews(views);
if (!freezeViews) {
item.setAllViews(views);
}
});
scene->enqueueTransaction(transaction);
@ -198,13 +204,6 @@ const gpu::PipelinePointer GameWorkloadRenderItem::getViewsPipeline() {
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);
batch.setModelTransform(Transform());
batch.setResourceBuffer(0, _allProxiesBuffer);
@ -214,16 +213,16 @@ void GameWorkloadRenderItem::render(RenderArgs* args) {
if (_showProxies) {
batch.setPipeline(getProxiesPipeline());
static const int NUM_VERTICES_PER_QUAD = 3;
batch.draw(gpu::TRIANGLES, NUM_VERTICES_PER_QUAD * _numAllProxies, 0);
static const int NUM_VERTICES_PER_PROXY = 3;
batch.draw(gpu::TRIANGLES, NUM_VERTICES_PER_PROXY * _numAllProxies, 0);
}
// Show Views
if (_showViews) {
batch.setPipeline(getViewsPipeline());
static const int NUM_VERTICES_PER_QUAD = 3;
batch.draw(gpu::TRIANGLES, NUM_VERTICES_PER_QUAD * 3 * _numAllViews, 0);
static const int NUM_VERTICES_PER_VIEW = 27;
batch.draw(gpu::TRIANGLES, NUM_VERTICES_PER_VIEW * _numAllViews, 0);
}
batch.setResourceBuffer(0, nullptr);

View file

@ -14,10 +14,12 @@
class GameSpaceToRenderConfig : public workload::Job::Config {
Q_OBJECT
Q_PROPERTY(bool freezeViews MEMBER freezeViews NOTIFY dirty)
Q_PROPERTY(bool showProxies MEMBER showProxies NOTIFY dirty)
Q_PROPERTY(bool showViews MEMBER showViews NOTIFY dirty)
public:
bool freezeViews{ false };
bool showProxies{ false };
bool showViews{ false };
signals:
@ -39,6 +41,7 @@ public:
protected:
render::ItemID _spaceRenderItemID{ render::Item::INVALID_ITEM_ID };
bool _freezeViews{ false };
bool _showAllProxies{ false };
bool _showAllViews{ false };
};

View file

@ -14,10 +14,10 @@
<@include gpu/Paint.slh@>
in vec4 varColor;
in vec2 varTexcoord;
in vec3 varTexcoord;
void main(void) {
float r = sqrt(dot(varTexcoord.xy,varTexcoord.xy));
float r = sqrt(dot(varTexcoord.xyz,varTexcoord.xyz));
float a = paintStripe(r * varColor.w, 0.0, 1.0 / varColor.w, 0.05 / varColor.w);
if (a <= 0.1 || r > 1.1) {
discard;

View file

@ -48,7 +48,7 @@ WorkloadProxy getWorkloadProxy(int i) {
out vec4 varColor;
out vec2 varTexcoord;
out vec3 varTexcoord;
void main(void) {
const vec4 UNIT_SPRITE[3] = vec4[3](
@ -80,7 +80,7 @@ void main(void) {
// vec3 dirY = normalize(cross(dirZ, vec3(1.0, 0.0, 0.0)));
vec4 pos = vec4(proxyPosEye.xyz + proxy.sphere.w * ( dirX * spriteVert.x + dirY * spriteVert.y /* + dirZ * spriteVert.z*/), 1.0);
varTexcoord = spriteVert.xy;
varTexcoord = spriteVert.xyz;
<$transformEyeToClipPos(cam, pos, gl_Position)$>
// Convert region to color

View file

@ -48,23 +48,37 @@ WorkloadView getWorkloadView(int i) {
out vec4 varColor;
out vec2 varTexcoord;
out vec3 varTexcoord;
const int NUM_VERTICES_PER_VIEW = 27;
const int NUM_REGIONS_PER_VIEW = 3;
const int NUM_VERTICES_PER_VIEW_REGION = NUM_VERTICES_PER_VIEW / NUM_REGIONS_PER_VIEW;
void main(void) {
const vec4 UNIT_SPRITE[3] = vec4[3](
const vec4 UNIT_SPRITE[NUM_VERTICES_PER_VIEW_REGION] = vec4[NUM_VERTICES_PER_VIEW_REGION](
vec4(-1.0, -1.0, 0.0, 1.0),
vec4(3.0, -1.0, 0.0, 1.0),
vec4(-1.0, 3.0, 0.0, 1.0)
vec4(-1.0, 3.0, 0.0, 1.0),
vec4(-1.0, 0.0, -1.0, 1.0),
vec4(3.0, 0.0, -1.0, 1.0),
vec4(-1.0, 0.0, 3.0, 1.0),
vec4(0.0, -1.0, -1.0, 1.0),
vec4(0.0, 3.0, -1.0, 1.0),
vec4(0.0, -1.0, 3.0, 1.0)
);
const int UNIT_SPRITE_INDICES[3] = int[3](
0, 1, 2
const int UNIT_SPRITE_INDICES[NUM_VERTICES_PER_VIEW_REGION] = int[NUM_VERTICES_PER_VIEW_REGION](
0, 1, 2, 3, 4, 5, 6, 7, 8
);
int viewID = gl_VertexID / 9;
int reminder = gl_VertexID - viewID * 9;
int regionID = reminder / 3;
reminder = reminder - regionID * 3;
int vertexID = reminder;
int viewID = gl_VertexID / NUM_VERTICES_PER_VIEW;
int viewVertexID = gl_VertexID - viewID * NUM_VERTICES_PER_VIEW;
int regionID = viewVertexID / NUM_VERTICES_PER_VIEW_REGION;
int regionVertexID = viewVertexID - regionID * NUM_VERTICES_PER_VIEW_REGION;
int vertexID = regionVertexID;
vec4 spriteVert = UNIT_SPRITE[UNIT_SPRITE_INDICES[vertexID]];
@ -78,15 +92,23 @@ void main(void) {
<$transformModelToEyePos(cam, obj, proxyPosWorld, proxyPosEye)$>
// Define the billboarded space
vec3 dirZ = -normalize(proxyPosEye.xyz);
vec3 dirX = normalize(cross(vec3(0.0, 1.0, 0.0), dirZ));
vec3 dirZ = vec3(0.0, 0.0, 1.0);
vec3 dirX = vec3(1.0, 0.0, 0.0);
vec3 dirY = vec3(0.0, 1.0, 0.0);
// vec3 dirY = normalize(cross(dirZ, vec3(1.0, 0.0, 0.0)));
/*normalize(cross(vec3(0.0, 1.0, 0.0), dirZ));
if (dot(proxyPosEye.xyz, proxyPosEye.xyz) > 0.01) {
dirZ = -normalize(proxyPosEye.xyz);
}
vec3 dirX = normalize(cross(vec3(0.0, 1.0, 0.0), dirZ));
vec3 dirY = normalize(cross(dirZ, dirX));
*/
float regionRadius = view.radiuses[regionID];
vec4 pos = vec4(proxyPosEye.xyz + regionRadius * ( dirX * spriteVert.x + dirY * spriteVert.y /* + dirZ * spriteVert.z*/), 1.0);
varTexcoord = spriteVert.xy;
vec3 originSpaceVert = dirY * (-0.02) + regionRadius * ( dirX * spriteVert.x + dirY * spriteVert.y + dirZ * spriteVert.z);
vec4 pos = vec4(proxyPosEye.xyz + originSpaceVert, 1.0);
varTexcoord = spriteVert.xyz;
<$transformEyeToClipPos(cam, pos, gl_Position)$>
// Convert region to color

View file

@ -33,6 +33,12 @@ Rectangle {
HifiControls.Label {
text: "Workload"
}
HifiControls.CheckBox {
boxSize: 20
text: "Freeze Views"
checked: workload.spaceToRender["freezeViews"]
onCheckedChanged: { workload.spaceToRender["freezeViews"] = checked }
}
Separator {}
HifiControls.Label {
text: "Display"