correct spout homo and refine performance

master
uc-hoba 8 years ago
parent b3e32dd017
commit fc84400773
  1. 2180
      Frozen.avc
  2. 6
      Unity_2018_Frozen/Assets/Frozen/CosineGradient.asset
  3. 205
      Unity_2018_Frozen/Assets/Frozen/Frozen.unity
  4. 2
      Unity_2018_Frozen/Assets/Frozen/Material/Point.mat
  5. 6
      Unity_2018_Frozen/Assets/Frozen/PostProcessingProfile.asset
  6. 3
      Unity_2018_Frozen/Assets/Frozen/Script/SnowflakeParticleUpdater.cs
  7. 191
      Unity_2018_Frozen/Assets/Frozen/Script/SpaceHomography.cs
  8. 13
      Unity_2018_Frozen/Assets/Frozen/Script/SpaceHomography.cs.meta
  9. 49
      Unity_2018_Frozen/Assets/Frozen/Shader/FrozenParticleUnlitPoint.shader
  10. 10
      Unity_2018_Frozen/Assets/Frozen/Shader/SnowflakeParticleUpdate.compute
  11. 101
      Unity_2018_Frozen/Assets/Frozen/Shader/SpaceMapping.shader
  12. 9
      Unity_2018_Frozen/Assets/Frozen/Shader/SpaceMapping.shader.meta
  13. 2
      Unity_2018_Frozen/Assets/Frozen/Texture/RenderTexture-Final.renderTexture
  14. 2
      Unity_2018_Frozen/Assets/Frozen/Texture/RenderTexture-Particle.renderTexture
  15. 2
      Unity_2018_Frozen/Assets/Frozen/Texture/RenderTexture-Scene.renderTexture
  16. 6
      Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlow.cs
  17. 2
      Unity_2018_Frozen/ProjectSettings/ProjectVersion.txt

File diff suppressed because one or more lines are too long

@ -11,6 +11,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 54276434dda9c694e85abaf98cdd981d, type: 3}
m_Name: CosineGradient
m_EditorClassIdentifier:
_redCoeffs: {x: 0.743, y: 0.14, z: 0.56, w: 0.453}
_greenCoeffs: {x: 0.711, y: 0.177, z: 0.3, w: 0.825}
_blueCoeffs: {x: 0.835, y: 0.131, z: 0.27, w: 0}
_redCoeffs: {x: 0.414, y: 0.14, z: 0.56, w: 0.453}
_greenCoeffs: {x: 0.313, y: 0.177, z: 0.3, w: 0.825}
_blueCoeffs: {x: 0.685, y: 0.282, z: 0.27, w: 0}

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 1071731254}
m_IndirectSpecularColor: {r: 0.021216419, g: 0.053037528, b: 0.08577963, a: 1}
m_IndirectSpecularColor: {r: 0.021216419, g: 0.053037524, b: 0.08577964, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
@ -171,7 +171,7 @@ Camera:
m_TargetTexture: {fileID: 8400000, guid: da32e5550d217674aa980199f6a84db3, type: 2}
m_TargetDisplay: 1
m_TargetEye: 3
m_HDR: 0
m_HDR: 1
m_AllowMSAA: 0
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
@ -204,7 +204,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &151858420
GameObject:
@ -217,7 +217,6 @@ GameObject:
- component: {fileID: 151858423}
- component: {fileID: 151858422}
- component: {fileID: 151858421}
- component: {fileID: 151858426}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@ -268,7 +267,7 @@ Camera:
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_HDR: 0
m_AllowMSAA: 0
m_AllowDynamicResolution: 0
m_ForceIntoRT: 1
@ -282,69 +281,12 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 151858420}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -2.73}
m_LocalPosition: {x: 0, y: 1.5, z: -2.73}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &151858426
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 151858420}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 948f4100a11a5c24981795d21301da5c, type: 3}
m_Name:
m_EditorClassIdentifier:
volumeTrigger: {fileID: 151858424}
volumeLayer:
serializedVersion: 2
m_Bits: 4294967295
stopNaNPropagation: 1
antialiasingMode: 2
temporalAntialiasing:
jitterSpread: 0.75
sharpness: 0.25
stationaryBlending: 0.95
motionBlending: 0.85
subpixelMorphologicalAntialiasing:
quality: 2
fastApproximateAntialiasing:
fastMode: 0
keepAlpha: 0
fog:
enabled: 1
excludeSkybox: 1
debugLayer:
lightMeter:
width: 512
height: 256
showCurves: 1
histogram:
width: 512
height: 256
channel: 3
waveform:
exposure: 0.12
height: 256
vectorscope:
size: 256
exposure: 0.12
overlaySettings:
motionColorIntensity: 4
motionGridSize: 64
colorBlindnessType: 0
colorBlindnessStrength: 1
m_Resources: {fileID: 11400000, guid: d82512f9c8e5d4a4d938b575d47f88d4, type: 2}
m_ShowToolkit: 0
m_ShowCustomSorter: 0
breakBeforeColorGrading: 0
m_BeforeTransparentBundles: []
m_BeforeStackBundles: []
m_AfterStackBundles: []
--- !u!1 &182553293
GameObject:
m_ObjectHideFlags: 0
@ -468,7 +410,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &338663764
GameObject:
@ -497,7 +439,7 @@ Transform:
m_Children:
- {fileID: 917676528}
m_Father: {fileID: 0}
m_RootOrder: 13
m_RootOrder: 14
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &343589998
GameObject:
@ -557,7 +499,7 @@ Camera:
m_TargetTexture: {fileID: 8400000, guid: 3d63e39cdb1f2e5419672e7560e22145, type: 2}
m_TargetDisplay: 1
m_TargetEye: 3
m_HDR: 0
m_HDR: 1
m_AllowMSAA: 0
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
@ -605,7 +547,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
reset: 0
maxParticles: 500000
maxParticles: 262144
particleBuffer: {fileID: 438615022}
shader: {fileID: 7200000, guid: d6604fabdbb13e9428c849c59feccdac, type: 3}
uniformBuffer: {fileID: 441718966}
@ -679,7 +621,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!1 &386695295
GameObject:
@ -710,7 +652,7 @@ Transform:
- {fileID: 850228141}
- {fileID: 1848145250}
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &401185750
GameObject:
@ -742,7 +684,7 @@ Transform:
- {fileID: 1579390333}
- {fileID: 343589999}
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &432509337
GameObject:
@ -770,7 +712,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 18
m_RootOrder: 19
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &438615021
GameObject:
@ -901,7 +843,7 @@ RectTransform:
- {fileID: 770059767}
- {fileID: 1774693142}
m_Father: {fileID: 0}
m_RootOrder: 17
m_RootOrder: 18
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
@ -963,6 +905,64 @@ MonoBehaviour:
m_EditorClassIdentifier:
bufferName: uniform_buffer
uniform: {fileID: 11400000, guid: 43a114cac50c03e4ea881a51dbb6e7bd, type: 2}
--- !u!1 &499091830
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 499091833}
- component: {fileID: 499091832}
- component: {fileID: 499091831}
m_Layer: 5
m_Name: Post-process Volume
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!114 &499091831
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 499091830}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8b9a305e18de0c04dbd257a21cd47087, type: 3}
m_Name:
m_EditorClassIdentifier:
sharedProfile: {fileID: 11400000, guid: 79182fbaf32faca4ca265d09dbd05840, type: 2}
isGlobal: 0
blendDistance: 0
weight: 1
priority: 0
--- !u!65 &499091832
BoxCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 499091830}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!4 &499091833
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 499091830}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -1.5566128}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &528715328
GameObject:
m_ObjectHideFlags: 0
@ -1287,7 +1287,7 @@ Transform:
m_LocalScale: {x: 2, y: 2, z: 2}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &618046638
GameObject:
@ -1345,7 +1345,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 15
m_RootOrder: 16
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &658720283
GameObject:
@ -1373,7 +1373,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &732632614
GameObject:
@ -1406,7 +1406,7 @@ Transform:
- {fileID: 1035960134}
- {fileID: 441718964}
m_Father: {fileID: 0}
m_RootOrder: 10
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &764073633
GameObject:
@ -1434,7 +1434,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 14
m_RootOrder: 15
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &770059766
GameObject:
@ -2019,17 +2019,17 @@ RectTransform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 957254312}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 10.065733}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalPosition: {x: 0, y: 0, z: 10.065701}
m_LocalScale: {x: 0.1, y: 0.1, z: 1}
m_Children: []
m_Father: {fileID: 1765914297}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 512, y: 512}
m_Pivot: {x: 1, y: 1}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: -0.00012207031}
m_SizeDelta: {x: 5040, y: 3200}
m_Pivot: {x: 0, y: 1}
--- !u!114 &957254314
MonoBehaviour:
m_ObjectHideFlags: 0
@ -2049,7 +2049,7 @@ MonoBehaviour:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Texture: {fileID: 8400000, guid: 1ded3bafa85a18b4f87c48288b4439a1, type: 2}
m_Texture: {fileID: 8400000, guid: e222b09ab4f80eb4eae6760ed0503d87, type: 2}
m_UVRect:
serializedVersion: 2
x: 0
@ -2168,7 +2168,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!1 &1196719910
GameObject:
@ -2260,6 +2260,7 @@ GameObject:
- component: {fileID: 1283180270}
- component: {fileID: 1283180267}
- component: {fileID: 1283180269}
- component: {fileID: 1283180271}
- component: {fileID: 1283180268}
m_Layer: 0
m_Name: Final Camera
@ -2293,7 +2294,7 @@ Camera:
m_CullingMask:
serializedVersion: 2
m_Bits: 32
m_RenderingPath: -1
m_RenderingPath: 1
m_TargetTexture: {fileID: 8400000, guid: e222b09ab4f80eb4eae6760ed0503d87, type: 2}
m_TargetDisplay: 0
m_TargetEye: 3
@ -2315,7 +2316,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: fda5366b87aa3934a8e5823faa38f54c, type: 3}
m_Name:
m_EditorClassIdentifier:
sharingName: UnitySender
sharingName: FrozenSpout
textureFormat: 28
yFlip: 1
output: {fileID: 0}
@ -2343,7 +2344,7 @@ MonoBehaviour:
stationaryBlending: 0.95
motionBlending: 0.85
subpixelMorphologicalAntialiasing:
quality: 2
quality: 0
fastApproximateAntialiasing:
fastMode: 0
keepAlpha: 0
@ -2371,8 +2372,8 @@ MonoBehaviour:
colorBlindnessType: 0
colorBlindnessStrength: 1
m_Resources: {fileID: 11400000, guid: d82512f9c8e5d4a4d938b575d47f88d4, type: 2}
m_ShowToolkit: 0
m_ShowCustomSorter: 0
m_ShowToolkit: 1
m_ShowCustomSorter: 1
breakBeforeColorGrading: 0
m_BeforeTransparentBundles: []
m_BeforeStackBundles: []
@ -2388,8 +2389,20 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 16
m_RootOrder: 17
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1283180271
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1283180266}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7cf1e6cce802d3c49a437b3125a95960, type: 3}
m_Name:
m_EditorClassIdentifier:
space: {x: 2880, y: 1800, z: 1080}
--- !u!1 &1390635887
GameObject:
m_ObjectHideFlags: 0
@ -2417,7 +2430,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1390635889
MonoBehaviour:
@ -2552,7 +2565,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 12
m_RootOrder: 13
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!1 &1579390332
GameObject:
@ -2696,7 +2709,7 @@ RectTransform:
m_Children:
- {fileID: 957254313}
m_Father: {fileID: 0}
m_RootOrder: 19
m_RootOrder: 20
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
@ -2973,5 +2986,5 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

@ -81,7 +81,7 @@ Material:
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Size: 0.005
- _Size: 0.0164
- _SmoothnessTextureChannel: 0
- _SoftParticlesEnabled: 0
- _SoftParticlesFarFadeDistance: 1

@ -45,7 +45,7 @@ MonoBehaviour:
overrideState: 0
value: 0
color:
overrideState: 1
overrideState: 0
value: {r: 1, g: 1, b: 1, a: 1}
fastMode:
overrideState: 0
@ -123,10 +123,10 @@ MonoBehaviour:
overrideState: 0
value: 0
postExposure:
overrideState: 1
overrideState: 0
value: 0
contrast:
overrideState: 1
overrideState: 0
value: 17
mixerRedOutRedIn:
overrideState: 0

@ -88,7 +88,7 @@ namespace UltraCombos.Frozen
{
shader.SetFloat("timeStep", time_step);
shader.SetFloat("timeValue", Utilities.GetTimeValue());
shader.SetInt("home_count", kinectOpticalFlow.HomeCount);
//shader.SetInt("home_count", kinectOpticalFlow.HomeCount);
shader.SetFloat("bufferCount", particleBuffer.count);
if (cosineGradient != null)
@ -105,6 +105,7 @@ namespace UltraCombos.Frozen
shader.SetBuffer(0, particleBuffer.bufferName, particleBuffer.obj);
shader.SetBuffer(0, uniformBuffer.bufferName, uniformBuffer.obj);
shader.SetBuffer(0, "home_count_buffer", kinectOpticalFlow.HomeCountBuffer);
shader.SetBuffer(0, "home_position_buffer", kinectOpticalFlow.HomePositionBuffer);
shader.SetBuffer(0, "home_velocity_buffer", kinectOpticalFlow.HomeVelocityBuffer);
shader.SetBuffer(0, "fluid_velocity_buffer", smokeFluidSim.VelocityBuffer);

@ -0,0 +1,191 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpaceHomography : MonoBehaviour
{
public Vector3 space;
Matrix4x4 front_homo;
Matrix4x4 left_homo;
Matrix4x4 right_homo;
Vector2 texture_size;
private void Start()
{
float dim = space.x + space.z * 2.0f;
//Vector2 canvas_size = new Vector2(space.x + space.z * 2.0f, space.y + space.z * 2.0f);
//Vector2 clipped_size = new Vector2(space.x, 3200);
var rt = GetComponent<Camera>().targetTexture;
texture_size = new Vector2(rt.width, rt.height);
float offset = 0.5f;
var src = new List<Vector2>();
var dst = new List<Vector2>();
// front
{
src.Clear();
src.Add(new Vector2(0, 0));
src.Add(new Vector2(dim, 0));
src.Add(new Vector2(space.z, space.z));
src.Add(new Vector2(space.z + space.x, space.z));
for (int i = 0; i < src.Count; i++)
src[i] += Vector2.one * offset;
dst.Clear();
dst.Add(new Vector2(space.z, 0));
dst.Add(new Vector2(space.z + space.x, 0));
dst.Add(new Vector2(space.z, space.z));
dst.Add(new Vector2(space.z + space.x, space.z));
for (int i = 0; i < dst.Count; i++)
dst[i] += Vector2.one * offset;
front_homo = Matrix4x4.identity;
FindHomography(dst.ToArray(), src.ToArray(), ref front_homo);
}
// left
{
src.Clear();
src.Add(new Vector2(0, 0));
src.Add(new Vector2(0, dim));
src.Add(new Vector2(space.z, space.z));
src.Add(new Vector2(space.z, space.z + space.x));
for (int i = 0; i < src.Count; i++)
src[i] += Vector2.one * offset;
dst.Clear();
dst.Add(new Vector2(0, space.z));
dst.Add(new Vector2(0, space.z + space.x));
dst.Add(new Vector2(space.z, space.z));
dst.Add(new Vector2(space.z, space.z + space.x));
for (int i = 0; i < dst.Count; i++)
dst[i] += Vector2.one * offset;
left_homo = Matrix4x4.identity;
FindHomography(dst.ToArray(), src.ToArray(), ref left_homo);
}
// right
{
src.Clear();
src.Add(new Vector2(dim, 0));
src.Add(new Vector2(dim, dim));
src.Add(new Vector2(space.z + space.x, space.z));
src.Add(new Vector2(space.z + space.x, space.z + space.x));
for (int i = 0; i < src.Count; i++)
src[i] += Vector2.one * offset;
dst.Clear();
dst.Add(new Vector2(dim, space.z));
dst.Add(new Vector2(dim, space.z + space.x));
dst.Add(new Vector2(space.z + space.x, space.z));
dst.Add(new Vector2(space.z + space.x, space.z + space.x));
for (int i = 0; i < dst.Count; i++)
dst[i] += Vector2.one * offset;
right_homo = Matrix4x4.identity;
FindHomography(dst.ToArray(), src.ToArray(), ref right_homo);
}
}
private void Update()
{
Shader.SetGlobalMatrix("front_homo", front_homo);
Shader.SetGlobalMatrix("left_homo", left_homo);
Shader.SetGlobalMatrix("right_homo", right_homo);
Shader.SetGlobalVector("homo_space", space);
Shader.SetGlobalVector("texture_size", texture_size);
}
void FindHomography(Vector2[] src, Vector2[] dest, ref Matrix4x4 homography)
{
float[,] P = new float[,]{
{-src[0].x, -src[0].y, -1, 0, 0, 0, src[0].x*dest[0].x, src[0].y*dest[0].x, -dest[0].x }, // h11
{ 0, 0, 0, -src[0].x, -src[0].y, -1, src[0].x*dest[0].y, src[0].y*dest[0].y, -dest[0].y }, // h12
{-src[1].x, -src[1].y, -1, 0, 0, 0, src[1].x*dest[1].x, src[1].y*dest[1].x, -dest[1].x }, // h13
{ 0, 0, 0, -src[1].x, -src[1].y, -1, src[1].x*dest[1].y, src[1].y*dest[1].y, -dest[1].y }, // h21
{-src[2].x, -src[2].y, -1, 0, 0, 0, src[2].x*dest[2].x, src[2].y*dest[2].x, -dest[2].x }, // h22
{ 0, 0, 0, -src[2].x, -src[2].y, -1, src[2].x*dest[2].y, src[2].y*dest[2].y, -dest[2].y }, // h23
{-src[3].x, -src[3].y, -1, 0, 0, 0, src[3].x*dest[3].x, src[3].y*dest[3].x, -dest[3].x }, // h31
{ 0, 0, 0, -src[3].x, -src[3].y, -1, src[3].x*dest[3].y, src[3].y*dest[3].y, -dest[3].y }, // h32
};
GaussianElimination(ref P, 9);
float[] aux_H ={ P[0,8],P[3,8],0,P[6,8], // h11 h21 0 h31
P[1,8],P[4,8],0,P[7,8], // h12 h22 0 h32
0 , 0,1,0, // 0 0 0 0
P[2,8],P[5,8],0,1}; // h13 h23 0 h33
for (int i = 0; i < 16; i++) homography[i] = aux_H[i];
}
void GaussianElimination(ref float[,] A, int n)
{
int i = 0;
int j = 0;
int m = n - 1;
while (i < m && j < n)
{
int maxi = i;
for (int k = i + 1; k < m; k++)
{
if (Mathf.Abs(A[k, j]) > Mathf.Abs(A[maxi, j]))
{
maxi = k;
}
}
if (A[maxi, j] != 0)
{
if (i != maxi)
for (int k = 0; k < n; k++)
{
float aux = A[i, k];
A[i, k] = A[maxi, k];
A[maxi, k] = aux;
}
float A_ij = A[i, j];
for (int k = 0; k < n; k++)
{
A[i, k] /= A_ij;
}
for (int u = i + 1; u < m; u++)
{
float A_uj = A[u, j];
for (int k = 0; k < n; k++)
{
A[u, k] -= A_uj * A[i, k];
}
}
i++;
}
j++;
}
for (int k = m - 2; k >= 0; k--)
{
for (int l = k + 1; l < n - 1; l++)
{
A[k, m] -= A[k, l] * A[l, m];
}
}
}
}

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7cf1e6cce802d3c49a437b3125a95960
timeCreated: 1523516889
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -2,10 +2,8 @@
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Emission("Emission", Range(0, 5)) = 0.0
_Size("Size", Range(0, 1)) = 0.1
_Size("Size", Range(0.0, 0.1)) = 0.01
}
SubShader
@ -29,18 +27,17 @@
struct v2g
{
float4 vertex : SV_POSITION;
float4 color : COLOR;
};
struct g2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD;
float4 color : COLOR;
UNITY_FOG_COORDS(1)
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
half _Emission;
half _Size;
@ -56,19 +53,21 @@
#ifdef SHADER_API_D3D11
o.vertex = mul(model_matrix, float4(ssbo[vid].position, 1.0));
o.vertex.w = ssbo[vid].life;
o.color = ssbo[vid].color;
#endif
return o;
}
[maxvertexcount(6)]
[maxvertexcount(4)]
void geom(point v2g input[1], inout TriangleStream<g2f> OutputStream)
{
float3 position = input[0].vertex.xyz;
position = UnityObjectToViewPos(position);
float size = _Size * pow(saturate(1.0f - input[0].vertex.w), 1.0f / 2.2f);
const int side = 4;
float3 vertices[side];
float2 uvs[side];
const int side = 3;
g2f o = (g2f)0;
o.color = input[0].color;
float delta_a = UNITY_PI * 2.0f / side;
for (int i = 0; i < side; i++)
@ -76,36 +75,20 @@
float a = delta_a * i;
float x = cos(-a);
float y = sin(-a);
vertices[i] = position + float3(x * size, y * size, 0);
uvs[i] = float2(x, y) * 0.5f + 0.5f;
}
g2f o = (g2f)0;
int index;
for (int k = 0; k < side - 2; k++)
{
for (int j = 0; j < 3; j++)
{
index = (j == 0) ? 0 : (k + j);
o.vertex = mul(UNITY_MATRIX_P, float4(vertices[index], 1.0f));
o.uv = TRANSFORM_TEX(uvs[index], _MainTex);
UNITY_TRANSFER_FOG(o, o.vertex);
OutputStream.Append(o);
}
OutputStream.RestartStrip();
o.vertex = mul(UNITY_MATRIX_P, float4(position + float3(x * size, y * size, 0), 1.0f));
o.uv = float2(x, y);
UNITY_TRANSFER_FOG(o, o.vertex);
OutputStream.Append(o);
}
OutputStream.RestartStrip();
}
fixed4 frag(g2f i) : SV_Target
{
clip(0.5f / sqrt(2.0f) - length(i.uv - float2(0.5f, 0.5f)));
clip(0.5f / sqrt(2.0f) - length(i.uv));
fixed4 col = tex2D(_MainTex, i.uv) * _Color;
//fixed4 col = _Color;
fixed4 col = i.color;
col.rgb *= 1 + _Emission;
UNITY_APPLY_FOG(i.fogCoord, col);
return col;

@ -10,7 +10,7 @@ CBUFFER_START(Variables)
float timeStep;
float timeValue;
float bufferCount;
int home_count;
//int home_count;
float3 coeffsA;
float3 coeffsB;
float3 coeffsC;
@ -22,13 +22,15 @@ CBUFFER_END
RWStructuredBuffer<Particle> ssbo;
RWStructuredBuffer<ParticleUniforms> uniform_buffer;
RWStructuredBuffer<float4> home_position_buffer;
RWStructuredBuffer<float4> home_velocity_buffer;
RWStructuredBuffer<float3> fluid_velocity_buffer;
StructuredBuffer<int> home_count_buffer;
StructuredBuffer<float4> home_position_buffer;
StructuredBuffer<float4> home_velocity_buffer;
StructuredBuffer<float3> fluid_velocity_buffer;
[numthreads(WORK_GROUP_SIZE, 1, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
int home_count = home_count_buffer[0];
uint idx = id.x;
Particle p = ssbo[idx];
float4 home_position = (home_count > 0) ? home_position_buffer[p.seed * home_count] : float4(0, 0, 0, 1);

@ -0,0 +1,101 @@
Shader "Frozen/SpaceMapping"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
yFlip ("display name", Int) = 0
}
SubShader
{
Tags { "RenderType"="Opeque" }
LOD 100
//Blend One Zero
Blend One OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
int yFlip;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
float4x4 front_homo;
float4x4 left_homo;
float4x4 right_homo;
float3 homo_space;
float2 texture_size;
fixed4 frag (v2f i) : SV_Target
{
float2 uv = i.uv;
//if (yFlip == 1) uv = i.uv * float2(1.0, -1.0) + float2(0.0, 1.0);
fixed4 col = tex2D(_MainTex, uv);
col.rgb *= col.a;
const float3 space = homo_space;
//const float2 size = float2(space.x + space.z * 2.0, space.y + space.z * 2.0);
//const float dim = space.x + space.z * 2.0;
const float2 clipped_size = texture_size;
float2 pos = uv * clipped_size;
if (pos.y <= space.z)
{
float4 homo_pos = mul(front_homo, float4(pos, 0, 1));
pos = homo_pos.xy / homo_pos.w;
//if (pos.x < space.z || pos.x > space.z + space.x) pos = float2(clipped_size.x * 0.5, clipped_size.y);
}
else if (pos.x <= space.z)
{
float4 homo_pos = mul(left_homo, float4(pos, 0, 1));
pos = homo_pos.xy / homo_pos.w;
}
else if (pos.x >= space.z + space.x)
{
float4 homo_pos = mul(right_homo, float4(pos, 0, 1));
pos = homo_pos.xy / homo_pos.w;
}
uv = pos / clipped_size;
if (yFlip == 1) uv = uv * float2(1.0, -1.0) + float2(0.0, 1.0);
col = tex2D(_MainTex, uv);
//col = tex2D(_MainTex, i.uv * float2(1.0, -1.0) + float2(0.0, 1.0));
//col = float4(i.uv, 0.0, 1.0);
return col;
}
ENDCG
}
}
}

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 499c23f758325064e88cd0632bcb368f
timeCreated: 1490605733
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

@ -18,7 +18,7 @@ RenderTexture:
m_ColorFormat: 0
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_SRGB: 1
m_UseDynamicScale: 0
m_BindMS: 0
m_TextureSettings:

@ -18,7 +18,7 @@ RenderTexture:
m_ColorFormat: 0
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_SRGB: 1
m_UseDynamicScale: 0
m_BindMS: 0
m_TextureSettings:

@ -18,7 +18,7 @@ RenderTexture:
m_ColorFormat: 0
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_SRGB: 1
m_UseDynamicScale: 0
m_BindMS: 0
m_TextureSettings:

@ -51,6 +51,7 @@ namespace UltraCombos
ComputeBuffer home_velocity_buffer;
public ComputeBuffer HomeVelocityBuffer { get { return home_velocity_buffer; } }
ComputeBuffer home_count_buffer;
public ComputeBuffer HomeCountBuffer { get { return home_count_buffer; } }
int home_count = 0;
public int HomeCount { get { return home_count; } }
@ -110,10 +111,15 @@ namespace UltraCombos
}
{
ComputeBuffer.CopyCount(home_position_buffer, home_count_buffer, 0);
#if false
var data = new int[home_count_buffer.count];
home_count_buffer.GetData(data);
home_count = data[0];
#else
home_count = 0;
#endif
debugInfo = string.Format("{0}", home_count);
home_position_buffer.SetCounterValue(0);
home_velocity_buffer.SetCounterValue(0);

@ -1 +1 @@
m_EditorVersion: 2017.3.1f1
m_EditorVersion: 2017.4.1f1

Loading…
Cancel
Save