public FastFourierTransform(RenderDrawContext context, int size, FastFourierTransformShaders shaders) { _size = size; _shaders = shaders; _precomputedData = PrecomputeTwiddleFactorsAndInputIndices(context); }
public override void Draw(RenderContext context) { base.Draw(context); var graphicsDevice = Services.GetService <IGraphicsDeviceService>().GraphicsDevice; var sceneSystem = context.Services.GetService <SceneSystem>(); var camera = sceneSystem.TryGetMainCamera(); if (camera == null) { return; } var time = (float)sceneSystem.Game.UpdateTime.Total.TotalSeconds; var deltaTime = (float)sceneSystem.Game.UpdateTime.Elapsed.TotalSeconds; if (_calculateInitialSpectrumShader == null) { // TODO: DISPOSE AT SYSTEM REMOVAL! _calculateInitialSpectrumShader = new ComputeEffectShader(context) { ShaderSourceName = "OceanCalculateInitialSpectrum", Name = "OceanCalculateInitialSpectrum" }; _calculateConjugatedSpectrumShader = new ComputeEffectShader(context) { ShaderSourceName = "OceanCalculateConjugatedSpectrum", Name = "OceanCalculateConjugatedSpectrum" }; _timeDependantSpectrumShader = new ComputeEffectShader(context) { ShaderSourceName = "OceanTimeDependentSpectrum", Name = "OceanTimeDependentSpectrum" }; _fillResultTexturesShader = new ComputeEffectShader(context) { ShaderSourceName = "OceanFillResultTextures", Name = "OceanFillResultTextures" }; _generateMipsShader = new ComputeEffectShader(context) { ShaderSourceName = "OceanGenerateMips", Name = "OceanGenerateMips" }; _fastFourierTransformShaders = new FastFourierTransformShaders(context); } Dispatcher.ForEach(ComponentDatas, (pair) => { var component = pair.Key; var data = pair.Value; var entity = component.Entity; var renderDrawContext = context.GetThreadContext(); var commandList = renderDrawContext.CommandList; // Update shader parameters for wave settings component.WavesSettings.UpdateShaderParameters(); // Create cascades if dirty var calculateInitials = component.AlwaysRecalculateInitials; if (data.Size != component.Size || data.Cascades == null) { data.DestroyCascades(); data.Size = component.Size; // Create noise texture data.GaussianNoise?.Dispose(); var rng = new Random(); var noise = new Vector2[data.Size * data.Size]; for (int y = 0; y < data.Size; y++) { for (int x = 0; x < data.Size; x++) { var index = y * data.Size + x; noise[index] = new Vector2(NormalRandom(rng), NormalRandom(rng)); } } data.GaussianNoise = Texture.New2D(graphicsDevice, data.Size, data.Size, PixelFormat.R32G32_Float, noise, TextureFlags.ShaderResource | TextureFlags.UnorderedAccess);