From 587f07b7c17f228c5944bf3db71250fb1b2e8955 Mon Sep 17 00:00:00 2001 From: RaghadAl-Halabi Date: Mon, 13 Jun 2022 06:35:42 +0300 Subject: [PATCH] render --- Assets/Materials/Particle3D.mat | 10 +- Assets/Prefabs/Fluid3D.prefab | 2 +- Assets/Scripts/Fluid3D/FluidBase3D.cs | 4 + Assets/Scripts/Fluid3D/FluidRenderer3D.cs | 10 +- Assets/Shaders/Particle3D.shader | 81 +- Packages/manifest.json | 12 +- Packages/packages-lock.json | 14 +- ProjectSettings/MemorySettings.asset | 35 + ProjectSettings/ProjectVersion.txt | 4 +- ProjectSettings/boot.config | 0 UserSettings/EditorUserSettings.asset | 7 + UserSettings/Layouts/default-2021.dwlt | 964 ++++++++++++++++++++++ 12 files changed, 1115 insertions(+), 28 deletions(-) create mode 100644 ProjectSettings/MemorySettings.asset create mode 100644 ProjectSettings/boot.config create mode 100644 UserSettings/Layouts/default-2021.dwlt diff --git a/Assets/Materials/Particle3D.mat b/Assets/Materials/Particle3D.mat index ab03b1d..379a9ac 100644 --- a/Assets/Materials/Particle3D.mat +++ b/Assets/Materials/Particle3D.mat @@ -2,14 +2,15 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: Particle3D m_Shader: {fileID: 4800000, guid: 773f4e8ce8ec9c74cae8ffe7f76df354, type: 3} - m_ShaderKeywords: + m_ValidKeywords: [] + m_InvalidKeywords: [] m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 1 @@ -55,6 +56,7 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: - AbsorptionScale: 1.5 - _BumpScale: 1 @@ -68,7 +70,7 @@ Material: - _Mode: 0 - _OcclusionStrength: 1 - _Parallax: 0.02 - - _ParticleRadius: 0.1 + - _ParticleRadius: 0.5 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 @@ -78,5 +80,5 @@ Material: - AbsorptionCoff: {r: 0.45, g: 0.029, b: 0.018, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - - _WaterColor: {r: 0.25882354, g: 0.57254905, b: 0.97647065, a: 1} + - _WaterColor: {r: 0.8627451, g: 0.9556026, b: 1, a: 0.18039216} m_BuildTextureStacks: [] diff --git a/Assets/Prefabs/Fluid3D.prefab b/Assets/Prefabs/Fluid3D.prefab index 0bd996c..f3b273c 100644 --- a/Assets/Prefabs/Fluid3D.prefab +++ b/Assets/Prefabs/Fluid3D.prefab @@ -28,6 +28,7 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 @@ -84,6 +85,5 @@ MonoBehaviour: Lines: [] solver: {fileID: 3940404416909209042} RenderParticleMat: {fileID: 2100000, guid: 79b8e4e87d0027242b76475f51be3f57, type: 2} - WaterColor: {r: 0.25882354, g: 0.57254905, b: 0.97647065, a: 1} IsRenderInShader: 1 IsBoundsDrawed: 1 diff --git a/Assets/Scripts/Fluid3D/FluidBase3D.cs b/Assets/Scripts/Fluid3D/FluidBase3D.cs index ed39d6d..3988614 100644 --- a/Assets/Scripts/Fluid3D/FluidBase3D.cs +++ b/Assets/Scripts/Fluid3D/FluidBase3D.cs @@ -125,6 +125,10 @@ protected virtual void Awake() protected virtual void Start() { + var res = Screen.currentResolution; + print(res); + // float ratio = (float)res.width/res.height; + // print(ratio); InitBuffers(); InitProfilling(); } diff --git a/Assets/Scripts/Fluid3D/FluidRenderer3D.cs b/Assets/Scripts/Fluid3D/FluidRenderer3D.cs index 8100ce8..3fc0dc7 100644 --- a/Assets/Scripts/Fluid3D/FluidRenderer3D.cs +++ b/Assets/Scripts/Fluid3D/FluidRenderer3D.cs @@ -3,6 +3,7 @@ using UnityEngine.Profiling; using System.Collections.Generic; + namespace Kareem.Fluid.SPH { [RequireComponent(typeof(Fluid3D))] @@ -14,7 +15,7 @@ public class FluidRenderer3D : MonoBehaviour public Fluid3D solver; public Material RenderParticleMat; - public Color WaterColor; + // public Color WaterColor; public bool IsRenderInShader = true; public bool IsBoundsDrawed = true; @@ -42,8 +43,9 @@ void OnRenderObject() void DrawParticle() { float radius = 0.1f; + Color WaterColor = Color.blue; RenderParticleMat.SetPass(0); - RenderParticleMat.SetColor("_WaterColor", WaterColor); + // RenderParticleMat.SetColor("_WaterColor", WaterColor); RenderParticleMat.SetBuffer("_ParticlesBuffer", solver.ParticlesBuffer); // RenderParticleMat.SetFloat("_ParticleRadius", solver.BallRadius); @@ -54,11 +56,11 @@ void DrawParticle() } else { - DrawByExtension(radius); + DrawByExtension(radius, WaterColor); } } - void DrawByExtension(float radius) + void DrawByExtension(float radius, Color WaterColor) { GetDate.Begin(); FluidParticle3D[] particles = new FluidParticle3D[solver.NumParticles]; diff --git a/Assets/Shaders/Particle3D.shader b/Assets/Shaders/Particle3D.shader index 26e923a..e718b2d 100644 --- a/Assets/Shaders/Particle3D.shader +++ b/Assets/Shaders/Particle3D.shader @@ -1,4 +1,6 @@ -Shader "Custom/SPH3D" { + + +Shader "Custom/SPH3D" { Properties { _MainTex("Texture", 2D) = "black" {} _ParticleRadius("Particle Radius", Float) = 0.05 @@ -7,10 +9,13 @@ CGINCLUDE #include "UnityCG.cginc" + sampler2D _MainTex; float4 _MainTex_ST; - fixed4 _WaterColor; + float4 _WaterColor; + uniform float iTime; + uniform float3 iResolution; float _ParticleRadius; float4x4 _InvViewMatrix; @@ -21,7 +26,7 @@ }; struct g2f { - float4 pos : POSITION; + float4 pos : SV_POSITION; float2 tex : TEXCOORD0; float4 color : COLOR; }; @@ -33,6 +38,60 @@ StructuredBuffer _ParticlesBuffer; + float2 fract(float2 num){ + return num - floor(num); + } + + float2 random(float2 block_index){ + float2 p = float2(block_index); + float2 ret = fract(sin(float2(dot(p,float2(123.1,311.7)),dot(p,float2(269.5,183.3))))*4358.5453); + + return ret; + //return vec2(0., 0.); +} + + float4 mix(float4 v1, float4 v2, float a) { return v1 * (1 - a) + v2 * a;} + + float2 hash2(float2 p ) { + return fract(sin(float2(dot(p, float2(123.4, 748.6)), dot(p, float2(547.3, 659.3))))*5232.85324); + } + float hash(float2 p) { + return fract(sin(dot(p, float2(43.232, 75.876)))*4526.3257); + } + + float voronoi(float2 p) { + float2 n = floor(p); + float2 f = fract(p); + float md = 5.0; + + float2 m = float2(0.0, 0.0); + + for (int i = -1;i<=1;i++) { + for (int j = -1;j<=1;j++) { + float2 g = float2(i, j); + float o = hash(n+g); + o = 0.5+0.5*sin(unity_DeltaTime+5.038*o); + float2 r = g + o - f; + float d = dot(r, r); + if (d