dbawel Posted June 20, 2016 Share Posted June 20, 2016 Great post - lots to learn here... This is one of those days and this topic in particular by which my understanding of several processes in BJS has taken a leap in understanding how to manage reflections efficiently. I have loads of work to do, yet I find myself spending time I don't have to reconcile the many Playground examples posted here today. I just hope I save enough time to actually get my work done. DB gamefan 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 21, 2016 Share Posted June 21, 2016 This is the current computation: https://github.com/BabylonJS/Babylon.js/blob/7317ed822e3e2d52a44966fa4d2fdc3b0a91291a/src/Shaders/ShadersInclude/reflectionFunction.fx#L42 So you suggest to replace it by this, correct? vec3 viewDir = worldPos.xyz - vEyePosition; mat4 reflectionMatrix = mat4(-1.,0.,0.,0.,0.,-1.,0.,0.,0.,0.,-1.,0.,0.,0.,0.,-1.); vec3 coords = reflect(normalize(worldPos.xyz * 3.141592653589793 * length(viewDir) *.1 - vEyePosition.xyz),worldNormal.xyz); return vec3(reflectionMatrix * vec4(coords, 0)); So what is 0.1 here? Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted June 21, 2016 Share Posted June 21, 2016 i don't know but i think it is relation for camera fav (perspective) and about reflectionMatrix you need have a uniform like this Quote Link to comment Share on other sites More sharing options...
gamefan Posted June 21, 2016 Author Share Posted June 21, 2016 Wow, I am really glad a lot is happening here.. Too bad my understanding of the babylonjs internals is very little. I hope to learn very soon. And I think its going to work for probes as well, adam got it working in his playgrounds. Nice Quote Link to comment Share on other sites More sharing options...
adam Posted June 21, 2016 Share Posted June 21, 2016 1 minute ago, gamefan said: adam got it working in his playgrounds I didn't really do anything. All credit goes to NasimiAsi and Deltakosh. gamefan 1 Quote Link to comment Share on other sites More sharing options...
gamefan Posted June 21, 2016 Author Share Posted June 21, 2016 Yeah, NasimiAsi made it work. Huge huge thanks to him. I was meaning to say that you got it working for probes, so his solution works. Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted June 25, 2016 Share Posted June 25, 2016 @Deltakosh and all BABYLONJS Devs : don't forget finish this task. we are bug in reflection we can not see this bug in rounded mesh like sphere but we have it Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 25, 2016 Share Posted June 25, 2016 I'm still waiting for a good candidate for "0.1" value Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 25, 2016 Share Posted June 25, 2016 And can you explain the math behind: vec3 coords = reflect(normalize(worldPos.xyz * 3.141592653589793 * length(viewDir) *.1 - vEyePosition.xyz),worldNormal.xyz); ? Quote Link to comment Share on other sites More sharing options...
adam Posted June 25, 2016 Share Posted June 25, 2016 This page might help: http://www.physicsclassroom.com/calcpad/refln Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted June 25, 2016 Share Posted June 25, 2016 i write what i think about that and why i change this parameters Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 27, 2016 Share Posted June 27, 2016 to me it is more related to this: https://community.arm.com/groups/arm-mali-graphics/blog/2014/08/07/reflections-based-on-local-cubemaps Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted June 28, 2016 Share Posted June 28, 2016 11 hours ago, Deltakosh said: to me it is more related to this: https://community.arm.com/groups/arm-mali-graphics/blog/2014/08/07/reflections-based-on-local-cubemaps where is the LocalCorrect in DefaultShader float3 viewDirWS = normalize(input.viewDirInWorld); float3 normalWS = normalize(input.normalInWorld); float3 reflDirWS = reflect(viewDirWS, normalWS); // Get local corrected reflection vector. float3 localCorrReflDirWS = LocalCorrect(reflDirWS, _BBoxMin, _BBoxMax, input.vertexInWorld, _EnviCubeMapPos) // Lookup the environment reflection texture with the right vector. reflColor = texCUBE(_Cube, localCorrReflDirWS); it is not Exactly what i append but very close to that in localCorrect change the world pos and cube Map Pos at last with control min and max and after result it change ViewDirection i dont know about _BBoxMin and _BBoxMax (BindingBOX ? ) but we r not correct that we have computeReflectionCoords this maybe calculate that but i know this not have Distance parameters because we don't send any parameter about that we just have ' vec4(vPositionW,1.0) ' ' normalW ' // Find the ray intersection with box plane float3 invOrigVec = float3(1.0,1.0,1.0)/origVec; float3 intersecAtMaxPlane = (bboxMax - vertexPos) * invOrigVec; float3 intersecAtMinPlane = (bboxMin - vertexPos) * invOrigVec; // Get the largest intersection values (we are not intersted in negative values) float3 largestIntersec = max(intersecAtMaxPlane, intersecAtMinPlane); // Get the closest of all solutions float Distance = min(min(largestIntersec.x, largestIntersec.y), largestIntersec.z); // Get the intersection position float3 IntersectPositionWS = vertexPos + origVec * Distance; // Get corrected vector float3 localCorrectedVec = IntersectPositionWS - cubemapPos; return localCorrectedVec; Quote Link to comment Share on other sites More sharing options...
Sebavan Posted June 28, 2016 Share Posted June 28, 2016 Hello, The unity way is one good trade off perf vs quality for local reflections and the one used in a few engines for local cube map. This works nicely without magic numbers. http://www.babylonjs-playground.com/#1NP9BY#19 This would nevertheless require to be in another #define to avoid the cost of the computation in none local reflection and also be applied to refraction. Hope that could help, adam and NasimiAsl 2 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 28, 2016 Share Posted June 28, 2016 Yep..there is no simple way to fix the default shader here. I would highly recommend to use @NasimiAsl version with ShaderBuilder. 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.