Skip to content

Commit

Permalink
Add Marker Menu example in the Toolkit + accordingly readme change.
Browse files Browse the repository at this point in the history
  • Loading branch information
fzellweger committed Feb 12, 2020
1 parent a8a0546 commit 5b72c9b
Show file tree
Hide file tree
Showing 62 changed files with 4,791 additions and 101 deletions.

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
%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: a3a2a09c03c0b5d42a3f59c8a89129ce, type: 3}
m_Name: Square ShaderDrawingProperties
m_EditorClassIdentifier:
Offset: -0.005
Spacing: 0.5
MinWidth: 0
ComputeShaderRef: {fileID: 7200000, guid: 4c1fe886ed1c29740b9a72a581d32e00, type: 3}
TextureDimension: {x: 3840, y: 3840}
UndoHistorySize: 24

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

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Each #kernel tells which function to compile; you can have many kernels
// Each #kernel tells which function to compile; you can have many kernels.
#pragma kernel CSMain
#pragma kernel SaveFrame
#pragma kernel WriteFrame
#pragma kernel EraseAll

// Variables
// Variables.
RWTexture2D<float4> Result;
float Range;

Expand All @@ -26,77 +26,55 @@ Texture2D<float4> UndoTextures[100];
[numthreads(32,32,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
for(int i = 0;i<arrayLength;i++){
for(int i = 0; i < arrayLength; i++)
{
float newBrushSize = lerp(previousBrushSize, brushSize, (float) i / arrayLength);
float dx = abs(id.x-penPosition[i].x);
if(dx>newBrushSize)continue;
float dy = abs(id.y-penPosition[i].y);
if(dy>newBrushSize)continue;
float zero = float(0);
if(dx+dy<newBrushSize)
{
float f = distance(id.xy,penPosition[i])-newBrushSize*hardness;
float4 outColor = penColor;
float4 currentColor = Result[id.xy];
float distanceFromInk = distance(penPosition[i], id.xy);
float brushDrawing = step(distanceFromInk, newBrushSize);

outColor.a = f<0?1: 1 - distance(id.xy,penPosition[i])/newBrushSize;
// Color from the stylus that is going to be blended.
float4 sourceColor = penColor;
// Destination color, basically the canvas.
float4 destinationColor = Result[id.xy];
// Final color.
float4 outColor = penColor;

if (currentColor.r == zero && currentColor.g == zero && currentColor.b == zero && currentColor.a == zero)
{
outColor.rgb = outColor.rgb;
}
else
{
outColor.rgb = outColor.rgb*outColor.a+currentColor.rgb*(1-outColor.a);
}
// Alpha blending as per https://en.wikipedia.org/wiki/Alpha_compositing#Composing_alpha_blending_with_gamma_correction.
outColor.a = sourceColor.a + destinationColor.a * (1 - sourceColor.a);
outColor.rgb = sourceColor.rgb + destinationColor.rgb * (1 - sourceColor.a);

outColor.a = outColor.a +currentColor.a *(1-outColor.a);
// Do not blend if drawing is on the same color.
float allowBlending = step(0.01, distance(destinationColor, sourceColor));
outColor = allowBlending * outColor + step(allowBlending, 0) * penColor;

Result[id.xy] =isErasing? penColor: outColor;
continue;
}
if(dx*dx+dy*dy<newBrushSize*newBrushSize)
if (allowBlending == 0)
{
float f = distance(id.xy,penPosition[i])-newBrushSize*hardness;
float4 outColor = penColor;
float4 currentColor = Result[id.xy];

outColor.a = f<0?1: 1 - distance(id.xy,penPosition[i])/newBrushSize;

float zero = float(0);
if (currentColor.r == zero && currentColor.g == zero && currentColor.b == zero && currentColor.a == zero)
{
outColor.rgb = outColor.rgb;
}
else
{
outColor.rgb = outColor.rgb*outColor.a+currentColor.rgb*(1-outColor.a);
}

outColor.a = outColor.a +currentColor.a *(1-outColor.a);

Result[id.xy] =isErasing? penColor: outColor;
outColor = penColor;
}

if (brushDrawing == 1)
{
Result[id.xy] = outColor;
}
}
}

int currentDepth;
[numthreads(32,32,1)]
[numthreads(32, 32, 1)]
void SaveFrame (uint3 id : SV_DispatchThreadID)
{
UndoTexture[uint3(id.x,id.y,currentDepth)] = Result[id.xy];
UndoTexture[uint3(id.x, id.y, currentDepth)] = Result[id.xy];
}

[numthreads(32,32,1)]
[numthreads(32, 32, 1)]
void WriteFrame (uint3 id : SV_DispatchThreadID)
{
Result[id.xy] = UndoTexture[uint3(id.x,id.y,currentDepth)];
Result[id.xy] = UndoTexture[uint3(id.x, id.y, currentDepth)];
}

[numthreads(32,32,1)]
[numthreads(32, 32, 1)]
void EraseAll (uint3 id : SV_DispatchThreadID)
{
Result[id.xy] = float4(0,0,0,0);
Result[id.xy] = float4(0, 0, 0, 0);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Each #kernel tells which function to compile; you can have many kernels.
#pragma kernel CSMain
#pragma kernel SaveFrame
#pragma kernel WriteFrame
#pragma kernel EraseAll

// Variables.
RWTexture2D<float4> Result;
float Range;
float2 TextureDimension;
int arrayLength;
float4 penColor;
float4 penPosition;
float4 previousPenPosition;
float hardness;
float brushSize;
float previousBrushSize;
bool isErasing;

RWTexture2DArray<float4> UndoTexture;
Texture2D<float4> UndoTextures[100];

[numthreads(32, 32, 1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
float distanceFromInk = distance(penPosition, id.xy);
float brushDrawing = step(distanceFromInk, brushSize);

// Color from the stylus that is going to be blended.
float4 sourceColor = penColor;
// Destination color, basically the canvas.
float4 destinationColor = Result[id.xy];
// Final color.
float4 outColor = penColor;

// Alpha blending as per https://en.wikipedia.org/wiki/Alpha_compositing#Composing_alpha_blending_with_gamma_correction.
outColor.a = sourceColor.a + destinationColor.a * (1 - sourceColor.a);
outColor.rgb = sourceColor.rgb + destinationColor.rgb*(1 - sourceColor.a);

// Do not blend if drawing is on the same color.
float allowBlending = step(0.01, distance(destinationColor, sourceColor));
outColor = allowBlending * outColor + step(allowBlending, 0) * penColor;

Result[id.xy] = brushDrawing * outColor + step(brushDrawing, 0) * Result[id.xy];
}

int currentDepth;
[numthreads(32, 32, 1)]
void SaveFrame (uint3 id : SV_DispatchThreadID)
{
UndoTexture[uint3(id.x, id.y, currentDepth)] = Result[id.xy];
}

[numthreads(32, 32, 1)]
void WriteFrame (uint3 id : SV_DispatchThreadID)
{
Result[id.xy] = UndoTexture[uint3(id.x, id.y, currentDepth)];
}

[numthreads(32, 32, 1)]
void EraseAll (uint3 id : SV_DispatchThreadID)
{
Result[id.xy] = float4(0, 0, 0, 0);
}

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

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5b72c9b

Please sign in to comment.