mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Added primitives (geometryCache)
This commit is contained in:
parent
5ca8d20251
commit
ba8a15b893
6 changed files with 357 additions and 62 deletions
|
@ -1,7 +1,7 @@
|
|||
|
||||
set(TARGET_NAME gpu-test)
|
||||
|
||||
AUTOSCRIBE_SHADER_LIB(gpu)
|
||||
AUTOSCRIBE_SHADER_LIB(gpu model render gpu-test)
|
||||
|
||||
# This is not a testcase -- just set it up as a regular hifi project
|
||||
setup_hifi_project(Quick Gui OpenGL)
|
||||
|
@ -10,6 +10,6 @@ set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/")
|
|||
#include_oglplus()
|
||||
|
||||
# link in the shared libraries
|
||||
link_hifi_libraries(render-utils gpu shared)
|
||||
link_hifi_libraries(render-utils gpu shared networking fbx model animation)
|
||||
|
||||
copy_dlls_beside_windows_executable()
|
105
tests/gpu-test/src/gputest_simple_frag.h
Normal file
105
tests/gpu-test/src/gputest_simple_frag.h
Normal file
|
@ -0,0 +1,105 @@
|
|||
// File generated by Scribe Wed Aug 5 16:50:24 2015
|
||||
#ifndef scribe_simple_frag_h
|
||||
#define scribe_simple_frag_h
|
||||
|
||||
const char simple_frag[] = R"SCRIBE(#version 410 core
|
||||
// Generated on Wed Aug 5 16:50:24 2015
|
||||
//
|
||||
// simple.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/15/14.
|
||||
// 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
|
||||
//
|
||||
|
||||
layout(location = 0) out vec4 _fragColor0;
|
||||
layout(location = 1) out vec4 _fragColor1;
|
||||
layout(location = 2) out vec4 _fragColor2;
|
||||
|
||||
// the glow intensity
|
||||
uniform float glowIntensity;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
float evalOpaqueFinalAlpha(float alpha, float mapAlpha) {
|
||||
return mix(alpha * glowIntensity, 1.0 - alpha * glowIntensity, step(mapAlpha, alphaThreshold));
|
||||
}
|
||||
|
||||
const vec3 DEFAULT_SPECULAR = vec3(0.1);
|
||||
const float DEFAULT_SHININESS = 10;
|
||||
|
||||
void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) {
|
||||
if (alpha != glowIntensity) {
|
||||
discard;
|
||||
}
|
||||
_fragColor0 = vec4(diffuse.rgb, alpha);
|
||||
_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
_fragColor2 = vec4(specular, shininess / 128.0);
|
||||
}
|
||||
|
||||
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) {
|
||||
if (alpha != glowIntensity) {
|
||||
discard;
|
||||
}
|
||||
|
||||
_fragColor0 = vec4(diffuse.rgb, alpha);
|
||||
//_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);
|
||||
_fragColor2 = vec4(emissive, shininess / 128.0);
|
||||
}
|
||||
|
||||
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) {
|
||||
if (alpha <= alphaThreshold) {
|
||||
discard;
|
||||
}
|
||||
|
||||
_fragColor0 = vec4(diffuse.rgb, alpha);
|
||||
// _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
// _fragColor2 = vec4(specular, shininess / 128.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct Material {
|
||||
vec4 _diffuse;
|
||||
vec4 _specular;
|
||||
vec4 _emissive;
|
||||
vec4 _spare;
|
||||
};
|
||||
|
||||
uniform materialBuffer {
|
||||
Material _mat;
|
||||
};
|
||||
|
||||
Material getMaterial() {
|
||||
return _mat;
|
||||
}
|
||||
|
||||
float getMaterialOpacity(Material m) { return m._diffuse.a; }
|
||||
vec3 getMaterialDiffuse(Material m) { return m._diffuse.rgb; }
|
||||
vec3 getMaterialSpecular(Material m) { return m._specular.rgb; }
|
||||
float getMaterialShininess(Material m) { return m._specular.a; }
|
||||
|
||||
|
||||
// the interpolated normal
|
||||
in vec3 _normal;
|
||||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
Material material = getMaterial();
|
||||
packDeferredFragment(
|
||||
normalize(_normal.xyz),
|
||||
glowIntensity,
|
||||
_color.rgb,
|
||||
DEFAULT_SPECULAR, DEFAULT_SHININESS);
|
||||
}
|
||||
|
||||
)SCRIBE";
|
||||
|
||||
#endif
|
113
tests/gpu-test/src/gputest_simple_vert.h
Normal file
113
tests/gpu-test/src/gputest_simple_vert.h
Normal file
|
@ -0,0 +1,113 @@
|
|||
// File generated by Scribe Wed Aug 5 16:50:23 2015
|
||||
#ifndef scribe_simple_vert_h
|
||||
#define scribe_simple_vert_h
|
||||
|
||||
const char simple_vert[] = R"SCRIBE(#version 410 core
|
||||
// Generated on Wed Aug 5 16:50:23 2015
|
||||
//
|
||||
// simple.vert
|
||||
// vertex shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/15/14.
|
||||
// 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
|
||||
//
|
||||
|
||||
in vec4 inPosition;
|
||||
in vec4 inNormal;
|
||||
in vec4 inColor;
|
||||
in vec4 inTexCoord0;
|
||||
in vec4 inTangent;
|
||||
in vec4 inSkinClusterIndex;
|
||||
in vec4 inSkinClusterWeight;
|
||||
in vec4 inTexCoord1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct TransformObject {
|
||||
mat4 _model;
|
||||
mat4 _modelInverse;
|
||||
};
|
||||
|
||||
struct TransformCamera {
|
||||
mat4 _view;
|
||||
mat4 _viewInverse;
|
||||
mat4 _projectionViewUntranslated;
|
||||
mat4 _projection;
|
||||
mat4 _projectionInverse;
|
||||
vec4 _viewport;
|
||||
};
|
||||
|
||||
uniform transformObjectBuffer {
|
||||
TransformObject _object;
|
||||
};
|
||||
TransformObject getTransformObject() {
|
||||
return _object;
|
||||
}
|
||||
|
||||
uniform transformCameraBuffer {
|
||||
TransformCamera _camera;
|
||||
};
|
||||
TransformCamera getTransformCamera() {
|
||||
return _camera;
|
||||
}
|
||||
|
||||
|
||||
// the interpolated normal
|
||||
|
||||
out vec3 _normal;
|
||||
out vec3 _color;
|
||||
out vec2 _texCoord0;
|
||||
|
||||
void main(void) {
|
||||
_color = inColor.rgb;
|
||||
_texCoord0 = inTexCoord0.st;
|
||||
|
||||
// standard transform
|
||||
TransformCamera cam = getTransformCamera();
|
||||
TransformObject obj = getTransformObject();
|
||||
|
||||
|
||||
{ // transformModelToClipPos
|
||||
vec4 _eyepos = (obj._model * inPosition) + vec4(-inPosition.w * cam._viewInverse[3].xyz, 0.0);
|
||||
gl_Position = cam._projectionViewUntranslated * _eyepos;
|
||||
}
|
||||
|
||||
|
||||
{ // transformModelToEyeDir
|
||||
vec3 mr0 = vec3(obj._modelInverse[0].x, obj._modelInverse[1].x, obj._modelInverse[2].x);
|
||||
vec3 mr1 = vec3(obj._modelInverse[0].y, obj._modelInverse[1].y, obj._modelInverse[2].y);
|
||||
vec3 mr2 = vec3(obj._modelInverse[0].z, obj._modelInverse[1].z, obj._modelInverse[2].z);
|
||||
|
||||
vec3 mvc0 = vec3(dot(cam._viewInverse[0].xyz, mr0), dot(cam._viewInverse[0].xyz, mr1), dot(cam._viewInverse[0].xyz, mr2));
|
||||
vec3 mvc1 = vec3(dot(cam._viewInverse[1].xyz, mr0), dot(cam._viewInverse[1].xyz, mr1), dot(cam._viewInverse[1].xyz, mr2));
|
||||
vec3 mvc2 = vec3(dot(cam._viewInverse[2].xyz, mr0), dot(cam._viewInverse[2].xyz, mr1), dot(cam._viewInverse[2].xyz, mr2));
|
||||
|
||||
_normal = vec3(dot(mvc0, inNormal.xyz), dot(mvc1, inNormal.xyz), dot(mvc2, inNormal.xyz));
|
||||
}
|
||||
|
||||
}
|
||||
)SCRIBE";
|
||||
|
||||
#endif
|
|
@ -43,7 +43,8 @@
|
|||
#include <GeometryCache.h>
|
||||
|
||||
#include "gputest_shaders.h"
|
||||
|
||||
#include "gputest_simple_frag.h"
|
||||
#include "gputest_simple_vert.h"
|
||||
|
||||
class RateCounter {
|
||||
std::vector<float> times;
|
||||
|
@ -313,6 +314,8 @@ public:
|
|||
|
||||
_cubeModel = makeCube();
|
||||
|
||||
DependencyManager::set<GeometryCache>();
|
||||
|
||||
// makeCurrent();
|
||||
// _context->syncCache();
|
||||
|
||||
|
@ -355,19 +358,52 @@ void renderTestScene (gpu::Batch & batch) {
|
|||
gpu::PipelinePointer pipeline { nullptr };
|
||||
|
||||
std::call_once(initFlag, [&](){
|
||||
|
||||
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(simple_vert)));
|
||||
auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_frag)));
|
||||
auto shader = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs));
|
||||
|
||||
gpu::Shader::BindingSet bindings;
|
||||
if (!gpu::Shader::makeProgram(*shader, bindings)) {
|
||||
printf("Could not compile shader\n");
|
||||
if (!vs)
|
||||
printf("bad vertex shader\n");
|
||||
if (!fs)
|
||||
printf("bad fragment shader\n");
|
||||
if (!shader)
|
||||
printf("bad shader program\n");
|
||||
exit(-1);
|
||||
}
|
||||
auto state = std::make_shared<gpu::State>();
|
||||
state->setMultisampleEnable(true);
|
||||
state->setDepthTest({ true });
|
||||
pipeline = gpu::PipelinePointer(gpu::Pipeline::create(shader, state));
|
||||
});
|
||||
|
||||
batch.setPipeline(pipeline);
|
||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||
|
||||
geometryCache->renderGrid(batch, 4, 4, { 0.2f, 0.3f, 0.7f, 1.0f });
|
||||
float scale = 80.0f;
|
||||
|
||||
batch.setModelTransform(Transform(glm::angleAxis(40.0f, glm::vec3{ 0.0f, 1.0f, 0.0f}), glm::vec3 { scale }, glm::vec3 { -50.0f, -50.0f, 0.0f }));
|
||||
// geometryCache->renderGrid(batch, 800, 800, { 0.35f, 0.25f, 0.15f, 1.0f });
|
||||
// geometryCache->renderGrid(batch, 200, 200, { 0.4f, 0.4f, 0.9f, 1.0f });
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
batch.setModelTransform(Transform());
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
geometryCache->renderLine(batch, { -100.0f, -1.0f, -50.0f + float(i) }, { 100.0f, -1.0f, -50.0f + float(i) }, { 0.35f, 0.25f, 0.15f, 1.0f });
|
||||
}
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
geometryCache->renderLine(batch, { -50.0f + float(i), -1.0f, -100.0f}, { -50.0f + float(i), -1.0f, 100.0f }, { 0.15f, 0.25f, 0.35f, 1.0f });
|
||||
}
|
||||
|
||||
geometryCache->renderUnitCube(batch);
|
||||
geometryCache->renderWireCube(batch, 1.0f, { 0.4f, 0.4f, 0.7f, 1.0f });
|
||||
|
||||
batch.setModelTransform(Transform().setTranslation({ 1.5f, -0.5f, -0.5f }));
|
||||
geometryCache->renderSphere(batch, 0.5f, 50, 50, { 0.8f, 0.25f, 0.25f });
|
||||
// geometryCache->renderWireCube(batch, 1.0f, { 0.2f, 0.2f, 0.2f, 1.0f });
|
||||
}
|
||||
|
||||
void QTestWindow::draw() {
|
||||
if (!isVisible()) {
|
||||
|
@ -383,61 +419,37 @@ void QTestWindow::draw() {
|
|||
float ks = glm::sin(glm::pi<float>() * 2.0f * k);
|
||||
|
||||
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 0.1, 0.1, 0.1, 1.0 });
|
||||
batch.clearDepthFramebuffer(100.0f);
|
||||
batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() });
|
||||
|
||||
// glm::vec3 camera_focus { 5.0f * cos(t * 0.1f), 0.0f, 0.0f };
|
||||
glm::vec3 camera_focus { 0.0f, 0.0f, 0.0f };
|
||||
|
||||
glm::vec3 unitscale { 1.0f };
|
||||
glm::vec3 up { 0.0f, 1.0f, 0.0f };
|
||||
glm::vec3 cam_pos { 1.5f * sin(t), 0.0f, 2.0f };
|
||||
// glm::vec3 cam_pos { 5.0f * sin(t * 0.1f), 1.0f, 10.0f };
|
||||
// glm::quat cam_rotation;
|
||||
glm::quat cam_rotation = glm::quat_cast(glm::lookAt(cam_pos, camera_focus, up));
|
||||
cam_rotation.w = -cam_rotation.w;
|
||||
Transform cam_transform { cam_rotation, unitscale, cam_pos };
|
||||
|
||||
|
||||
float fov_degrees = 60;
|
||||
// float aspect_ratio = _size.height() / (_size.width() || 1.0f);
|
||||
float aspect_ratio = (float)_size.width() / _size.height();
|
||||
// float aspect_ratio = 16.0f / 9.0f;
|
||||
float near_clip = 0.1f;
|
||||
float far_clip = 1000.0f;
|
||||
auto projection = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip);
|
||||
|
||||
batch.setProjectionTransform(projection);
|
||||
|
||||
|
||||
// batch.setViewTransform(Transform().setTranslation({ 1.5f * sin(t), 0.5f, 1.0f }));
|
||||
batch.setViewTransform(cam_transform);
|
||||
|
||||
renderTestScene(batch);
|
||||
//
|
||||
//
|
||||
// // camera at x: 5 * sin(t)
|
||||
// // y: 1,
|
||||
// // z: +10
|
||||
// // obj at (0, 0, 0)
|
||||
// // camera is looking at obj (using glm::lookAt)
|
||||
//
|
||||
// glm::vec3 up { 0.0f, 1.0f, 0.0f };
|
||||
// glm::vec3 unitscale { 1.0f };
|
||||
//
|
||||
// float cube_angle = 0.0f;
|
||||
// // glm::vec3 cube_pos {
|
||||
// // 0.0f,
|
||||
// // 0.0f,
|
||||
// // 0.0f
|
||||
// // };
|
||||
// glm::vec3 cube_pos {
|
||||
// 20.0f * cos(t * 5.0f),
|
||||
// 10.0f * sin(t * 2.5f) + 1.0f,
|
||||
// -15.0f + float(int(t * int(1e3)) % int(1e4)) / 1e3
|
||||
// };
|
||||
//
|
||||
// // float cube_angle = 360.0f * k * 1.25 + 120.0f * k * 0.1f;
|
||||
// // glm::quat cube_rotation = glm::angleAxis(glm::radians(cube_angle), up);
|
||||
// glm::quat cube_rotation;
|
||||
// Transform cube_transform { cube_rotation, unitscale, cube_pos };
|
||||
//
|
||||
// // glm::vec3 cam_pos { 0.0f, 0.0f, -10.0f };
|
||||
// glm::vec3 cam_pos { 5.0f * sin(t * 0.1f), 1.0f, -10.0f };
|
||||
// glm::quat cam_rotation = glm::quat_cast(glm::lookAt(cam_pos, cube_pos, up));
|
||||
// cam_rotation.w = -cam_rotation.w;
|
||||
// Transform cam_transform { cam_rotation, unitscale, cam_pos };
|
||||
//
|
||||
// float fov_degrees = 120.0f;
|
||||
// // float aspect_ratio = _size.height() / (_size.width() || 1.0f);
|
||||
// float aspect_ratio = 16.0f / 9.0f;
|
||||
// float near_clip = 0.1f;
|
||||
// float far_clip = 1000.0f;
|
||||
// auto projection = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip);
|
||||
//
|
||||
// batch.setProjectionTransform(projection);
|
||||
// batch.setViewTransform(cam_transform);
|
||||
// batch.setModelTransform(cube_transform);
|
||||
//
|
||||
// batch.setModelTransform(Transform().setTranslation({ 20.0f * cos(t * 5.0f), 10.0f * sin(t * 2.5f + 1.0f), -15.0f + float(int(t * 1000) % 10000) / 1e3f}));
|
||||
// // batch.setPipeline(_pipeline);
|
||||
// // batch.setInputBuffer(gpu::Stream::POSITION, _buffer, 0, 3);
|
||||
// // batch.setInputFormat(_format);
|
||||
// // batch.draw(gpu::TRIANGLES, 3);
|
||||
//
|
||||
// renderCube(batch, *_cubeModel);
|
||||
|
||||
_context->render(batch);
|
||||
_qGlContext->swapBuffers(this);
|
||||
|
|
29
tests/gpu-test/src/simple.slf
Normal file
29
tests/gpu-test/src/simple.slf
Normal file
|
@ -0,0 +1,29 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// simple.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/15/14.
|
||||
// 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@>
|
||||
<@include model/Material.slh@>
|
||||
|
||||
// the interpolated normal
|
||||
in vec3 _normal;
|
||||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
Material material = getMaterial();
|
||||
packDeferredFragment(
|
||||
normalize(_normal.xyz),
|
||||
glowIntensity,
|
||||
_color.rgb,
|
||||
DEFAULT_SPECULAR, DEFAULT_SHININESS);
|
||||
}
|
36
tests/gpu-test/src/simple.slv
Normal file
36
tests/gpu-test/src/simple.slv
Normal file
|
@ -0,0 +1,36 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// simple.vert
|
||||
// vertex shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/15/14.
|
||||
// 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 gpu/Inputs.slh@>
|
||||
|
||||
<@include gpu/Transform.slh@>
|
||||
|
||||
<$declareStandardTransform()$>
|
||||
|
||||
// the interpolated normal
|
||||
|
||||
out vec3 _normal;
|
||||
out vec3 _color;
|
||||
out vec2 _texCoord0;
|
||||
|
||||
void main(void) {
|
||||
_color = inColor.rgb;
|
||||
_texCoord0 = inTexCoord0.st;
|
||||
|
||||
// standard transform
|
||||
TransformCamera cam = getTransformCamera();
|
||||
TransformObject obj = getTransformObject();
|
||||
<$transformModelToClipPos(cam, obj, inPosition, gl_Position)$>
|
||||
<$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal)$>
|
||||
}
|
Loading…
Reference in a new issue