public void CreateTextures(AtmosphereParameters AP) { transmittanceT = RTExtensions.CreateRTexture(new Vector2(AtmosphereConstants.TRANSMITTANCE_W, AtmosphereConstants.TRANSMITTANCE_H), 0, Format); irradianceT_Read = RTExtensions.CreateRTexture(new Vector2(AtmosphereConstants.SKY_W, AtmosphereConstants.SKY_H), 0, Format); irradianceT_Write = RTExtensions.CreateRTexture(new Vector2(AtmosphereConstants.SKY_W, AtmosphereConstants.SKY_H), 0, Format); inscatterT_Read = RTExtensions.CreateRTexture(new Vector2(AtmosphereConstants.RES_MU_S * AtmosphereConstants.RES_NU, AtmosphereConstants.RES_MU), 0, Format, FilterMode.Bilinear, TextureWrapMode.Clamp, AtmosphereConstants.RES_R); inscatterT_Write = RTExtensions.CreateRTexture(new Vector2(AtmosphereConstants.RES_MU_S * AtmosphereConstants.RES_NU, AtmosphereConstants.RES_MU), 0, Format, FilterMode.Bilinear, TextureWrapMode.Clamp, AtmosphereConstants.RES_R); deltaET = RTExtensions.CreateRTexture(new Vector2(AtmosphereConstants.SKY_W, AtmosphereConstants.SKY_H), 0, Format); deltaSRT = RTExtensions.CreateRTexture(new Vector2(AtmosphereConstants.RES_MU_S * AtmosphereConstants.RES_NU, AtmosphereConstants.RES_MU), 0, Format, FilterMode.Bilinear, TextureWrapMode.Clamp, AtmosphereConstants.RES_R); deltaSMT = RTExtensions.CreateRTexture(new Vector2(AtmosphereConstants.RES_MU_S * AtmosphereConstants.RES_NU, AtmosphereConstants.RES_MU), 0, Format, FilterMode.Bilinear, TextureWrapMode.Clamp, AtmosphereConstants.RES_R); deltaJT = RTExtensions.CreateRTexture(new Vector2(AtmosphereConstants.RES_MU_S * AtmosphereConstants.RES_NU, AtmosphereConstants.RES_MU), 0, Format, FilterMode.Bilinear, TextureWrapMode.Clamp, AtmosphereConstants.RES_R); }
protected override void InitNode() { ApplyPresset(AtmosphereParameters.Get(AtmosphereBase)); Bake(); InitMisc(); InitMaterials(); InitMesh(); InitUniforms(SkyMaterial); InitUniforms(planetoid.MPB); SetUniforms(SkyMaterial); SetUniforms(planetoid.MPB); }
private void OnAtmospherePresetChanged(Body body, Atmosphere atmosphere, AtmosphereBase atmosphereBase) { if (body == null) { Debug.Log("Atmosphere: OnAtmospherePresetChanged body is null!"); return; } if (atmosphere == null) { Debug.Log("Atmosphere: OnAtmospherePresetChanged atmosphere is null!"); return; } atmosphere.ApplyPresset(AtmosphereParameters.Get(atmosphereBase)); atmosphere.Bake(); }
private void OnAtmosphereBaked(Planetoid planetoid, Atmosphere atmosphere) { if (planetoid == null) { Debug.Log("Atmosphere: OnAtmosphereBaked planetoid is null!"); return; } if (atmosphere == null) { Debug.Log("Atmosphere: OnAtmosphereBaked atmosphere is null!"); return; } atmosphere.ApplyPresset(AtmosphereParameters.Get(atmosphere.AtmosphereBase)); atmosphere.Reanimate(); }
private void DoWork(AtmosphereParameters AP) { finished = false; step = 0; order = 2; PreGo(AP); while (!finished) { Calculate(AP); } if (ClearAfterBake) { CollectGarbage(false, true); } }
public AtmosphereParameters(AtmosphereParameters from) { this.MIE_G = from.MIE_G; this.HR = from.HR; this.HM = from.HM; this.AVERAGE_GROUND_REFLECTANCE = from.AVERAGE_GROUND_REFLECTANCE; this.BETA_R = from.BETA_R; this.BETA_MSca = from.BETA_MSca; this.BETA_MEx = from.BETA_MEx; this.Rg = from.Rg; this.Rt = from.Rt; this.Rl = from.Rl; this.bRg = from.bRg; this.bRt = from.bRt; this.bRl = from.bRl; this.SCALE = from.SCALE; }
private IEnumerator DoWorkCoroutine(AtmosphereParameters AP) { finished = false; step = 0; order = 2; PreGo(AP); while (!finished) { Calculate(AP); for (int i = 0; i < 8; i++) { yield return(Yielders.EndOfFrame); } } if (ClearAfterBake) { CollectGarbage(false, true); } }
public void PreBake(AtmosphereParameters AP) { PreGo(AP); }
public void Calculate(AtmosphereParameters AP) { if (step == 0) { // computes transmittance texture T (line 1 in algorithm 4.1) transmittance.SetTexture(0, "transmittanceWrite", transmittanceT); transmittance.Dispatch(0, AtmosphereConstants.TRANSMITTANCE_W / NUM_THREADS, AtmosphereConstants.TRANSMITTANCE_H / NUM_THREADS, 1); } else if (step == 1) { // computes irradiance texture deltaE (line 2 in algorithm 4.1) irradiance1.SetTexture(0, "transmittanceRead", transmittanceT); irradiance1.SetTexture(0, "deltaEWrite", deltaET); irradiance1.Dispatch(0, AtmosphereConstants.SKY_W / NUM_THREADS, AtmosphereConstants.SKY_H / NUM_THREADS, 1); } else if (step == 2) { // computes single scattering texture deltaS (line 3 in algorithm 4.1) // Rayleigh and Mie separated in deltaSR + deltaSM inscatter1.SetTexture(0, "transmittanceRead", transmittanceT); inscatter1.SetTexture(0, "deltaSRWrite", deltaSRT); inscatter1.SetTexture(0, "deltaSMWrite", deltaSMT); //The inscatter calc's can be quite demanding for some cards so process //the calc's in layers instead of the whole 3D data set. for (int i = 0; i < AtmosphereConstants.RES_R; i++) { inscatter1.SetInt("layer", i); inscatter1.Dispatch(0, (AtmosphereConstants.RES_MU_S * AtmosphereConstants.RES_NU) / NUM_THREADS, AtmosphereConstants.RES_MU / NUM_THREADS, 1); } } else if (step == 3) { // copies deltaE into irradiance texture E (line 4 in algorithm 4.1) copyIrradiance.SetFloat("k", 0.0f); copyIrradiance.SetTexture(0, "deltaERead", deltaET); copyIrradiance.SetTexture(0, "irradianceRead", irradianceT_Read); copyIrradiance.SetTexture(0, "irradianceWrite", irradianceT_Write); copyIrradiance.Dispatch(0, AtmosphereConstants.SKY_W / NUM_THREADS, AtmosphereConstants.SKY_H / NUM_THREADS, 1); //Swap irradianceT_Read - irradianceT_Write RTUtility.Swap(ref irradianceT_Read, ref irradianceT_Write); } else if (step == 4) { // copies deltaS into inscatter texture S (line 5 in algorithm 4.1) copyInscatter1.SetTexture(0, "deltaSRRead", deltaSRT); copyInscatter1.SetTexture(0, "deltaSMRead", deltaSMT); copyInscatter1.SetTexture(0, "inscatterWrite", inscatterT_Write); //The inscatter calc's can be quite demanding for some cards so process //the calc's in layers instead of the whole 3D data set. for (int i = 0; i < AtmosphereConstants.RES_R; i++) { copyInscatter1.SetInt("layer", i); copyInscatter1.Dispatch(0, (AtmosphereConstants.RES_MU_S * AtmosphereConstants.RES_NU) / NUM_THREADS, AtmosphereConstants.RES_MU / NUM_THREADS, 1); } //Swap inscatterT_Write - inscatterT_Read RTUtility.Swap(ref inscatterT_Read, ref inscatterT_Write); //!!! } else if (step == 5) { //Here Nvidia GTX 430 or lower driver will crash. //If only ray1 or mie1 calculated - slow, but all is alright. //But if both - driver crash. //INSCATTER_SPHERICAL_INTEGRAL_SAMPLES = 8 - limit for GTX 430. // computes deltaJ (line 7 in algorithm 4.1) inscatterS.SetInt("first", (order == 2) ? 1 : 0); inscatterS.SetTexture(0, "transmittanceRead", transmittanceT); inscatterS.SetTexture(0, "deltaERead", deltaET); inscatterS.SetTexture(0, "deltaSRRead", deltaSRT); inscatterS.SetTexture(0, "deltaSMRead", deltaSMT); inscatterS.SetTexture(0, "deltaJWrite", deltaJT); //The inscatter calc's can be quite demanding for some cards so process //the calc's in layers instead of the whole 3D data set. for (int i = 0; i < AtmosphereConstants.RES_R; i++) { inscatterS.SetInt("layer", i); inscatterS.Dispatch(0, (AtmosphereConstants.RES_MU_S * AtmosphereConstants.RES_NU) / NUM_THREADS, AtmosphereConstants.RES_MU / NUM_THREADS, 1); } } else if (step == 6) { // computes deltaE (line 8 in algorithm 4.1) irradianceN.SetInt("first", (order == 2) ? 1 : 0); irradianceN.SetTexture(0, "deltaSRRead", deltaSRT); irradianceN.SetTexture(0, "deltaSMRead", deltaSMT); irradianceN.SetTexture(0, "deltaEWrite", deltaET); irradianceN.Dispatch(0, AtmosphereConstants.SKY_W / NUM_THREADS, AtmosphereConstants.SKY_H / NUM_THREADS, 1); } else if (step == 7) { // computes deltaS (line 9 in algorithm 4.1) inscatterN.SetTexture(0, "transmittanceRead", transmittanceT); inscatterN.SetTexture(0, "deltaJRead", deltaJT); inscatterN.SetTexture(0, "deltaSRWrite", deltaSRT); //The inscatter calc's can be quite demanding for some cards so process //the calc's in layers instead of the whole 3D data set. for (int i = 0; i < AtmosphereConstants.RES_R; i++) { inscatterN.SetInt("layer", i); inscatterN.Dispatch(0, (AtmosphereConstants.RES_MU_S * AtmosphereConstants.RES_NU) / NUM_THREADS, AtmosphereConstants.RES_MU / NUM_THREADS, 1); } } else if (step == 8) { // adds deltaE into irradiance texture E (line 10 in algorithm 4.1) copyIrradiance.SetFloat("k", 1.0f); copyIrradiance.SetTexture(0, "deltaERead", deltaET); copyIrradiance.SetTexture(0, "irradianceRead", irradianceT_Read); copyIrradiance.SetTexture(0, "irradianceWrite", irradianceT_Write); copyIrradiance.Dispatch(0, AtmosphereConstants.SKY_W / NUM_THREADS, AtmosphereConstants.SKY_H / NUM_THREADS, 1); //Swap irradianceT_Read - irradianceT_Write RTUtility.Swap(ref irradianceT_Read, ref irradianceT_Write); } else if (step == 9) { // adds deltaS into inscatter texture S (line 11 in algorithm 4.1) copyInscatterN.SetTexture(0, "deltaSRead", deltaSRT); copyInscatterN.SetTexture(0, "inscatterRead", inscatterT_Read); copyInscatterN.SetTexture(0, "inscatterWrite", inscatterT_Write); //The inscatter calc's can be quite demanding for some cards so process //the calc's in layers instead of the whole 3D data set. for (int i = 0; i < AtmosphereConstants.RES_R; i++) { copyInscatterN.SetInt("layer", i); copyInscatterN.Dispatch(0, (AtmosphereConstants.RES_MU_S * AtmosphereConstants.RES_NU) / NUM_THREADS, AtmosphereConstants.RES_MU / NUM_THREADS, 1); } //Swap inscatterT_Read - inscatterT_Write RTUtility.Swap(ref inscatterT_Read, ref inscatterT_Write); if (order < 4) { step = 4; order += 1; } } else if (step == 10) { //placeholder } else if (step == 11) { finished = true; } step++; }