nullreality
07/20/2023, 4:28 PMandybak
07/20/2023, 4:30 PMandybak
07/20/2023, 4:30 PMandybak
07/20/2023, 4:31 PMandybak
07/20/2023, 4:32 PMnullreality
07/20/2023, 4:53 PMandybak
07/20/2023, 5:16 PMandybak
07/21/2023, 10:02 AMandybak
07/21/2023, 10:38 AMandybak
07/21/2023, 10:38 AMandybak
07/21/2023, 10:39 AMandybak
07/23/2023, 11:13 AMlua
Parameters = {speed={label="Rate", type="int", min=0, max=10, default=1}}
function Main()
amount = Math:Sin(App.time * speed) * 0.5 + 0.5 -- oscillates between 0 and 1
Sketch.mainLayer.SetShaderFloat("Paper", "_Shininess", amount)
endandybak
07/23/2023, 11:13 AMandybak
07/23/2023, 11:14 AMandybak
07/23/2023, 11:16 AMandybak
07/23/2023, 11:17 AMandybak
07/23/2023, 11:17 AMandybak
07/23/2023, 11:17 AMandybak
07/24/2023, 12:22 PMandybak
07/24/2023, 12:23 PMandybak
07/24/2023, 12:24 PMandybak
07/24/2023, 1:22 PMglsl
Shader "AnimateStrokeCompletion"
{
Properties {
_ClipStart("Clip Start", Float) = 0
_ClipEnd("Clip End", Float) = 1
}
SubShader {
Tags { "RenderType" = "Opaque" }
Cull Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
float _ClipStart;
float _ClipEnd;
struct appdata {
float4 vertex : POSITION;
float3 uv2 : TEXCOORD2;
};
struct v2f {
float3 uv2 : TEXCOORD2;
float4 vertex : SV_POSITION;
};
v2f vert(appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv2 = v.uv2;
return o;
}
float invLerp(float from, float to, float value) {
return (value - from) / (to - from);
}
fixed4 frag(v2f i) : SV_Target {
float val = invLerp(i.uv2.x, i.uv2.y, i.uv2.z);
float completion = (val > _ClipStart && val < _ClipEnd) ? 1 : -1;
clip(completion);
fixed4 col = fixed4(1, 1, 1, 1);
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}andybak
07/24/2023, 1:23 PMandybak
07/24/2023, 1:29 PMcsharp
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class AddStrokeIds
{
[MenuItem("Tools/AddStrokeIds")]
public static void DoAddStrokeIds()
{
var selected = Selection.transforms;
int currentStrokeIndex = 0;
foreach (var tr in selected)
{
var mf = tr.GetComponent<MeshFilter>();
var mesh = mf.mesh;
var uv2 = new List<Vector3>();
mesh.GetUVs(2, uv2);
float prevVertexTimestamp = -1;
// The following lists have one entry per stroke
var timestamps = new List<float>(); // Timestamps
for (int vertIndex = 0; vertIndex < uv2.Count; vertIndex++)
{
float currentVertTimestamp = uv2[vertIndex].x;
Debug.Log(uv2[vertIndex].y);
if (vertIndex == 0) // First vertex therefore first stroke
{
timestamps.Add(currentVertTimestamp);
}
if (currentVertTimestamp != prevVertexTimestamp)
{
// New Stroke
if (vertIndex > 0) // Skip the first vertex
{
// Add new timestamp
timestamps.Add(currentStrokeIndex);
currentStrokeIndex++;
}
}
prevVertexTimestamp = currentVertTimestamp;
}
var dataUVs = new List<Vector3>();
for (int i = 0; i < uv2.Count; i++)
{
float strokeIndex = uv2[i].x;
dataUVs.Add(new Vector3(strokeIndex, 0, 0));
}
mesh.SetUVs(3, dataUVs);
mf.mesh = mesh;
}
}
}nullreality
07/24/2023, 11:03 PMShader "Brush/StandardDoubleSided_Stroke_Modified" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_ClipStart ("Clip Start", Float) = 0
_ClipEnd ("Clip End", Float) = 1
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 400
Cull Off
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ AUDIO_REACTIVE
#pragma multi_compile __ TBT_LINEAR_TARGETs
#include "../../../Shaders/Include/Brush.cginc"
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv_MainTex : TEXCOORD0;
float2 uv_BumpMap : TEXCOORD1;
fixed4 color : COLOR;
float3 uv2 : TEXCOORD2;
float completion : TEXCOORD3;
};
struct v2f {
float2 uv_MainTex : TEXCOORD0;
float2 uv_BumpMap : TEXCOORD1;
fixed4 color : COLOR;
float3 uv2 : TEXCOORD2;
float completion : TEXCOORD3;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
half _Shininess;
float _Cutoff;
float _ClipStart;
float _ClipEnd;
uniform float4 _LightColor0;
float invLerp(float from, float to, float value) {
return (value - from) / (to - from);
}
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv_MainTex = v.uv_MainTex;
o.uv_BumpMap = v.uv_BumpMap;
o.color = v.color;
o.uv2 = v.uv2;
o.completion = invLerp(v.uv2.x, v.uv2.y, v.uv2.z);
return o;
}
fixed4 frag (v2f i) : SV_Target {
// Normals & lighting
fixed3 tangentNormal = UnpackNormal(tex2D(_BumpMap, i.uv_BumpMap)) * 2 - 1;
fixed3 lightDirection = normalize(_WorldSpaceLightPos0.xyz - i.vertex.xyz);
fixed3 diffuseLight = max(0, dot(tangentNormal, lightDirection)) * _LightColor0.rgb;
// Alpha test
fixed4 mainTex = tex2D(_MainTex, i.uv_MainTex);
clip(mainTex.a - _Cutoff);
// Stroke completiom
float completion = (i.completion > _ClipStart && i.completion < _ClipEnd) ? 1 : -1;
clip(completion);
fixed4 tex = tex2D(_MainTex, i.uv_MainTex);
fixed4 color = tex * _Color * i.color;
color.a *= step(_ClipStart, i.completion) * (1-step(_ClipEnd, i.completion)); // Modify alpha channel based on completion
return color;
}
ENDCG
}
}
FallBack "Transparent/Cutout/VertexLit"
}nullreality
07/24/2023, 11:05 PMandybak
07/25/2023, 9:47 AMandybak
08/12/2023, 3:28 PMandybak
08/12/2023, 3:29 PMnullreality
08/26/2023, 12:37 AMZandy
09/04/2023, 2:30 PM