Speckle shader
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
Shader "Unlit/Speckle"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Thickness("Thickness", Range(0, 1)) = 0.32
|
||||
_Margin("Margin", Range(0, 1)) = 0.15
|
||||
_Mul("Multiple", int) = 32
|
||||
_GridSize("Grid Size", int) = 32
|
||||
_Color0("Color 0", Color) = (0.8, 0.8, 0.8, 1)
|
||||
_Color1("Color 1", Color) = (0.85, 0.85, 0.85, 1)
|
||||
_Saturation("Saturation", range(0,1)) = 0.05
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
// make fog work
|
||||
#pragma multi_compile_fog
|
||||
#pragma target 2.0
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 tex_coord : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
};
|
||||
|
||||
float _Thickness;
|
||||
float _Margin;
|
||||
int _Mul;
|
||||
int _GridSize;
|
||||
|
||||
fixed4 _Color0;
|
||||
fixed4 _Color1;
|
||||
float _Saturation;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.tex_coord = v.uv;
|
||||
UNITY_TRANSFER_FOG(o,o.vertex);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
// sample the texture
|
||||
fixed top = +0.5;
|
||||
fixed left = -1;
|
||||
fixed base = -0.5;
|
||||
fixed4 background = _Color0;
|
||||
|
||||
|
||||
{ //Coarse grid
|
||||
float2 grid_pos = (i.tex_coord + 0.5) * _Mul / _GridSize;
|
||||
grid_pos = grid_pos - floor(grid_pos);
|
||||
if(grid_pos.x > 0.5 ^ grid_pos.y > 0.5)
|
||||
{
|
||||
background = _Color1;
|
||||
}
|
||||
}
|
||||
|
||||
{ //Fine Grid
|
||||
float2 grid_pos = (i.tex_coord + 0.5) * _Mul / 2.0;
|
||||
grid_pos = grid_pos - floor(grid_pos);
|
||||
if(grid_pos.x > 0.5 ^ grid_pos.y > 0.5)
|
||||
{
|
||||
top = -top;
|
||||
left = -left;
|
||||
base = -base;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float2 cell_pos = (i.tex_coord + 0.5) * _Mul;
|
||||
cell_pos = cell_pos - floor(cell_pos);
|
||||
//cell_pos between 0-1 for each Speckle cube
|
||||
|
||||
fixed grey;
|
||||
|
||||
//Cube
|
||||
{
|
||||
if(cell_pos.x + cell_pos.y < 1.0)
|
||||
grey = left;
|
||||
else
|
||||
grey = top;
|
||||
|
||||
if(cell_pos.x > _Thickness && cell_pos.y < 1.0 -_Thickness)
|
||||
grey = base;
|
||||
}
|
||||
|
||||
//Ears
|
||||
if( cell_pos.x + cell_pos.y < _Thickness
|
||||
|| 1.0 - cell_pos.x + 1.0 - cell_pos.y < _Thickness)
|
||||
{
|
||||
grey = 0;
|
||||
}
|
||||
|
||||
//Margins
|
||||
const bool inCube = cell_pos.x > _Margin && cell_pos.y < 1.0 -_Margin;
|
||||
if(!inCube) grey = 0;
|
||||
|
||||
fixed4 col = background += grey * _Saturation;
|
||||
UNITY_APPLY_FOG(i.fogCoord, col);
|
||||
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b618a3e2f8c16294c889846d16994d80
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,85 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: SpeckleSurface
|
||||
m_Shader: {fileID: 4800000, guid: b618a3e2f8c16294c889846d16994d80, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _GridSize: 256
|
||||
- _Margin: 0.15
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _Mul: 8192
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _Saturation: 0.05
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Thickness: 0.32
|
||||
- _UVSec: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Color0: {r: 0.8, g: 0.8, b: 0.8, a: 1}
|
||||
- _Color1: {r: 0.85, g: 0.85, b: 0.85, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2830afbce900e634985de6a3930d9608
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Speckle.Core.Api;
|
||||
using Speckle.Core.Logging;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -157,6 +158,13 @@ namespace Speckle.ConnectorUnity
|
||||
statusText.text = $"Sent {commitId}";
|
||||
sendProgress.gameObject.SetActive(false); //hide
|
||||
});
|
||||
},
|
||||
onErrorAction: (id, e) =>
|
||||
{
|
||||
MakeButtonsInteractable(true);
|
||||
statusText.text = $"Error {id}";
|
||||
sendProgress.gameObject.SetActive(false); //hide
|
||||
throw new SpeckleException(e.Message, e);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Speckle.ConnectorUnity
|
||||
private List<Stream> StreamList = null;
|
||||
private Stream SelectedStream = null;
|
||||
private List<GameObject> StreamPanels = new List<GameObject>();
|
||||
|
||||
|
||||
async void Start()
|
||||
{
|
||||
@@ -82,7 +83,7 @@ namespace Speckle.ConnectorUnity
|
||||
private async void AddReceiver()
|
||||
{
|
||||
var autoReceive = AutoReceiveToggle.isOn;
|
||||
var stream = await Streams.Get(SelectedStream.id, 10);
|
||||
var stream = await Streams.Get(SelectedStream.id, 30);
|
||||
|
||||
var streamPrefab = Instantiate(StreamPanel, new Vector3(0, 0, 0),
|
||||
Quaternion.identity);
|
||||
|
||||
@@ -1245,7 +1245,7 @@ MeshCollider:
|
||||
m_GameObject: {fileID: 512580998}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
m_Enabled: 0
|
||||
serializedVersion: 4
|
||||
m_Convex: 1
|
||||
m_CookingOptions: 30
|
||||
@@ -1269,7 +1269,7 @@ MeshRenderer:
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
- {fileID: 2100000, guid: 2830afbce900e634985de6a3930d9608, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
@@ -1298,7 +1298,7 @@ MeshFilter:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 512580998}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &512581002
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1308,7 +1308,7 @@ Transform:
|
||||
m_GameObject: {fileID: 512580998}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -2.5, z: 0}
|
||||
m_LocalScale: {x: 500, y: 0.1, z: 500}
|
||||
m_LocalScale: {x: 500, y: 1, z: 500}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 2
|
||||
@@ -4181,7 +4181,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2068176107}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -30.5}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -32}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
"dependencies": {
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.collab-proxy": "1.13.5",
|
||||
"com.unity.ide.rider": "2.0.7",
|
||||
"com.unity.ide.visualstudio": "2.0.11",
|
||||
"com.unity.ide.rider": "3.0.7",
|
||||
"com.unity.ide.visualstudio": "2.0.12",
|
||||
"com.unity.ide.vscode": "1.2.4",
|
||||
"com.unity.test-framework": "1.1.29",
|
||||
"com.unity.test-framework": "1.1.30",
|
||||
"com.unity.textmeshpro": "3.0.6",
|
||||
"com.unity.timeline": "1.4.8",
|
||||
"com.unity.ugui": "1.0.0",
|
||||
|
||||
@@ -24,16 +24,16 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.rider": {
|
||||
"version": "2.0.7",
|
||||
"version": "3.0.7",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.test-framework": "1.1.1"
|
||||
"com.unity.ext.nunit": "1.0.6"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.visualstudio": {
|
||||
"version": "2.0.11",
|
||||
"version": "2.0.12",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@@ -65,7 +65,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.test-framework": {
|
||||
"version": "1.1.29",
|
||||
"version": "1.1.30",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Objects.Geometry;
|
||||
using System;
|
||||
using System;
|
||||
using Objects.Geometry;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -17,13 +17,11 @@ namespace Objects.Converter.Unity
|
||||
public partial class ConverterUnity
|
||||
{
|
||||
|
||||
#region helper methods
|
||||
|
||||
private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor");
|
||||
private static readonly int Metallic = Shader.PropertyToID("_Metallic");
|
||||
private static readonly int Glossiness = Shader.PropertyToID("_Glossiness");
|
||||
|
||||
private static Color ToUnityColor(SColor color) => new Color(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f);
|
||||
|
||||
#region helper methods
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@@ -146,8 +144,8 @@ namespace Objects.Converter.Unity
|
||||
{
|
||||
var p = go.transform.TransformPoint(vertex);
|
||||
sVertices.Add(p.x);
|
||||
sVertices.Add(p.z); //z and y swapped
|
||||
sVertices.Add(p.y);
|
||||
sVertices.Add(p.z);
|
||||
}
|
||||
|
||||
var nColors = nativeMesh.colors;
|
||||
@@ -373,7 +371,7 @@ namespace Objects.Converter.Unity
|
||||
//Set vertex colors
|
||||
if (speckleMesh.colors.Count == speckleMesh.VerticesCount)
|
||||
{
|
||||
var colors = speckleMesh.colors.Select(c => ToUnityColor(SColor.FromArgb(c))).ToList();
|
||||
var colors = speckleMesh.colors.Select(c => c.ToUnityColor()).ToList();
|
||||
mesh.SetColors(colors);
|
||||
}
|
||||
else if (speckleMesh.colors.Count != 0)
|
||||
@@ -469,7 +467,7 @@ namespace Objects.Converter.Unity
|
||||
mat.SetFloat(Glossiness, 1 - (float)renderMaterial.roughness);
|
||||
|
||||
if (renderMaterial.emissive != SColor.Black.ToArgb()) mat.EnableKeyword ("_EMISSION");
|
||||
mat.SetColor(EmissionColor, ToUnityColor(SColor.FromArgb(renderMaterial.emissive)));
|
||||
mat.SetColor(EmissionColor, renderMaterial.emissive.ToUnityColor());
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
@@ -54,18 +54,24 @@ namespace Speckle.ConnectorUnity
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unity color to an ARBG int
|
||||
/// </summary>
|
||||
public static int ToIntColor(this Color c)
|
||||
{
|
||||
return
|
||||
System.Drawing.Color
|
||||
.FromArgb(Convert.ToInt32(c.r * 255), Convert.ToInt32(c.r * 255), Convert.ToInt32(c.r * 255))
|
||||
.FromArgb(Convert.ToInt32(c.r * 255), Convert.ToInt32(c.g * 255), Convert.ToInt32(c.b * 255))
|
||||
.ToArgb();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Converts a ARGB formatted int to a Unity Color
|
||||
/// </summary>
|
||||
public static Color ToUnityColor(this int c)
|
||||
{
|
||||
var argb = System.Drawing.Color.FromArgb(c);
|
||||
return new Color(argb.R / 255.0f, argb.G / 255.0f, argb.B / 255.0f);
|
||||
return new Color(argb.R / 255f, argb.G / 255f, argb.B / 255f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user