TESTVOXELGPU: added shaders
parent
eec260a1e2
commit
093022c11f
|
@ -3,5 +3,6 @@ set(SRCS
|
|||
TestVoxelGPU.h TestVoxelGPU.cpp
|
||||
)
|
||||
engine_add_executable(TARGET ${PROJECT_NAME} SRCS ${SRCS} WINDOWED NOINSTALL)
|
||||
engine_target_link_libraries(TARGET ${PROJECT_NAME} DEPENDENCIES testcore)
|
||||
engine_target_link_libraries(TARGET ${PROJECT_NAME} DEPENDENCIES testcore compute voxel)
|
||||
#generate_shaders(${PROJECT_NAME} testvoxelgpu)
|
||||
generate_compute_shaders(${PROJECT_NAME} mesher)
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
*/
|
||||
#include "TestVoxelGPU.h"
|
||||
#include "io/Filesystem.h"
|
||||
#include "compute/Compute.h"
|
||||
#include "voxel/MaterialColor.h"
|
||||
|
||||
TestVoxelGPU::TestVoxelGPU(const metric::MetricPtr& metric, const io::FilesystemPtr& filesystem, const core::EventBusPtr& eventBus, const core::TimeProviderPtr& timeProvider) :
|
||||
Super(metric, filesystem, eventBus, timeProvider) {
|
||||
Super(metric, filesystem, eventBus, timeProvider), _mesher(compute::MesherShader::getInstance()) {
|
||||
init(ORGANISATION, "testvoxelgpu");
|
||||
}
|
||||
|
||||
|
@ -15,11 +17,27 @@ core::AppState TestVoxelGPU::onInit() {
|
|||
return state;
|
||||
}
|
||||
|
||||
if (!compute::init()) {
|
||||
return core::AppState::InitFailure;
|
||||
}
|
||||
|
||||
if (!_mesher.setup()) {
|
||||
return core::AppState::InitFailure;
|
||||
}
|
||||
|
||||
if (!voxel::initDefaultMaterialColors()) {
|
||||
Log::error("Failed to initialize the palette data");
|
||||
return core::AppState::InitFailure;
|
||||
}
|
||||
|
||||
video::clearColor(::core::Color::White);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
core::AppState TestVoxelGPU::onCleanup() {
|
||||
core::AppState state = Super::onCleanup();
|
||||
_mesher.shutdown();
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "testcore/TestApp.h"
|
||||
#include "TestvoxelgpuShaders.h"
|
||||
|
||||
class TestVoxelGPU: public TestApp {
|
||||
private:
|
||||
using Super = TestApp;
|
||||
compute::MesherShader& _mesher;
|
||||
|
||||
void doRender() override;
|
||||
public:
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#if 0
|
||||
__constant sampler_t volumeSampler =
|
||||
CLK_NORMALIZED_COORDS_FALSE
|
||||
| CLK_ADDRESS_CLAMP_TO_EDGE
|
||||
| CLK_FILTER_NEAREST;
|
||||
#endif
|
||||
|
||||
__kernel void render(__read_only image3d_t volume, sampler_t volumeSampler, __global uchar *output, uint imageWidth, uint imageHeight, float w) {
|
||||
uint x = get_global_id(0);
|
||||
uint y = get_global_id(1);
|
||||
|
||||
float u = x / (float) imageWidth;
|
||||
float v = y / (float) imageHeight;
|
||||
|
||||
uint4 voxel = read_imageui(volume, volumeSampler, (float4)(u, v, w, 1.0f));
|
||||
|
||||
if (x < imageWidth && y < imageHeight) {
|
||||
uint i = (((imageHeight - 1) - y) * imageWidth * 4) + x * 4;
|
||||
output[i + 0] = output[i + 1] = output[i + 2] = 0;
|
||||
output[i + 3] = 255;
|
||||
if (voxel[0] == 0) { // empty
|
||||
output[i + 2] = 255;
|
||||
} else if (voxel[0] == 3) { // grass
|
||||
output[i + 1] = 255;
|
||||
} else if (voxel[0] == 14) { // dirt
|
||||
output[i + 0] = 127;
|
||||
output[i + 1] = 64;
|
||||
} else { // unknown 0xff00ffff
|
||||
output[i + 0] = 255;
|
||||
output[i + 1] = 0;
|
||||
output[i + 2] = 255;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue