georage Posted January 24, 2017 Share Posted January 24, 2017 Is it possible to remove the effect? Is it possible to check if the effect has been applied to a mesh (other than an independent variable)? I have an onClick event that adds the effect to the clicked mesh, but it seems to multiply the effect every time the mesh is clicked and it starts to look crazy. I'd like to remove the effect from non-targeted meshes to save gpu cycles, and be able to check if the effect even needs to be applied. Thanks for any tips. Here is an old playground I made if someone wants to play with it. http://babylonjs-playground.com/#AX6IZ#3 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted January 24, 2017 Share Posted January 24, 2017 http://www.html5gamedevs.com/topic/23509-dispose-godrays/#comment-134451 (found with forum search for 'dispose godrays') But, there's more fun ways: http://babylonjs-playground.com/#AX6IZ#5 Now you know how to dispose a godrays. Let's look at some more things. Ready for a playground tour? I knew you were. First, let's look at line 10, a basic hemi light (disabled). I needed to turn that on... to allow a .diffuseColor on the sun's material... to produce the godrays. You were using an .emissiveColor, which also works fine, and without needing to shine light on the sun. I just wanted to test .diffuseColor for godrays, too. I needed the hemi light momentarily... because the pointLight was not lighting the sun mesh itself. (I'm not sure it is SUPPOSED to. The point light might be there ONLY to light other scene mesh, and not the sun mesh itself.) The reason the pointLight (which is inside the sun mesh because of line 19) was not lighting the sun mesh... is because the sun mesh was constructed with sideOrientation.FRONTSIDE. At the end of line 18, I set the sun mesh to a BACKSIDE mesh. Now I can turn off the hemiLight, and the pointLight inside the sun mesh... also lights the sun mesh. DOUBLESIDE should work, too, I think... but it doesn't. Feel free to go back to emissiveColor... if you please, where the mesh produces its own light. I just wanted to do some tests. In lines 27-31, I included some godrays properties that can be tweaked/set. They are currently set to default values. You can also "turn off" a godrays (VLS)... by setting that .density = 0. OR, you can push the sun mesh into the godray's .excludedMeshes array (and take it back out)... to disable/enable the VLS. Line 33... just for fun... I "overloaded" the sun mesh... by adding a .godrays property, and I put the godrays post-proc-obj... INTO that property. The sun now "carries" its own VLS. This might not appropriate for 10,000 stars, but for something like the sun... it might be wise and handy. You might also consider sun.lightSource = sunlight, another "overload". Now the sun carries its godrays AND its light... with it. So now, sun.godrays.density = 0... turns off the sun's rays. So does sun.godrays.excludedMeshes.push(sun); Setting sun.godrays.excludedMeshes = []; ... would turn it back ON. Lastly, let's look at line 40 and 41. If you DO set sun.godrays = godrays (like line 33), then when you dispose it (line 40)... you should also do line 41. The godrays might not dispose properly... IF a reference to it... is still living in sun.godrays. You should release it from its duty as the property filler of sun.godrays. These godrays are very devoted, and they won't walk off the job. Once you relieve the godrays from sun.godrays duty... then it will dispose properly. Understand? I hope so. I COULD have told you wrong things. Check my stuff, and feel free to correct me... if your experiments prove me wrong. I'm no Godrays God. Ok George... you are now the world's leading expert on BJS godrays. (OH NO, huh?) Hope this helps. Ask questions if you like, of course. Party on! PS: Special thanks to @Luaacro for helping us with the godrays.dispose(camera) information, and to @OXY11 for the initial good question. They "blazed some trails" for us, here. georage and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
georage Posted January 24, 2017 Author Share Posted January 24, 2017 do they pay you wingy? i hope so. and well! thanks again. I searched for hours and never hit the right links. but i did see you helping many people. i particularly liked this one. http://playground.babylonjs.com/#MX8Q6 (cool colored spotlights) and this one ... http://playground.babylonjs.com/#5R8A1 (layered fog) I feel like WE owe you many beers. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
georage Posted January 24, 2017 Author Share Posted January 24, 2017 Well I'm as dense as a neutron star but I finally got it to work! Thanks wingy! for those who may find such things useful, this onclick function targets an arcRotate camera and toggles godrays on selected/previously selected objects. My star meshes are overloaded with custom names (sName for star name) which I check to make sure the mesh exists before trying to remove the godrays effect, so if you use this function be aware of this line ... if (prevTarget.sName). It will work without the check but throw an error the first time you select a mesh since no prior mesh/camera target exists. Also useful is the star != prevTarget check because it seems you can add godrays on top of godrays and the effect starts to look terrible if you do that too much. function focusCamera(camera, star){ //define previous star var prevTarget = camera.target; //retarget camera to selected star camera.setTarget(star); //set distance var camRad = star.sSize*12; camera.radius = camRad; console.log("set camera radius to "+camRad); //don't apply godrays to star that already has godrays if(star != prevTarget){ //apply godrays effect to selected star var godrays = new BABYLON.VolumetricLightScatteringPostProcess('godrays', 1.0, camera, star, 90, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, true); star.godrays = godrays; //if previous star is a mesh, delete godrays from it if(prevTarget.sName){ console.log(prevTarget.sName); prevTarget.godrays.excludedMeshes.push(prevTarget); } else{ console.log("no previous camera target"); } } } GameMonetize and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted January 25, 2017 Share Posted January 25, 2017 Interesting! Thanks for the info, code, and kind words. And yes, I get paid... by getting to be around VERY smart and inventive people... who are very patient with me... and they let me sort-of run-with the forum... in my own way. I really only answer the easier questions. The difficult things... are still for the big dogs... but I get the "pay" of reading big-dog answers to tough questions. It is pretty wonderful. I have learned TONS of things since I started hanging-around here. Free schooling, and with a pile of fascinating classmates. What else could a person ask-for? This forum is probably in the upper 5% of all forums, quality-wise. We have a top-notch leading-edge-tech subject matter (BJS), and kind and knowledgeable forum helpers. Our framework is the fastest-per-features-set... (most bang-for-the-bytes) of any of them, and we're all sort of big/muscular... so we can easily beat-up most ThreeJS people... anytime, for any reason. It's all good! Really though, it's the LIKES and nice words... they are great. (thx agn for that, George) But, believe you me... I get LOTS of schooling from here. EVERYONE teaches me things... including you, George. This is just an excellent place, with cool people, rallied around a superb product. It's easy to be helpful and happy... around here. And the playground? What a wonderful tool. It might be called a "play" ground, but it's a serious "work" horse, eh? What a sweet app. I want to have its baby! Errr... wait... no... that won't work. Party on! I'm going to go read more Deltakosh/other God replies to difficult questions... do some more learning. If Deltakosh falls asleep for the next 14 years... I can catch-up with him on webGL knowledge and JS prowess. heh. (maybe) georage 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.