public void SetSplatImplementation(SplatImplementation implementation) { if (implementation == _splatImplementationChoice) { return; } _particleContainer = SplatEnumToInstance(_splatImplementationChoice); _particleContainer.Initialise(_numParticles, _waveParticleKillThreshold); }
public WaveParticleSystem(float particleSpeed, float particleRadius, int maxNumParticles, int horRes, int vertRes, float height, float width, float waveParticleKillThreshold) { _particleSpeed = particleSpeed; _particleRadius = particleRadius; _numParticles = maxNumParticles; _waveParticleKillThreshold = waveParticleKillThreshold; _currentFrame = 0; // TODO: move all relvant code to do with this to here! _frameCycleLength = WaveParticle.FRAME_CYCLE_LENGTH; _extendedHeightField = new ExtendedHeightField(width, height, horRes, vertRes); _extendedHeightField.Clear(); _particleContainer = SplatEnumToInstance(_splatImplementationChoice); _particleContainer.Initialise(maxNumParticles, waveParticleKillThreshold); _heightFieldGenerator = ConvEnumToInstance(_convolutionImplementationChoice); _heightFieldGenerator.Initialise(_extendedHeightField.heightFieldInfo, _particleContainer); }
void Start() { waterMaterial = GetComponent <Renderer>().material; waveParticles.Initialise(numWaveParticles, waveParticleKillThreshold); { int horRes = 100; int vertRes = 100; float height = 8; float width = 8; extendedHeightField = new ExtendedHeightField(width, height, horRes, vertRes); extendedHeightField.Clear(); } _mesh = GetComponent <MeshFilter>().mesh; vertices = new Vector3[extendedHeightField.HoriRes * extendedHeightField.VertRes]; uv = new Vector2[extendedHeightField.HoriRes * extendedHeightField.VertRes]; triangles = new int[(extendedHeightField.HoriRes - 1) * (extendedHeightField.VertRes - 1) * 6]; heightFieldGenerator = HeightFieldGeneratorSelector.CreateAndInitialise(selectedHeightFieldGenerator, extendedHeightField.heightFieldInfo, waveParticles); // Initialise and set-up the mesh the wave particles will be rendered to { GenerateMeshFromHeightMap(extendedHeightField, vertices, uv, triangles, _mesh); Renderer rend = GetComponent <Renderer>(); if (rend != null) { rend.material = waterMaterial; waterMaterial.SetTexture(Shader.PropertyToID("_MainTex"), extendedHeightField.textureHeightMap); waterMaterial.SetFloat(Shader.PropertyToID("_UnitX"), extendedHeightField.UnitX); waterMaterial.SetFloat(Shader.PropertyToID("_UnitY"), extendedHeightField.UnitY); waterMaterial.SetFloat(Shader.PropertyToID("_HoriResInverse"), 1f / ((float)extendedHeightField.HoriRes)); waterMaterial.SetFloat(Shader.PropertyToID("_VertResInverse"), 1f / ((float)extendedHeightField.VertRes)); waterMaterial.SetInt(Shader.PropertyToID("_VertexEnabled"), _useGpuForVertices ? 1 : 0); } } _hasStarted = true; }