public override void ApplyParameters(Fractal fractal) { context.Synchronize(); mainStream.Synchronize(); float invAspectRatio = (XRes > 0) ? ((float)YRes / (float)XRes) : 0.0f; Affine2D viewTransform = fractal.CameraTransform.Inverse; Affine2D projTransform = new Affine2D(invAspectRatio, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); float xHalf = (float)XRes / 2.0f; float yHalf = (float)YRes / 2.0f; Affine2D screenTransform = new Affine2D(xHalf, 0.0f, 0.0f, yHalf, xHalf, yHalf); vpsTransform = screenTransform * projTransform * viewTransform; module.WriteConstant("vpsTransform", vpsTransform); module.WriteConstant("brightness", fractal.Brightness); float invGamma = 1.0f / fractal.Gamma; module.WriteConstant("invGamma", invGamma); module.WriteConstant("vibrancy", fractal.Vibrancy); module.WriteConstant("bgColor", fractal.BackgroundColor); Int32 branchCount = Math.Min(MaxBranches, fractal.Branches.Count); module.WriteConstant("branchCount", branchCount); Affine2D[] branchPreTransforms = new Affine2D[MaxBranches]; Affine2D[] branchPostTransforms = new Affine2D[MaxBranches]; float[] branchLumas = new float[MaxBranches]; Vec2[] branchChromas = new Vec2[MaxBranches]; float[] branchFactors = new float[MaxBranches * MaxFactors]; UInt32[] branchNormWeights = new UInt32[MaxBranches]; branchNormWeights.AssignAll((i) => (UInt32)0x00010000); float branchWeightSum = 0.0f; for (int bi = 0; bi < branchCount; bi++) { branchWeightSum += fractal.Branches[bi].Weight; } float[] branchColorWeights = new float[MaxBranches]; UInt32 runningSum = 0; for (int bi = 0; bi < branchCount; bi++) { Branch branch = fractal.Branches[bi]; branchPreTransforms[bi] = branch.PreTransform; branchPostTransforms[bi] = branch.PostTransform; branchLumas[bi] = branch.Luma; branchChromas[bi] = branch.Chroma; runningSum += (UInt32)(branch.Weight / branchWeightSum * 65536.0f); if (bi < branchCount - 1) { branchNormWeights[bi] = runningSum; } else { branchNormWeights[bi] = 0x00010000; } branchColorWeights[bi] = branch.ColorWeight; foreach (Branch.VariEntry ve in branch.Variations) { if (ve.Index >= 0 && ve.Index < MaxFactors) { branchFactors[MaxFactors * bi + ve.Index] += ve.Weight; } } } module.WriteConstant("branchPreTransforms", branchPreTransforms); module.WriteConstant("branchPostTransforms", branchPostTransforms); module.WriteConstant("branchLumas", branchLumas); module.WriteConstant("branchChromas", branchChromas); module.WriteConstant("branchNormWeights", branchNormWeights); module.WriteConstant("branchColorWeights", branchColorWeights); module.WriteConstant("branchFactors", branchFactors); context.Synchronize(); }