mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-12 14:29:42 -05:00
Volume raycasting jittering
- Added jitter to volume rendering, reducing artefacts - Added tracking of more shader files to update the resolve shader
This commit is contained in:
@@ -79,6 +79,9 @@ private:
|
||||
std::vector<ghoul::filesystem::File*> _samplerFiles;
|
||||
std::vector<std::string> _samplers;
|
||||
|
||||
// Development functionality to update shader for changes in several files
|
||||
std::vector<ghoul::filesystem::File*> _shaderFiles;
|
||||
|
||||
|
||||
|
||||
}; // ABuffer
|
||||
|
||||
@@ -56,6 +56,10 @@ float pscLength(vec4 v1, vec4 v2) {
|
||||
return length(vector.xyz)*pow(k,vector.w);
|
||||
}
|
||||
|
||||
float permute(float i) {
|
||||
return mod((62.0*i*i + i), 961.0); // permutation polynomial; 62=2*31; 961=31*31
|
||||
}
|
||||
|
||||
void sort_fragments_list(uint frag_count) {
|
||||
uint i,j;
|
||||
ABufferStruct_t tmp;
|
||||
@@ -91,6 +95,17 @@ void sort_fragments_list(uint frag_count) {
|
||||
// volume_zlength[ii] = pscLength(_pos_(fragments[jj]), startPosition);
|
||||
volumeStepSize[ii] = 1.0/(length(volume_direction[ii]*volume_dim[ii]));
|
||||
// volume_length[ii] = pscLength(_pos_(fragments[jj]), startPosition);
|
||||
|
||||
if(volumeStepSize[ii] < volume_length[ii]) {
|
||||
// jittering
|
||||
float x = gl_FragCoord.x;
|
||||
float y = gl_FragCoord.y;
|
||||
float jitterValue = float(permute(x + permute(y))) / 961.0;
|
||||
jitterValue *= 0.004;
|
||||
vec3 frontPosNew = startColor + (jitterValue*volume_length[ii])*volume_direction[ii];
|
||||
volume_position[ii] = frontPosNew;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ uniform sampler2D texture1;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_position;
|
||||
in vec3 vs_position;
|
||||
in float s;
|
||||
|
||||
#include "ABuffer/abufferStruct.hglsl"
|
||||
#include "ABuffer/abufferAddToBuffer.hglsl"
|
||||
@@ -37,10 +38,11 @@ in vec4 vs_position;
|
||||
|
||||
void main()
|
||||
{
|
||||
float depth = pscDepth(vs_position);
|
||||
vec4 position = vec4(vs_position,s);
|
||||
float depth = pscDepth(position);
|
||||
vec4 diffuse = texture(texture1, vs_st);
|
||||
|
||||
ABufferStruct_t frag = createGeometryFragment(diffuse, vs_position, depth);
|
||||
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
|
||||
addToBuffer(frag);
|
||||
|
||||
discard;
|
||||
|
||||
+13
-18
@@ -31,13 +31,6 @@ uniform mat4 camrot;
|
||||
uniform vec2 scaling;
|
||||
uniform vec4 objpos;
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
uniform sampler2D texture3;
|
||||
uniform float TessLevel;
|
||||
uniform bool Wireframe;
|
||||
uniform bool Lightsource;
|
||||
uniform bool UseTexture;
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
//in vec3 in_position;
|
||||
@@ -47,10 +40,10 @@ layout(location = 2) in vec3 in_normal;
|
||||
out vec2 vs_st;
|
||||
out vec3 vs_stp;
|
||||
out vec4 vs_normal;
|
||||
out vec4 vs_position;
|
||||
out vec3 vs_position;
|
||||
out float s;
|
||||
|
||||
const float k = 10.0;
|
||||
const float dgr_to_rad = 0.0174532925;
|
||||
|
||||
vec4 psc_addition(vec4 v1, vec4 v2) {
|
||||
float ds = v2.w - v1.w;
|
||||
@@ -92,25 +85,27 @@ void main()
|
||||
//vec4 lvp = ModelTransform * in_position;
|
||||
|
||||
// PSC addition; local vertex position and the object power scaled world position
|
||||
vs_position = psc_addition(vec4(local_vertex_pos,in_position.w),objpos);
|
||||
//vs_position = psc_addition(lvp,objpos);
|
||||
vec4 position = psc_addition(vec4(local_vertex_pos,in_position.w),objpos);
|
||||
//position = psc_addition(lvp,objpos);
|
||||
|
||||
// PSC addition; rotated and viewscaled vertex and the cmaeras negative position
|
||||
vs_position = psc_addition(vs_position,vec4(-campos.xyz,campos.w));
|
||||
position = psc_addition(position,vec4(-campos.xyz,campos.w));
|
||||
|
||||
// rotate the camera
|
||||
local_vertex_pos = mat3(camrot) * vs_position.xyz;
|
||||
vs_position = vec4(local_vertex_pos, vs_position.w);
|
||||
//vs_position = camrot* vs_position;
|
||||
local_vertex_pos = mat3(camrot) * position.xyz;
|
||||
position = vec4(local_vertex_pos, position.w);
|
||||
//position = camrot* position;
|
||||
|
||||
// rescales the scene to fit inside the view frustum
|
||||
// is set from the main program, but these are decent values
|
||||
// scaling = vec2(1.0, -8.0);
|
||||
|
||||
// project using the rescaled coordinates,
|
||||
//vec4 vs_position_rescaled = psc_scaling(vs_position, scaling);
|
||||
vec4 vs_position_rescaled = psc_to_meter(vs_position, scaling);
|
||||
vs_position = vs_position_rescaled;
|
||||
//vec4 vs_position_rescaled = psc_scaling(position, scaling);
|
||||
vec4 vs_position_rescaled = psc_to_meter(position, scaling);
|
||||
position = vs_position_rescaled;
|
||||
vs_position = vs_position_rescaled.xyz;
|
||||
s = vs_position_rescaled.w;
|
||||
|
||||
|
||||
// project the position to view space
|
||||
|
||||
@@ -62,6 +62,14 @@ ABuffer::~ABuffer() {
|
||||
|
||||
if(_resolveShader)
|
||||
delete _resolveShader;
|
||||
|
||||
for(auto file: _samplerFiles) {
|
||||
delete file;
|
||||
}
|
||||
for(auto file: _shaderFiles) {
|
||||
delete file;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool ABuffer::initializeABuffer() {
|
||||
@@ -73,6 +81,17 @@ bool ABuffer::initializeABuffer() {
|
||||
};
|
||||
_fragmentShaderFile->setCallback(shaderCallback);
|
||||
|
||||
// Development functionality to update shader for changes in several files
|
||||
auto addFunc = [this, shaderCallback](const std::string& path) {
|
||||
ghoul::filesystem::File* f = new ghoul::filesystem::File(path, false);
|
||||
f->setCallback(shaderCallback);
|
||||
_shaderFiles.push_back(f);
|
||||
};
|
||||
addFunc("${SHADERS}/ABuffer/abufferSort.hglsl");
|
||||
addFunc("${SHADERS}/ABuffer/abufferAddToBuffer.hglsl");
|
||||
addFunc("${SHADERS}/ABuffer/abufferStruct.hglsl");
|
||||
|
||||
|
||||
_resolveShader = nullptr;
|
||||
generateShaderSource();
|
||||
updateShader();
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <string>
|
||||
|
||||
#define MAX_LAYERS 10
|
||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||
|
||||
namespace {
|
||||
std::string _loggerCat = "ABufferSingleLinked";
|
||||
|
||||
Reference in New Issue
Block a user