Skip to content

Commit

Permalink
Add Brush Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
jmickle66666666 committed Nov 10, 2018
1 parent 828b794 commit 7bac966
Show file tree
Hide file tree
Showing 76 changed files with 4,855 additions and 1,705 deletions.
52 changes: 16 additions & 36 deletions Gizmos/ButtonCapsule.png.meta

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

Binary file removed Gizmos/Circle.png
Binary file not shown.
Binary file removed Gizmos/CircleOutline.png
Binary file not shown.
Binary file added Gizmos/GroupHeaderButtonClose.png
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.

Binary file added Gizmos/GroupHeaderButtonHelp.png
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.

Binary file added Gizmos/ImporterQuake1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions Gizmos/ImporterQuake1.png.meta

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

Binary file added Gizmos/MouseRightClickHint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions Gizmos/MouseRightClickHint.png.meta

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

48 changes: 45 additions & 3 deletions Internal/Shaders/BrushPreview.shader
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Shader "SabreCSG/BrushPreview"
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_GridSize("Grid Size", float) = 1.0
_GridStrength("Grid Strength", Range(0,1)) = 0.25
_GridThickness("Grid Thickness", Range(0.01,0.1)) = 0.05
[HideInInspector] _GridToggle("Grid Toggle", float) = 1.0
}

SubShader
Expand All @@ -16,17 +20,55 @@ Shader "SabreCSG/BrushPreview"
#pragma surface surf Lambert alpha:blend nofog

fixed4 _Color;
float _GridStrength;
float _GridSize;
float _GridThickness;
half _GridToggle;

struct Input
{
fixed4 color; // Can't declare empty structs in CG, so just put a filler variable to get it compiling
float3 worldPos;
float3 worldNormal;
};

float mod(float val, float mod) {

while (val < 0) {
val += mod*100;
}

return val % mod;
}

void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;

float3 worldNormal = abs(IN.worldNormal);

worldNormal.x = (worldNormal.x > worldNormal.y && worldNormal.x > worldNormal.z)?1:0;
worldNormal.y = (worldNormal.y > worldNormal.x && worldNormal.y > worldNormal.z)?1:0;
worldNormal.z = (worldNormal.z > worldNormal.y && worldNormal.z > worldNormal.x)?1:0;

float3 worldspace = IN.worldPos;
worldspace -= _GridThickness * 0.5;

float2 grid = float2(
(worldspace.z * worldNormal.x) + (worldspace.x * worldNormal.z) + (worldspace.x * worldNormal.y),
(worldspace.y * worldNormal.x) + (worldspace.y * worldNormal.z) + (worldspace.z * worldNormal.y)
);

_GridSize = max(0.01, _GridSize);

grid.x = step((1.0 - _GridThickness)*_GridSize, mod(grid.x, _GridSize));
grid.y = step((1.0 - _GridThickness)*_GridSize, mod(grid.y, _GridSize));

float g = saturate(grid.x + grid.y);

//o.Alpha = g;

o.Albedo = c.rgb + (g * _GridStrength * _GridToggle);
o.Alpha = c.a + (g * _GridStrength * _GridToggle);
}
ENDCG
}
Expand Down
29 changes: 15 additions & 14 deletions Materials/Add.mat
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Add
m_Shader: {fileID: 4800000, guid: b36682a2a82e54bb28920dd1a712dc4d, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 2
serializedVersion: 3
m_TexEnvs:
data:
first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats: {}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _GridSize: 0.5
- _GridStrength: 0.3
- _GridThickness: 0.03
- _GridToggle: 1
m_Colors:
data:
first:
name: _Color
second: {r: 0, g: .710344791, b: 1, a: .509803951}
- _Color: {r: 0, g: 0.7103448, b: 1, a: 0.2}
Binary file modified Materials/Collision.mat
Binary file not shown.
Binary file modified Materials/NoCSG.mat
Binary file not shown.
Binary file modified Materials/Subtract.mat
Binary file not shown.
Binary file modified Materials/Volume.mat
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public class ShapeEditorBrushInspector : CompoundBrushInspector
{
public override void DoInspectorGUI()
{
using (new NamedVerticalScope("Shape Editor Brush"))
using (NamedVerticalScope scope = new NamedVerticalScope("Shape Editor Brush"))
{
scope.WikiLink = "2D-Shape-Editor#embedded-projects";

GUILayout.BeginHorizontal(EditorStyles.toolbar);
GUIStyle createBrushStyle = new GUIStyle(EditorStyles.toolbarButton);
if (GUILayout.Button(new GUIContent(" Shape Editor", SabreCSGResources.ButtonShapeEditorTexture, "Show 2D Shape Editor"), createBrushStyle))
Expand Down
Loading

0 comments on commit 7bac966

Please sign in to comment.