Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFT system module and new audiovisual demo #38

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
05bf7bf
add napfft module and basic audiovisual demo
lshoek Nov 29, 2023
8201333
fft audio node fixes - demo improvement shows distinct frequency bins
lshoek Nov 30, 2023
38e8668
compile kissfft from source
lshoek Dec 4, 2023
e82bebd
add mid frequency measurement to audiovisual demo
lshoek Dec 4, 2023
84a6563
safekeeping fft on polar coordinates shader
lshoek Dec 6, 2023
25e4155
audiovisual demonstrate mesh normals compute shader update
lshoek Dec 12, 2023
0649d0a
separate mesh compute from rendering - add sky - make cool road thing
lshoek Dec 14, 2023
46c646c
Merge branch 'naprenderadvanced' into napfft
lshoek Dec 18, 2023
25c7bc6
three rotational dof - fix compute shader invocations - parameterization
lshoek Dec 19, 2023
789a6f5
Merge branch 'naprenderadvanced' into napfft
lshoek Dec 19, 2023
6072bce
Merge branch 'naprenderadvanced' into napfft
lshoek Dec 20, 2023
14088b6
update audiovisual demo to use renderadvanced light system
lshoek Dec 21, 2023
475f629
Merge branch 'naprenderadvanced' into napfft
lshoek Jan 4, 2024
55f28ae
Merge branch 'naprenderadvanced' into napfft
lshoek Jan 14, 2024
16dc899
prerender stars cube map and render reflection in road
lshoek Jan 14, 2024
e82b738
Merge branch 'naprenderadvanced' into napfft
lshoek Jan 15, 2024
ae01b11
remove gridfillpolicy
lshoek Jan 16, 2024
ea55ad8
fix plane artifacts - add dof and chroma vfx - rename fft to audioroad
lshoek Jan 16, 2024
bba0c40
Merge branch 'naprenderadvanced' of github.com:naivisoftware/nap into…
lshoek Jan 17, 2024
9622667
update to napportaudio
lshoek Jan 17, 2024
7bf301d
buffer size check on init - improve dof
lshoek Jan 17, 2024
2230a07
rerender cube map when reinitialized after reload
lshoek Jan 17, 2024
aa94bd0
audiovisual demo cleanup - renderdofcomponent improvement
lshoek Jan 17, 2024
1e0d37a
fix depth of field component - document demo
lshoek Jan 17, 2024
bfff21d
Merge branch '0.7' of github.com:naivisoftware/nap into napfft
lshoek Jan 17, 2024
cba12e6
audiovisual demo documentation
lshoek Jan 17, 2024
2303a98
Merge branch 'naprenderadvanced' of github.com:naivisoftware/nap into…
lshoek Mar 12, 2024
9145a9d
Merge branch 'naprenderadvanced' into napfft
lshoek Mar 19, 2024
3e4b85e
fix compilation after render advanced update
lshoek Mar 19, 2024
be204f4
restore reflection effect in audiovisual demo
lshoek Mar 19, 2024
e3b46dd
Merge branch 'naprenderadvanced' into napfft
lshoek Mar 21, 2024
105c180
Merge branch '0.7' into napfft
lshoek Apr 2, 2024
a7b2f83
cleanup fluxmeasurement comp interface and implementation
lshoek Apr 2, 2024
bce52e8
fftbuffer additional documentation
lshoek Apr 2, 2024
a664f14
Merge branch 'main' into napfft
cklosters Jul 16, 2024
241c43e
fix kissfft thirdparty packaging and deployment - only include and co…
cklosters Jul 16, 2024
6845456
improve kissfft source / target license definitions
cklosters Jul 16, 2024
d5c1bc4
fix compilation GCC
cklosters Jul 22, 2024
3c8d28d
Merge remote-tracking branch 'origin/napfft' into napfft
cklosters Jul 22, 2024
8a7a6fb
fix compilation GCC
cklosters Jul 22, 2024
973404a
remove not used (not applied) GPL license
cklosters Jul 22, 2024
13c9c9f
Merge branch 'main' into napfft
cklosters Aug 7, 2024
254009a
change default render index to 1
cklosters Aug 7, 2024
d466d7a
change defaults
cklosters Aug 7, 2024
60b5d19
First batch of changes based on review
cklosters Aug 13, 2024
e0d083c
Second batch of review changes
cklosters Aug 13, 2024
70c265f
don't perform dirty check and make dirty flag atomic
cklosters Aug 13, 2024
b14bd70
simplify & optimize threaded sample data transfer
cklosters Aug 13, 2024
3b2da12
Third batch of review changes
cklosters Aug 13, 2024
27dbd02
add MPL license
cklosters Aug 13, 2024
647f527
fix gcc
cklosters Aug 14, 2024
ee3df1d
Merge branch 'main' into napfft
cklosters Aug 14, 2024
59b9ca0
Merge branch 'main' into napfft
cklosters Aug 19, 2024
9673a60
Merge branch 'main' into napfft
cklosters Sep 3, 2024
a50d330
fix formatted buffer zero padding using zero fill instead of clear
lshoek Sep 16, 2024
23702a5
fix error message leak in portaudioservice
lshoek Sep 23, 2024
b1deff0
Merge branch 'main' into napfft
lshoek Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix plane artifacts - add dof and chroma vfx - rename fft to audioroad
  • Loading branch information
lshoek committed Jan 16, 2024
commit ea55ad80216a053aa4f65eb741c192650157e34e
535 changes: 375 additions & 160 deletions demos/audiovisual/data/objects.json

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions demos/audiovisual/data/shaders/composite.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#version 450 core

// Ensure we register a constant to set
layout(constant_id = 0) const uint CHROMATIC_ABBERATION = 0;

uniform FRAGUBO
{
float blend;
float abberation;
} ubo;

in vec3 pass_UV;

out vec4 out_Color;

uniform sampler2D colorTexture;

vec4 chromatic_abberation_sample(sampler2D tex, vec2 uv)
{
const vec2 ctr = { 0.5, 0.5 };
const ivec2 res = textureSize(tex, 0);
vec2 diff = uv - ctr;
float intensity = clamp(length(diff), 0.0, 1.0);
vec2 d = normalize(diff) * intensity * ubo.abberation;

vec4 col = vec4(0.0);
col.r = texture(tex, uv + d).r;
col.ga = texture(tex, uv).ga;
col.b = texture(tex, uv - d).b;

return col;
}

void main(void)
{
// Get texel color values
vec4 col = (CHROMATIC_ABBERATION > 0) ?
chromatic_abberation_sample(colorTexture, pass_UV.xy) :
texture(colorTexture, pass_UV.xy);

out_Color = vec4(col.rgb, 1.0);
}
26 changes: 26 additions & 0 deletions demos/audiovisual/data/shaders/composite.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#version 450 core

uniform nap
{
mat4 projectionMatrix;
mat4 viewMatrix;
mat4 modelMatrix;
} mvp;

in vec3 in_Position;
in vec3 in_UV0;

out vec3 pass_UV;

void main(void)
{
// Calculate position
gl_Position = mvp.projectionMatrix * mvp.viewMatrix * mvp.modelMatrix * vec4(in_Position, 1.0);

// Pass uv's
pass_UV = in_UV0;
}
3 changes: 1 addition & 2 deletions demos/audiovisual/data/shaders/constantvec4.frag
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ out vec4 out_Color;

void main()
{
float d = (1.0-passUV0.y);
out_Color = vec4(ubo.color, ubo.alpha * d);
out_Color = vec4(ubo.color, ubo.alpha * passUV0.y);
}

69 changes: 69 additions & 0 deletions demos/audiovisual/data/shaders/dof.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#version 450

// Extensions
#extension GL_GOOGLE_include_directive : enable

// Includes
#include "shadow.glslinc"

uniform UBO
{
vec2 textureSize; // The size of 'colorTexture', used to pre-calculate sampling coordinates in vertex shader
vec2 direction; // The sampling direction
vec2 nearFar; // camera near/far planes
float aperture;
float focusDistance;
float focusPower;
} ubo;

uniform sampler2D colorTexture; // The input color texture to sample from
uniform sampler2D depthTexture; // The input color texture to sample from

in vec2 pass_UV;
out vec4 out_Color;

const float weight[] = { 0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162 };


// Sampler must be configured with filter VK_FILTER_LINEAR
vec4 blur(sampler2D tx, vec4 col, float s)
{
const vec2 offset[] = {
{ 0.0, 0.0 },
ubo.direction * (1.0/ubo.textureSize),
ubo.direction * (2.0/ubo.textureSize),
ubo.direction * (3.0/ubo.textureSize),
ubo.direction * (4.0/ubo.textureSize)
};

col = col * weight[0];
for (uint i = 1; i < offset.length(); i++)
{
col += texture(tx, pass_UV + offset[i] * s) * weight[i];
col += texture(tx, pass_UV - offset[i] * s) * weight[i];
}
return col;
}


void main()
{
// Adding this small constant to resolve sampling artifacts in cube seams
float near = min(ubo.nearFar.x + 0.001, ubo.nearFar.y);
float far = ubo.nearFar.y;

vec4 frag_col = texture(colorTexture, pass_UV);
float frag_depth = texture(depthTexture, pass_UV).x;

// https://developer.nvidia.com/gpugems/gpugems/part-iv-image-processing/chapter-23-depth-field-survey-techniques
const float aperture = ubo.aperture;
const float focal = 0.5;
const float focus = 1.0 + ubo.focusDistance*0.01;

float coc_scale = (aperture * focal * focus * (far - near)) / ((focus - focal) * near * far);
float coc_bias = (aperture * focal * (near - focus)) / ((focus * focal) * near);
float coc = abs(frag_depth * coc_scale + coc_bias);

out_Color = blur(colorTexture, frag_col, min(pow(coc, max(ubo.focusPower, 1.0)), 4.0));
}

19 changes: 19 additions & 0 deletions demos/audiovisual/data/shaders/dof.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#version 450

uniform nap
{
mat4 projectionMatrix;
mat4 viewMatrix;
mat4 modelMatrix;
} mvp;

in vec3 in_Position;
in vec3 in_UV0;

out vec2 pass_UV;

void main()
{
pass_UV = in_UV0.xy;
gl_Position = mvp.projectionMatrix * mvp.viewMatrix * mvp.modelMatrix * vec4(in_Position, 1.0);
}
2 changes: 1 addition & 1 deletion demos/audiovisual/data/shaders/normals.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#version 450
#version 450 core

// NAP overwrites the workgroup size specialization constant, when detected and not 0, with the maximum group
// size supported by the device on pipeline creation.
Expand Down
4 changes: 3 additions & 1 deletion demos/audiovisual/data/shaders/phongvec4.frag
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ uniform sampler2DShadow shadowMaps[MAX_LIGHTS];
uniform samplerCubeShadow cubeShadowMaps[MAX_LIGHTS];
uniform samplerCube environmentMap;

const float highlightLength = 0.015;

void main()
{
// Diffuse-only early exit for debugging purposes
Expand Down Expand Up @@ -166,7 +168,7 @@ void main()
}

color_result = mix(color_result, ubo.fresnelColor, passFresnel);
color_result = mix(color_result, ubo.highlight, smoothstep(0.975, 1.0, 1.0-passUV0.y));
color_result = mix(color_result, ubo.highlight, smoothstep(1.0-highlightLength, 1.0, passUV0.y));
out_Color = vec4(color_result, ubo.alpha);
}

16 changes: 14 additions & 2 deletions demos/audiovisual/data/shaders/positions.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#version 450
#version 450 core

// Extensions
#extension GL_GOOGLE_include_directive : enable

// Includes
#include "noise.glslinc"

// NAP overwrites the workgroup size specialization constant, when detected and not 0, with the maximum group
// size supported by the device on pipeline creation.
Expand Down Expand Up @@ -35,6 +41,9 @@ uniform UBO
float prevAmps[COLUMN_COUNT];
float flux;
float bump;
float elapsedTime;
float noiseStrength;
float noiseScale;
} ubo;

const float TWO_PI = 6.283185;
Expand All @@ -59,11 +68,14 @@ void main()
float height = weighted_sample(ubo.amps[gid], gid);
height = mix(prev * 0.95, height, 0.5) * ubo.bump;

float uvx = (gid%COLUMN_COUNT)/float(COLUMN_COUNT);
vec4 n = simplexd(vec3((uvx*2.0-1.0)*ubo.noiseScale, ubo.elapsedTime, 0.0));
height += n.w * ubo.noiseStrength;

vec3 forward = ubo.direction;
vec3 right = ubo.tangent;
vec3 up = ubo.up;

float uvx = (gid%COLUMN_COUNT)/float(COLUMN_COUNT);
vec3 p = ubo.origin + (uvx * right - right * 0.5) + height * up + forward * cell_size.y;
outpositions[gid] = vec4(p, ubo.flux);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "fftmeshcomponent.h"
#include "audioroadcomponent.h"

// External Includes
#include <entity.h>
Expand All @@ -10,24 +10,27 @@
#include <glm/gtc/noise.hpp>
#include <glm/gtx/vec_swizzle.hpp>

// nap::FFTMeshComponent run time class definition
RTTI_BEGIN_CLASS(nap::FFTMeshComponent)
RTTI_PROPERTY("ReferenceMesh", &nap::FFTMeshComponent::mReferenceMesh, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("FrameCount", &nap::FFTMeshComponent::mFrameCount, nap::rtti::EPropertyMetaData::Default)
RTTI_PROPERTY("BumpAmount", &nap::FFTMeshComponent::mBumpAmount, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("SwerveSpeed", &nap::FFTMeshComponent::mSwerveSpeed, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("SwerveIntensity", &nap::FFTMeshComponent::mSwerveIntensity, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("FFT", &nap::FFTMeshComponent::mFFT, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("FluxMeasurement", &nap::FFTMeshComponent::mFluxMeasurement, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("ComputePopulate", &nap::FFTMeshComponent::mComputePopulate, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("ComputeNormals", &nap::FFTMeshComponent::mComputeNormals, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("Camera", &nap::FFTMeshComponent::mCamera, nap::rtti::EPropertyMetaData::Default)
RTTI_PROPERTY("CameraFloatHeight", &nap::FFTMeshComponent::mCameraFloatHeight, nap::rtti::EPropertyMetaData::Default)
RTTI_PROPERTY("CameraFollowDistance", &nap::FFTMeshComponent::mCameraFollowDistance, nap::rtti::EPropertyMetaData::Default)
// nap::AudioRoadComponent run time class definition
RTTI_BEGIN_CLASS(nap::AudioRoadComponent)
RTTI_PROPERTY("ReferenceMesh", &nap::AudioRoadComponent::mReferenceMesh, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("FrameCount", &nap::AudioRoadComponent::mFrameCount, nap::rtti::EPropertyMetaData::Default)
RTTI_PROPERTY("BumpAmount", &nap::AudioRoadComponent::mBumpAmount, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("SwerveSpeed", &nap::AudioRoadComponent::mSwerveSpeed, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("SwerveIntensity", &nap::AudioRoadComponent::mSwerveIntensity, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("NoiseStrength", &nap::AudioRoadComponent::mNoiseStrength, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("NoiseScale", &nap::AudioRoadComponent::mNoiseScale, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("NoiseSpeed", &nap::AudioRoadComponent::mNoiseSpeed, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("FFT", &nap::AudioRoadComponent::mFFT, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("FluxMeasurement", &nap::AudioRoadComponent::mFluxMeasurement, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("ComputePopulate", &nap::AudioRoadComponent::mComputePopulate, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("ComputeNormals", &nap::AudioRoadComponent::mComputeNormals, nap::rtti::EPropertyMetaData::Required)
RTTI_PROPERTY("Camera", &nap::AudioRoadComponent::mCamera, nap::rtti::EPropertyMetaData::Default)
RTTI_PROPERTY("CameraFloatHeight", &nap::AudioRoadComponent::mCameraFloatHeight, nap::rtti::EPropertyMetaData::Default)
RTTI_PROPERTY("CameraFollowDistance", &nap::AudioRoadComponent::mCameraFollowDistance, nap::rtti::EPropertyMetaData::Default)
RTTI_END_CLASS

// nap::FFTMeshComponentInstance run time class definition
RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR(nap::FFTMeshComponentInstance)
// nap::AudioRoadComponentInstance run time class definition
RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR(nap::AudioRoadComponentInstance)
RTTI_CONSTRUCTOR(nap::EntityInstance&, nap::Component&)
RTTI_END_CLASS

Expand All @@ -36,16 +39,16 @@ RTTI_END_CLASS

namespace nap
{
void FFTMeshComponent::getDependentComponents(std::vector<rtti::TypeInfo>& components) const
void AudioRoadComponent::getDependentComponents(std::vector<rtti::TypeInfo>& components) const
{
components.emplace_back(RTTI_OF(ComputeComponent));
}


bool FFTMeshComponentInstance::init(utility::ErrorState& errorState)
bool AudioRoadComponentInstance::init(utility::ErrorState& errorState)
{
// Fetch resource
mResource = getComponent<FFTMeshComponent>();
mResource = getComponent<AudioRoadComponent>();

auto& mesh_instance = mResource->mReferenceMesh->getMeshInstance();
GPUMesh& gpu_mesh = mesh_instance.getGPUMesh();
Expand Down Expand Up @@ -105,6 +108,18 @@ namespace nap
if (!errorState.check(mBumpUniform != nullptr, "Missing uniform member with name `bump`"))
return false;

mNoiseStrengthUniform = positions_ubo->getOrCreateUniform<UniformFloatInstance>("noiseStrength");
if (!errorState.check(mNoiseStrengthUniform != nullptr, "Missing uniform member with name `noiseStrength`"))
return false;

mNoiseScaleUniform = positions_ubo->getOrCreateUniform<UniformFloatInstance>("noiseScale");
if (!errorState.check(mNoiseScaleUniform != nullptr, "Missing uniform member with name `noiseScale`"))
return false;

mElapsedTimeUniform = positions_ubo->getOrCreateUniform<UniformFloatInstance>("elapsedTime");
if (!errorState.check(mElapsedTimeUniform != nullptr, "Missing uniform member with name `elapsedTime`"))
return false;

mOriginUniform = positions_ubo->getOrCreateUniform<UniformVec3Instance>("origin");
mDirectionUniform = positions_ubo->getOrCreateUniform<UniformVec3Instance>("direction");
mTangentUniform = positions_ubo->getOrCreateUniform<UniformVec3Instance>("tangent");
Expand Down Expand Up @@ -193,10 +208,11 @@ namespace nap
}


void FFTMeshComponentInstance::update(double deltaTime)
void AudioRoadComponentInstance::update(double deltaTime)
{
float delta_time = static_cast<float>(deltaTime);
mElapsedTime += delta_time;
mElapsedTime += delta_time * mResource->mNoiseSpeed->mValue;
mElapsedTimeUniform->setValue(mElapsedTime);

uint cur_idx = mFrameIndex % static_cast<uint>(mPositionBuffers.size());
uint prev_idx = (mFrameIndex + 1) % static_cast<uint>(mPositionBuffers.size());
Expand All @@ -209,6 +225,8 @@ namespace nap
mPrevAmpsUniform->setValues(mAmpsUniform->getValues());
mAmpsUniform->setValues(amps_cut);
mBumpUniform->setValue(mResource->mBumpAmount->mValue);
mNoiseStrengthUniform->setValue(mResource->mNoiseStrength->mValue);
mNoiseScaleUniform->setValue(mResource->mNoiseScale->mValue);

const auto& flux_params = mFluxMeasurement->getParameterItems();
if (!flux_params.empty())
Expand Down
Loading