Skip to content

Commit

Permalink
ImGui. Tweak rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelbigos committed Apr 7, 2022
1 parent 82c3bf9 commit aae07d3
Show file tree
Hide file tree
Showing 30 changed files with 626 additions and 137 deletions.
57 changes: 20 additions & 37 deletions Assets/Compute/SDFGenMutate.compute
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

RWTexture3D<float> _sdfTexOut;

float _sphereRadius;
bool _mouseSubtract;
bool _mouseAdd;
float4 _mouseOrigin;
float4 _mouseDir;
float _brushSize;

float raySphereIntersect(float3 r0, float3 rd, float3 s0, float sr)
{
Expand Down Expand Up @@ -77,51 +79,32 @@ void SDFMutate(uint3 id : SV_DispatchThreadID)
float3 uv = kernelToUV(id);
float current = sdfUV(uv);
float3 world = uvToWorld(uv);

// Eikonal
float3 u;
u.x = neighborMin(id, uint3(1, 0, 0));
u.y = neighborMin(id, uint3(0, 1, 0));
u.z = neighborMin(id, uint3(0, 0, 1));

float g = _sdfRadius * 2.0 / _sdfTexSizeX;
float e = eikonal(u, g);
if (current > g) current = e;

if (_mouseAdd)
{
float toSdf = raySphereIntersect(_mouseOrigin.xyz, _mouseDir.xyz, float3(0.0, 0.0, 0.0), 1.0);
float toSdf = raySphereIntersect(_mouseOrigin.xyz, _mouseDir.xyz, float3(0.0, 0.0, 0.0), _sphereRadius);
float3 ro = _mouseOrigin.xyz + _mouseDir.xyz * toSdf;
float3 rd = _mouseDir.xyz;
float res;
float3 hitPos;
float hit = rayMarch(ro, _mouseDir.xyz, 1.0, res, hitPos);
if (hit > 0.0)
{
float addRadius = 0.05;
float3 pos = ro;
current = opSmoothUnion(sdSphere(world, pos, addRadius), current, 0.05);
}
float d = sdSphere(world, ro, _brushSize);
current = opSmoothUnion(d, current, 0.05);
}

if (_mouseSubtract)
{
float toSdf = raySphereIntersect(_mouseOrigin.xyz, _mouseDir.xyz, float3(0.0, 0.0, 0.0), 1.0);
float toSdf = raySphereIntersect(_mouseOrigin.xyz, _mouseDir.xyz, float3(0.0, 0.0, 0.0), _sphereRadius);
float3 ro = _mouseOrigin.xyz + _mouseDir.xyz * toSdf;
float3 rd = _mouseDir.xyz;
float res;
float3 hitPos;
float hit = rayMarch(ro, _mouseDir.xyz, 1.0, res, hitPos);
if (hit > 0.0)
{
float subtractRadius = 0.06;
for (int i = 0; i < 5; i++)
{
float3 pos = ro - rd * subtractRadius * 0.1 * float(i);
current = opSmoothSubtraction(sdSphere(world, pos, subtractRadius), current, 0.1);
}
}
float d = sdSphere(world, ro, _brushSize * 1.05f);
current = opSmoothSubtraction(d, current, 0.1);
}
if (!_mouseAdd)
{
// Eikonal pass
float3 u;
u.x = neighborMin(id, uint3(1, 0, 0));
u.y = neighborMin(id, uint3(0, 1, 0));
u.z = neighborMin(id, uint3(0, 0, 1));

float g = _sdfRadius * 2.0 / _sdfTexSizeX;
float e = eikonal(u, g);
if (current > g) current = e;
}

_sdfTexOut[id.xyz] = pack(current);
Expand Down
8 changes: 8 additions & 0 deletions Assets/ImGui.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Assets/ImGui/ImGuiCursorShapes.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70792e8e7be06b54e87366f539f7222b, type: 3}
m_Name: ImGuiCursorShapes
m_EditorClassIdentifier:
Arrow:
Texture: {fileID: 0}
Hotspot: {x: 0, y: 0}
TextInput:
Texture: {fileID: 0}
Hotspot: {x: 0, y: 0}
ResizeAll:
Texture: {fileID: 0}
Hotspot: {x: 0, y: 0}
ResizeNS:
Texture: {fileID: 0}
Hotspot: {x: 0, y: 0}
ResizeEW:
Texture: {fileID: 0}
Hotspot: {x: 0, y: 0}
ResizeNESW:
Texture: {fileID: 0}
Hotspot: {x: 0, y: 0}
ResizeNWSE:
Texture: {fileID: 0}
Hotspot: {x: 0, y: 0}
Hand:
Texture: {fileID: 0}
Hotspot: {x: 0, y: 0}
NotAllowed:
Texture: {fileID: 0}
Hotspot: {x: 0, y: 0}
8 changes: 8 additions & 0 deletions Assets/ImGui/ImGuiCursorShapes.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Assets/ImGui/ImGuiFontAtlas.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b5d229fe961e90a478d5b37aad1d4bdf, type: 3}
m_Name: ImGuiFontAtlas
m_EditorClassIdentifier:
RasterizerFlags: 0
Fonts: []
8 changes: 8 additions & 0 deletions Assets/ImGui/ImGuiFontAtlas.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Assets/ImGui/ImGuiIniSettings.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0e48206e359bc1247a32a885f4b70748, type: 3}
m_Name: ImGuiIniSettings
m_EditorClassIdentifier:
_data:
8 changes: 8 additions & 0 deletions Assets/ImGui/ImGuiIniSettings.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Assets/ImGui/ImGuiShaderResource.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 438e6449119fa624398b779cb7299e71, type: 3}
m_Name: ImGuiShaderResource
m_EditorClassIdentifier:
Shader:
Mesh: {fileID: 0}
Procedural: {fileID: 0}
PropertyNames:
Texture:
Vertices:
BaseVertex:
8 changes: 8 additions & 0 deletions Assets/ImGui/ImGuiShaderResource.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 108 additions & 0 deletions Assets/ImGui/ImGuiStyle.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 33d496755d9bce04b8e1fd75c1fa4673, type: 3}
m_Name: ImGuiStyle
m_EditorClassIdentifier:
Alpha: 0
WindowPadding: {x: 0, y: 0}
WindowRounding: 0
WindowBorderSize: 0
WindowMinSize: {x: 0, y: 0}
WindowTitleAlign: {x: 0, y: 0}
WindowMenuButtonPosition: 0
ChildRounding: 0
ChildBorderSize: 0
PopupRounding: 0
PopupBorderSize: 0
FramePadding: {x: 0, y: 0}
FrameRounding: 0
FrameBorderSize: 0
ItemSpacing: {x: 0, y: 0}
ItemInnerSpacing: {x: 0, y: 0}
CellPadding: {x: 0, y: 0}
TouchExtraPadding: {x: 0, y: 0}
IndentSpacing: 0
ColumnsMinSpacing: 0
ScrollbarSize: 0
ScrollbarRounding: 0
GrabMinSize: 0
GrabRounding: 0
LogSliderDeadzone: 0
TabRounding: 0
TabBorderSize: 0
ColorButtonPosition: 0
ButtonTextAlign: {x: 0, y: 0}
SelectableTextAlign: {x: 0, y: 0}
DisplayWindowPadding: {x: 0, y: 0}
DisplaySafeAreaPadding: {x: 0, y: 0}
MouseCursorScale: 0
AntiAliasedLines: 0
AntiAliasedLinesUseTex: 0
AntiAliasedFill: 0
CurveTessellationTol: 0
CircleTessellationMaxError: 0
Colors:
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 0, a: 0}
8 changes: 8 additions & 0 deletions Assets/ImGui/ImGuiStyle.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Assets/Includes/SDF.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,21 @@ float sdSphere(float3 pos, float3 spherePos, float sphereRadius)
}
float opSubtraction(float d1, float d2)
{
return max(d1, -d2);
return max(-d1,d2);
}
float opSmoothSubtraction(float d1, float d2, float k)
{
float h = clamp(0.5 - 0.5 * (d2 + d1) / k, 0.0, 1.0);
return lerp(d2, -d1, h) + k * h * (1.0 - h);
float h = max(k-abs(-d1-d2),0.0);
return max(-d1, d2) + h*h*0.25/k;
}
float opUnion(float d1, float d2)
{
return min(d1, d2);
return min(d1,d2);
}
float opSmoothUnion(float d1, float d2, float k)
{
float h = clamp(0.5 + 0.5 * (d2 - d1) / k, 0.0, 1.0);
return lerp(d2, d1, h) - k * h * (1.0 - h);
float h = max(k-abs(d1-d2),0.0);
return min(d1, d2) - h*h*0.25/k;
}

#endif // SDF_INCLUDED
Loading

0 comments on commit aae07d3

Please sign in to comment.