/// <summary> /// Read texture data and bg color from environments /// </summary> public void HandleEnvironments(RenderEnvironment.Usage usage) { SimulatedEnvironment simenv; switch (usage) { case RenderEnvironment.Usage.Background: if (BackgroundEnvironment != null) { simenv = BackgroundEnvironment.SimulateEnvironment(true); if (simenv != null) { BgColor = simenv.BackgroundColor; } BitmapConverter.EnvironmentBitmapFromEvaluator(BackgroundEnvironment, BgTexture, Gamma); } else { BgColor = Color.Empty; BgTexture.Clear(); } break; case RenderEnvironment.Usage.Skylighting: if (SkylightEnvironment != null) { simenv = SkylightEnvironment.SimulateEnvironment(true); if (simenv != null) { SkyColor = simenv.BackgroundColor; } BitmapConverter.EnvironmentBitmapFromEvaluator(SkylightEnvironment, SkyTexture, Gamma); } else { SkyColor = Color.Empty; SkyTexture.Clear(); } break; case RenderEnvironment.Usage.ReflectionAndRefraction: if (ReflectionEnvironment != null) { simenv = ReflectionEnvironment.SimulateEnvironment(true); if (simenv != null) { ReflectionColor = simenv.BackgroundColor; } BitmapConverter.EnvironmentBitmapFromEvaluator(ReflectionEnvironment, ReflectionTexture, Gamma); } else { ReflectionColor = Color.Empty; ReflectionTexture.Clear(); } break; } }
protected override void ApplyEnvironmentChanges(RenderEnvironment.Usage usage) { // background - when camera ray doesn't hit any geometry // skylight - image-based lighting // reflection - what is seen in reflections var env = EnvironmentForid(EnvironmentIdForUsage(usage)); RhinoApp.WriteLine(env != null ? $"{usage} {env.Name}" : $"No env for {usage}"); // retrieving textures is with RenderMaterial, refer to HandleRenderMaterial() }
/// <summary> /// Set the RenderEnvironment for usage /// </summary> /// <param name="environment"></param> /// <param name="usage"></param> public void SetBackground(RenderEnvironment environment, RenderEnvironment.Usage usage) { switch (usage) { case RenderEnvironment.Usage.Background: if (environment?.RenderHash == _cqBackground.BackgroundEnvironment?.RenderHash) { return; } _cqBackground.Xml = ""; var xmlenv = (environment?.TopLevelParent as Materials.ICyclesMaterial); if (xmlenv?.MaterialType == RhinoCyclesCore.ShaderBody.CyclesMaterial.XmlEnvironment || xmlenv?.MaterialType == RhinoCyclesCore.ShaderBody.CyclesMaterial.SimpleNoiseEnvironment) { xmlenv.BakeParameters(); _cqBackground.Xml = xmlenv.MaterialXml; } _cqBackground.BackgroundEnvironment = environment; if (environment != null) { var s = environment.GetParameter("background-projection") as IConvertible; var proj = Convert.ToString(s, CultureInfo.InvariantCulture); _cqBackground.PlanarProjection = proj.Equals("planar"); } else { _cqBackground.PlanarProjection = false; } break; case RenderEnvironment.Usage.Skylighting: _cqBackground.SkylightEnvironment = environment; break; case RenderEnvironment.Usage.ReflectionAndRefraction: _cqBackground.ReflectionEnvironment = environment; break; } _cqBackground.Modified = true; }
public void HandleEnvironments(RenderEnvironment.Usage usage) { _cqBackground.HandleEnvironments(usage); }
/// <summary> /// Read texture data and bg color from environments /// </summary> public void HandleEnvironments(RenderEnvironment.Usage usage) { SimulatedEnvironment simenv; switch (usage) { case RenderEnvironment.Usage.Background: if (background_environment != null) { simenv = background_environment.SimulateEnvironment(true); if (simenv != null) { bg_color = simenv.BackgroundColor; } } else { bg_color = Color.Empty; bg.Clear(); } BitmapConverter.EnvironmentBitmapFromEvaluator(background_environment, bg, Gamma, PlanarProjection); break; case RenderEnvironment.Usage.Skylighting: bool resampled = false; if (skylight_environment != null) { simenv = skylight_environment.SimulateEnvironment(true); if (simenv != null) { sky_color = simenv.BackgroundColor; } } else { sky_color = Color.Empty; sky.Clear(); } if (!resampled) { BitmapConverter.EnvironmentBitmapFromEvaluator(skylight_environment, sky, Gamma, false); } break; case RenderEnvironment.Usage.ReflectionAndRefraction: if (reflection_environment != null) { simenv = reflection_environment.SimulateEnvironment(true); if (simenv != null) { refl_color = simenv.BackgroundColor; } } else { refl_color = Color.Empty; refl.Clear(); } BitmapConverter.EnvironmentBitmapFromEvaluator(reflection_environment, refl, Gamma, false); break; } }