public void Init() { _numParticlesX = _particleGroupsX * kNumThreadsX; _numParticlesY = _particleGroupsY * kNumThreadsY; _numParticles = _numParticlesX * _numParticlesY; _currentCopiedVertices = 0; _particleMaterial = Resources.Load<Material>("GPUParticleMat"); _computeShader = Resources.Load<ComputeShader>("ComputeShaders/GPUParticleUpdater"); _kernelMoveParticles = _computeShader.FindKernel(kKernelMoveParticles); _particlesData = new Particle[_numParticles]; InitBuffer(_particlesData); for (int i = 0; i < _particlesData.Length; ++i) { float id = ((float)i) / 10000.1f; CreateParticle(id); } // Set ComputeShader Parameters _particlesBuffer = new ComputeBuffer(_particlesData.Length, System.Runtime.InteropServices.Marshal.SizeOf(typeof(GPUParticleSystem.Particle))); _particlesBuffer.SetData(_particlesData); _computeShader.SetBuffer(_kernelMoveParticles, "_ParticlesBuffer", _particlesBuffer); _computeShader.SetFloat("_Width", _numParticlesX); _computeShader.SetFloat("_Height", _numParticlesY); // Set Shader Parameters _particleMaterial.SetBuffer("_ParticlesBuffer", _particlesBuffer); }
public void SetConstants(ComputeShader compute, float dt) { compute.SetFloat(ShaderConst.PROP_DELTA_TIME, dt); compute.SetFloat(ShaderConst.PROP_ELASTICS, _data.elastics); compute.SetFloat(ShaderConst.PROP_PARTICLE_RADIUS, _data.radius); compute.SetVector(ShaderConst.PROP_BOUNDS, _data.bounds); }
// // GPU STUFF // private static void SetShaderVars(UnityEngine.ComputeShader shader, UnityEngine.Vector2 noiseOffset, bool normalize, float noiseScale) { shader.SetInt("octaves", octaves); shader.SetFloat("falloff", falloff); shader.SetInt("normalize", System.Convert.ToInt32(normalize)); shader.SetFloat("noiseScale", noiseScale); shader.SetVector("offset", noiseOffset); }
public void SetConstants(ComputeShader compute, float dt) { CheckDragCoeffs (); compute.SetFloat(ShaderConst.PROP_DELTA_TIME, dt); compute.SetFloat(ShaderConst.PROP_ELASTICS, _data.elastics); compute.SetFloat(ShaderConst.PROP_FRICTION, _data.friction); compute.SetFloat(ShaderConst.PROP_PARTICLE_RADIUS, _data.radius); compute.SetFloat(ShaderConst.PROP_PENETRATION_BIAS, _data.penetrationBias); compute.SetVector(ShaderConst.PROP_BOUNDS, _data.bounds); }
static public int SetFloat(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (matchType(l, argc, 2, typeof(int), typeof(float))) { UnityEngine.ComputeShader self = (UnityEngine.ComputeShader)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); self.SetFloat(a1, a2); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(string), typeof(float))) { UnityEngine.ComputeShader self = (UnityEngine.ComputeShader)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); self.SetFloat(a1, a2); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function SetFloat to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int SetFloat(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif int argc = LuaDLL.lua_gettop(l); if (matchType(l, argc, 2, typeof(int), typeof(float))) { UnityEngine.ComputeShader self = (UnityEngine.ComputeShader)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); self.SetFloat(a1, a2); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(string), typeof(float))) { UnityEngine.ComputeShader self = (UnityEngine.ComputeShader)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); self.SetFloat(a1, a2); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function SetFloat to call"); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
public void Init() { _grassShader = Resources.Load<Shader>("Shaders/GrassGeneratorShader"); _grassMaterial = Resources.Load<Material>("GrassGeneratorMat"); _noiseTex = Resources.Load<Texture>("Noise"); if(_noiseTex == null) { Debug.LogError("Not found noise"); } _grassComputeShader = Resources.Load<ComputeShader>("ComputeShaders/GrassComputeShader"); _initGrassKernelId = _grassComputeShader.FindKernel(kInitGrassKernel); _updateGrassKernelId = _grassComputeShader.FindKernel(kUpdateGrassKernel); _numGrassItems = _numGroupGrassX*_numGroupGrassY*kThreadsX*kThreadsY; _grassBuffer = new ComputeBuffer(_numGrassItems, System.Runtime.InteropServices.Marshal.SizeOf(typeof(GrassData))); _obstaclesBuffer = new ComputeBuffer(kMaxObstacles, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ObstacleData))); _grassComputeShader.SetFloat("_Width", _numGroupGrassX*kThreadsX); _grassComputeShader.SetFloat("_Height", _numGroupGrassY*kThreadsY); _grassComputeShader.SetTexture(_initGrassKernelId, "_NoiseTex", _noiseTex); _grassMaterial.SetTexture("_NoiseTex", _noiseTex); _grassMaterial.SetFloat("_Width", _numGroupGrassX*kThreadsX); _grassMaterial.SetFloat("_Height", _numGroupGrassY*kThreadsY); _grassComputeShader.SetBuffer(_initGrassKernelId, "_GrassBuffer", _grassBuffer); _grassComputeShader.SetBuffer(_updateGrassKernelId, "_GrassBuffer", _grassBuffer); _grassComputeShader.SetBuffer(_updateGrassKernelId, "_ObstaclesBuffer", _obstaclesBuffer); _grassComputeShader.SetInt("_NumObstacles", 0); _grassMaterial.SetBuffer("_GrassBuffer", _grassBuffer); _grassComputeShader.Dispatch(_initGrassKernelId, _numGroupGrassX, _numGroupGrassY, 1); #if GRASS_CPU _grassDataTestCPU = new GrassData[_numGrassItems]; _grassBuffer.GetData(_grassDataTestCPU); #endif _isInit = true; }
static public int SetFloat(IntPtr l) { try { UnityEngine.ComputeShader self = (UnityEngine.ComputeShader)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); self.SetFloat(a1, a2); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static public int SetFloat(IntPtr l) { try { UnityEngine.ComputeShader self = (UnityEngine.ComputeShader)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); self.SetFloat(a1, a2); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
void SetParameters(ComputeShader mat) { mat.SetFloat("Rg", Rg); mat.SetFloat("Rt", Rt); mat.SetFloat("RL", RL); mat.SetInt("TRANSMITTANCE_W", TRANSMITTANCE_W); mat.SetInt("TRANSMITTANCE_H", TRANSMITTANCE_H); mat.SetInt("SKY_W", SKY_W); mat.SetInt("SKY_H", SKY_H); mat.SetInt("RES_R", RES_R); mat.SetInt("RES_MU", RES_MU); mat.SetInt("RES_MU_S", RES_MU_S); mat.SetInt("RES_NU", RES_NU); mat.SetFloat("AVERAGE_GROUND_REFLECTANCE", AVERAGE_GROUND_REFLECTANCE); mat.SetFloat("HR", HR); mat.SetFloat("HM", HM); mat.SetVector("betaR", BETA_R); mat.SetVector("betaMSca", BETA_MSca); mat.SetVector("betaMEx", BETA_MSca / 0.9f); mat.SetFloat("mieG", Mathf.Clamp(MIE_G, 0.0f, 0.99f)); }
private static void DecodeFloat3D(int w, int h, int d, int c, float min, float max, RenderTexture tex, Color[] map, ComputeShader shader) { Color[] array = new Color[w * h * d]; Color[] array2 = new Color[w * h * d]; Color[] array3 = new Color[w * h * d]; Color[] array4 = new Color[w * h * d]; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { for (int k = 0; k < d; k++) { array[i + j * w + k * w * h] = new Color(0f, 0f, 0f, 0f); array2[i + j * w + k * w * h] = new Color(0f, 0f, 0f, 0f); array3[i + j * w + k * w * h] = new Color(0f, 0f, 0f, 0f); array4[i + j * w + k * w * h] = new Color(0f, 0f, 0f, 0f); if (c > 0) { array[i + j * w + k * w * h] = map[(i + j * w + k * w * h) * c]; } if (c > 1) { array2[i + j * w + k * w * h] = map[(i + j * w + k * w * h) * c + 1]; } if (c > 2) { array3[i + j * w + k * w * h] = map[(i + j * w + k * w * h) * c + 2]; } if (c > 3) { array4[i + j * w + k * w * h] = map[(i + j * w + k * w * h) * c + 3]; } } } } Texture3D texture3D = new Texture3D(w, h, d, TextureFormat.ARGB32, false); texture3D.hideFlags = HideFlags.HideAndDontSave; texture3D.filterMode = FilterMode.Point; texture3D.wrapMode = TextureWrapMode.Clamp; texture3D.SetPixels(array); texture3D.Apply(); Texture3D texture3D2 = new Texture3D(w, h, d, TextureFormat.ARGB32, false); texture3D2.hideFlags = HideFlags.HideAndDontSave; texture3D2.filterMode = FilterMode.Point; texture3D2.wrapMode = TextureWrapMode.Clamp; texture3D2.SetPixels(array2); texture3D2.Apply(); Texture3D texture3D3 = new Texture3D(w, h, d, TextureFormat.ARGB32, false); texture3D3.hideFlags = HideFlags.HideAndDontSave; texture3D3.filterMode = FilterMode.Point; texture3D3.wrapMode = TextureWrapMode.Clamp; texture3D3.SetPixels(array3); texture3D3.Apply(); Texture3D texture3D4 = new Texture3D(w, h, d, TextureFormat.ARGB32, false); texture3D4.hideFlags = HideFlags.HideAndDontSave; texture3D4.filterMode = FilterMode.Point; texture3D4.wrapMode = TextureWrapMode.Clamp; texture3D4.SetPixels(array4); texture3D4.Apply(); shader.SetFloat("_Min", min); shader.SetFloat("_Max", max); shader.SetTexture(0, "_TexR", texture3D); shader.SetTexture(0, "_TexG", texture3D2); shader.SetTexture(0, "_TexB", texture3D3); shader.SetTexture(0, "_TexA", texture3D4); shader.SetTexture(0, "des", tex); shader.Dispatch(0, w, h, d); UnityEngine.Object.Destroy(texture3D); UnityEngine.Object.Destroy(texture3D2); UnityEngine.Object.Destroy(texture3D3); UnityEngine.Object.Destroy(texture3D4); }