Skip to content

Commit

Permalink
Anisotropic Mipmapping + Improved Marchers and March Sets
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyPenguins committed Jan 22, 2020
1 parent 437d623 commit 4b2cde5
Show file tree
Hide file tree
Showing 60 changed files with 984 additions and 253 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Xenko.Rendering.Voxels.Debug
namespace Xenko.Rendering.Voxels.Debug
{
shader VoxelVisualizationRawShader : ImageEffectShader
{
Expand All @@ -25,4 +25,4 @@
return color.xyzz + float4(0.1, 0.1, 0.1, 1.0) * (1.0 - color.a);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Xenko.Rendering.Voxels.Debug
namespace Xenko.Rendering.Voxels.Debug
{
effect VoxelVisualizationViewEffect
{
Expand All @@ -18,4 +18,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Xenko.Rendering.Voxels.Debug
namespace Xenko.Rendering.Voxels.Debug
{
shader VoxelVisualizationViewShader : MarchAttributes, ImageEffectShader
{
Expand All @@ -25,4 +25,4 @@
return color.xyzz + background * saturate(1.0-color.a);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,18 @@
// and re-save the associated .xkfx.
// </auto-generated>

// Nothing to generate
using System;
using Xenko.Core;
using Xenko.Rendering;
using Xenko.Graphics;
using Xenko.Shaders;
using Xenko.Core.Mathematics;
using Buffer = Xenko.Graphics.Buffer;

namespace Xenko.Rendering
{
public static partial class VoxelMarchSetHemisphere12Keys
{
public static readonly ValueParameterKey<float> offset = ParameterKeys.NewValue<float>();
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
shader VoxelMarchSetHemisphere12 : VoxelMarchSet
{
cbuffer PerView.Lighting
{
float offset;
}
compose VoxelMarchMethod Marcher;
override float4 March(float3 rayPos, float3 rayDir)
{
float3 tan = normalize(cross(rayDir, normalize(float3(1, 1, 1))));
float3 bitan = cross(tan, rayDir);
float3x3 tangentMatrix = float3x3(tan, bitan, rayDir);

float3 startPos = rayPos + rayDir * Marcher.StepSize();
float3 startPos = rayPos + rayDir * Marcher.StepSize() * offset;

float4 reflLighting = float4(0, 0, 0, 0);

//Dot products of rays
float central = 0.84;
float outer = 0.22;
float sum = (central*4+outer*8);
central /= sum;
outer /= sum;

rayDir = mul(float3(-0.38, -0.37, 0.84), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.1475;
reflLighting += Marcher.March(startPos, rayDir) * central;
rayDir = mul(float3(-0.31, 0.43, 0.84), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.1475;
reflLighting += Marcher.March(startPos, rayDir) * central;
rayDir = mul(float3(0.36, 0.39, 0.84), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.1475;
reflLighting += Marcher.March(startPos, rayDir) * central;
rayDir = mul(float3(0.36, -0.39, 0.84), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.1475;
reflLighting += Marcher.March(startPos, rayDir) * central;

rayDir = mul(float3(-0.87, 0.41, 0.22), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.0512;
reflLighting += Marcher.March(startPos, rayDir) * outer;
rayDir = mul(float3(-0.35, 0.90, 0.22), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.0512;
reflLighting += Marcher.March(startPos, rayDir) * outer;
rayDir = mul(float3(0.40, 0.88, 0.22), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.0512;
reflLighting += Marcher.March(startPos, rayDir) * outer;
rayDir = mul(float3(0.92, 0.31, 0.22), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.0512;
reflLighting += Marcher.March(startPos, rayDir) * outer;
rayDir = mul(float3(0.87, -0.43, 0.22), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.0512;
reflLighting += Marcher.March(startPos, rayDir) * outer;
rayDir = mul(float3(0.30, -0.92, 0.22), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.0512;
reflLighting += Marcher.March(startPos, rayDir) * outer;
rayDir = mul(float3(-0.43, -0.87, 0.22), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.0512;
reflLighting += Marcher.March(startPos, rayDir) * outer;
rayDir = mul(float3(-0.93, -0.28, 0.22), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * 0.0512;
reflLighting += Marcher.March(startPos, rayDir) * outer;

return reflLighting;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,18 @@
// and re-save the associated .xkfx.
// </auto-generated>

// Nothing to generate
using System;
using Xenko.Core;
using Xenko.Rendering;
using Xenko.Graphics;
using Xenko.Shaders;
using Xenko.Core.Mathematics;
using Buffer = Xenko.Graphics.Buffer;

namespace Xenko.Rendering
{
public static partial class VoxelMarchSetHemisphere6Keys
{
public static readonly ValueParameterKey<float> offset = ParameterKeys.NewValue<float>();
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
shader VoxelMarchSetHemisphere6 : VoxelMarchSet
shader VoxelMarchSetHemisphere6 : VoxelMarchSet, ShaderBase
{
cbuffer PerView.Lighting
{
float offset;
}
compose VoxelMarchMethod Marcher;
override float4 March(float3 rayPos, float3 rayDir)
{
float3 tan = normalize(cross(rayDir, normalize(float3(1, 1, 1))));
float3 bitan = cross(tan, rayDir);
float3x3 tangentMatrix = float3x3(tan, bitan, rayDir);

float3 startPos = rayPos + rayDir * Marcher.StepSize();
float3 startPos = rayPos + rayDir * Marcher.StepSize() * offset;

float4 reflLighting = float4(0, 0, 0, 0);

float mainDot = 1.0;
float sideDot = dot(normalize(float3(0.527, -0.723, 0.445)), float3(0, 0, 1));
float divisor = mainDot + sideDot * 5;
mainDot /= divisor;
sideDot /= divisor;

//Dot products of rays
float central = 1.0;
float outer = 0.445;
float sum = central + outer * 5;
central /= sum;
outer /= sum;

rayDir = mul(float3(0, 0, 1), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * mainDot;
reflLighting += Marcher.March(startPos, rayDir) * central;

rayDir = mul(normalize(float3(0.85, 0.278, 0.445)), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * sideDot;
reflLighting += Marcher.March(startPos, rayDir) * outer;

rayDir = mul(normalize(float3(0.527, -0.723, 0.445)), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * sideDot;
reflLighting += Marcher.March(startPos, rayDir) * outer;

rayDir = mul(normalize(float3(-0.526, -0.724, 0.445)), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * sideDot;
reflLighting += Marcher.March(startPos, rayDir) * outer;

rayDir = mul(normalize(float3(-0.851, 0.277, 0.445)), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * sideDot;
reflLighting += Marcher.March(startPos, rayDir) * outer;

rayDir = mul(normalize(float3(0.895, 0.445, 0.445)), tangentMatrix);
reflLighting += Marcher.March(startPos, rayDir) * sideDot;
reflLighting += Marcher.March(startPos, rayDir) * outer;

return reflLighting;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// <auto-generated>
// Do not edit this file yourself!
//
// This code was generated by Xenko Shader Mixin Code Generator.
// To generate it yourself, please install Xenko.VisualStudio.Package .vsix
// and re-save the associated .xkfx.
// </auto-generated>

using System;
using Xenko.Core;
using Xenko.Rendering;
using Xenko.Graphics;
using Xenko.Shaders;
using Xenko.Core.Mathematics;
using Buffer = Xenko.Graphics.Buffer;

namespace Xenko.Rendering
{
public static partial class VoxelMarchSetRandomHemisphereKeys
{
public static readonly ValueParameterKey<int> marchCount = ParameterKeys.NewValue<int>();
public static readonly ValueParameterKey<float> time = ParameterKeys.NewValue<float>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
shader VoxelMarchSetRandomHemisphere : VoxelMarchSet, ShaderBase
{
cbuffer PerView.Lighting
{
int marchCount;
float time;
}
float Random(in float2 uv)
{
float2 noise = (frac(sin(dot(uv,float2(12.9898,78.233)*2.0)) * 43758.5453));
return abs(noise.x + noise.y) * 0.5;
}
float3 CosineWeightedPointOnHemisphere(float2 uv) {
float u = Random(uv) * 6.28;
float v = Random(uv + 0.1);

v = sqrt(v);

float2 pos = float2(sin(u),cos(u)) * v;

return float3(pos, sqrt(1-pos.x*pos.x-pos.y*pos.y));
}

compose VoxelMarchMethod Marcher;
override float4 March(float3 rayPos, float3 rayDir)
{
float3 tan = normalize(cross(rayDir, normalize(float3(1,1,1))));
float3 bitan = cross(tan, rayDir);
float3x3 tangentMatrix = float3x3(tan, bitan, rayDir);

float3 startPos = rayPos + rayDir * Marcher.StepSize();

float4 reflLighting = float4(0, 0, 0, 0);

for(int i = 0; i < marchCount; i ++)
{
float3 dir = CosineWeightedPointOnHemisphere(streams.ShadingPosition.xy + i*1.73 + time);
dir = mul(dir, tangentMatrix);
reflLighting += Marcher.March(startPos, dir);
}

return reflLighting/(float)marchCount;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xenko.Core;
using Xenko.Shaders;

namespace Xenko.Rendering.Voxels
{
[DataContract(DefaultMemberMode = DataMemberMode.Default)]
public class VoxelMarchSetBase
{
public IVoxelMarchMethod Marcher { set; get; } = new VoxelMarchConePerMipmap();
public float Offset { set; get; } = 1.0f;
public VoxelMarchSetBase()
{

}
public VoxelMarchSetBase(IVoxelMarchMethod marcher)
{
Marcher = marcher;
}

protected ValueParameterKey<float> OffsetKey;
public virtual void UpdateMarchingLayout(string compositionName)
{
Marcher.UpdateMarchingLayout("Marcher." + compositionName);
}
public virtual void ApplyMarchingParameters(ParameterCollection parameters)
{
Marcher.ApplyMarchingParameters(parameters);
parameters.Set(OffsetKey, Offset);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ namespace Xenko.Rendering.Voxels
{
[DataContract(DefaultMemberMode = DataMemberMode.Default)]
[Display("Hemisphere (12)")]
public class VoxelMarchSetHemisphere12 : IVoxelMarchSet
public class VoxelMarchSetHemisphere12 : VoxelMarchSetBase, IVoxelMarchSet
{
public IVoxelMarchMethod Marcher { set; get; } = new VoxelMarchCone(9, 1.0f, 1.0f);
public VoxelMarchSetHemisphere12()
{

Expand All @@ -19,6 +18,7 @@ public VoxelMarchSetHemisphere12(IVoxelMarchMethod marcher)
{
Marcher = marcher;
}

public ShaderSource GetMarchingShader(int attrID)
{
var mixin = new ShaderMixinSource();
Expand All @@ -27,13 +27,10 @@ public ShaderSource GetMarchingShader(int attrID)
return mixin;
}

public void UpdateMarchingLayout(string compositionName)
{
Marcher.UpdateMarchingLayout("Marcher."+compositionName);
}
public void ApplyMarchingParameters(ParameterCollection parameters)
public override void UpdateMarchingLayout(string compositionName)
{
Marcher.ApplyMarchingParameters(parameters);
base.UpdateMarchingLayout(compositionName);
OffsetKey = VoxelMarchSetHemisphere12Keys.offset.ComposeWith(compositionName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ namespace Xenko.Rendering.Voxels
{
[DataContract(DefaultMemberMode = DataMemberMode.Default)]
[Display("Hemisphere (6)")]
public class VoxelMarchSetHemisphere6 : IVoxelMarchSet
public class VoxelMarchSetHemisphere6 : VoxelMarchSetBase, IVoxelMarchSet
{
public IVoxelMarchMethod Marcher { set; get; } = new VoxelMarchCone(9, 1.0f, 1.7f);
public VoxelMarchSetHemisphere6()
{

Expand All @@ -19,6 +18,7 @@ public VoxelMarchSetHemisphere6(IVoxelMarchMethod marcher)
{
Marcher = marcher;
}

public ShaderSource GetMarchingShader(int attrID)
{
var mixin = new ShaderMixinSource();
Expand All @@ -27,13 +27,10 @@ public ShaderSource GetMarchingShader(int attrID)
return mixin;
}

public void UpdateMarchingLayout(string compositionName)
{
Marcher.UpdateMarchingLayout("Marcher." + compositionName);
}
public void ApplyMarchingParameters(ParameterCollection parameters)
public override void UpdateMarchingLayout(string compositionName)
{
Marcher.ApplyMarchingParameters(parameters);
base.UpdateMarchingLayout(compositionName);
OffsetKey = VoxelMarchSetHemisphere6Keys.offset.ComposeWith(compositionName);
}
}
}
Loading

0 comments on commit 4b2cde5

Please sign in to comment.