Pryme8 Posted March 28, 2018 Share Posted March 28, 2018 So I am generating a Terrain Heightmap with a rtt. The idea is besides the zones texture size of 1024x1024, I am trying to have it generate a gutter around the applicable area so when I go to calculate normals I can sample a point that is off the zone. Now I am kinda lost on where to go from here, When sampling the texture I am doing it be detail units so pseudo code: var overflowUnit = textureSize/meshSubDivs; textureSize.xy += overflowUnit*2; then when I iterate over it: var pID=0; for(var y=1; y<detail.y+2; y++){ for(var x=1; x<detail.x+2; x++, pID+=3){ xUV = x/(detail.x+2); yUV = y/(detail.y+2); xp = (Math.floor(size.x*xUV)-this.args.overflow.x)+1; yp = (Math.floor(size.y*yUV)-this.args.overflow.y)+1; id = (xp*4)+(yp*size.x*4); var v = (this.getMapDataAtID(map, id)).r; v = this.transposeRange(v/255, this.args.heights.x, this.args.heights.y); vDat.positions[pID+1] = v; } } Now, how would I use this loop to manually define the normals? Pretty sure all the data is there. http://www.babylonjs-playground.com/#N123V9#23 *edit* http://www.babylonjs-playground.com/#N123V9#25 seems my numbers are off by a bit. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 28, 2018 Author Share Posted March 28, 2018 Really close on positions but something is still off:http://www.babylonjs-playground.com/#N123V9#29 anyone got an idea? http://www.babylonjs-playground.com/#N123V9#31 tried to simplify it but I am drawing a blank... smh Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 29, 2018 Author Share Posted March 29, 2018 http://www.babylonjs-playground.com/#0J7M2M#11 arg so close yet so far. I feel like I am not sampling the correct point from the rtt when I am looking up the textel space vs UV of the mesh. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 29, 2018 Author Share Posted March 29, 2018 http://www.babylonjs-playground.com/#0J7M2M#18 Gonna go about this a different way. Quote Link to comment Share on other sites More sharing options...
Guest Posted March 30, 2018 Share Posted March 30, 2018 Lol it is like a web log..Keep posting! Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 30, 2018 Author Share Posted March 30, 2018 http://www.babylonjs-playground.com/#0J7M2M#27 I am able to generate my normals now ( I think ) just gotta figure out how to display them when I am storing it as a texture. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 30, 2018 Author Share Posted March 30, 2018 I gotta figure out how to make this work: vec3 vLightPosition = vec3(0.,40.,10.); vec3 vPositionW = vec3(world * vec4(vPosition, 1.0)); vec3 vNormalW = normalize(vec3(world * vec4(texture(normalMap, vUV).rgb, 0.0))); vec3 viewDirectionW = normalize(cameraPosition - vPositionW); vec3 lightVectorW = normalize(vLightPosition - vPositionW); vec3 color = texture(heightMap, vUV).rgb; float ndl = max(0., dot(vNormalW, lightVectorW)); vec3 angleW = normalize(viewDirectionW + lightVectorW); float specComp = max(0., dot(vNormalW, angleW)); specComp = pow(specComp, max(1., 64.)) * 2.; gl_FragColor = vec4(color * ndl + vec3(specComp), 1.0); I am assuming its not even close... but I am not sure how to even validate if I am going the correct direction. Prolly need to go over this: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-13-normal-mapping/ Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 30, 2018 Author Share Posted March 30, 2018 uhg totally about to give up on this... I have no clue where to go with it. Which is sad, because I am really interested in this topic but Its hard to develop something with no support or anyone who can help ever. http://www.babylonjs-playground.com/#0J7M2M#33 hmmm how to figure out tangentSpace and bitTangent from the texture only. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 30, 2018 Author Share Posted March 30, 2018 http://www.babylonjs-playground.com/#0J7M2M#35 Rabble Rabble rabble... this has to be close. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 30, 2018 Author Share Posted March 30, 2018 http://sunandblackcat.com/tipFullView.php?l=eng&topicid=6 Been trying to follow along with this, but I am still having trouble... hmm anyone ever convert black and white values into a normal map? I'm doing it with noise and am pretty sure I got that par correct as far as sampling the 4 adjacent points to central point. Just having a disconect somewhere on the math to convert it to tangent space. http://www.babylonjs-playground.com/#0J7M2M#42 Line 380 in the generation shader is where the normal information is being processed. Any input would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Guest Posted April 2, 2018 Share Posted April 2, 2018 Not something I looked into already Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 3, 2018 Author Share Posted April 3, 2018 I think I might have fixed the math. http://www.babylonjs-playground.com/#WWJUIG#21 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 3, 2018 Author Share Posted April 3, 2018 sooooo close: http://www.babylonjs-playground.com/#WWJUIG#23 Everything comes up as black for some reason when I try to use the matrix effected normal's. but if I just use my texture sample (pan to the left and look around): http://www.babylonjs-playground.com/#WWJUIG#24 It kinda works... I really am not sure where to go with this from here though. I want to get my normals and lighting working before I start digging into the noise algorithms for generating more complex shapes. Quote Link to comment Share on other sites More sharing options...
Guest Posted April 3, 2018 Share Posted April 3, 2018 I'm with you!! keep the faith! Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 3, 2018 Author Share Posted April 3, 2018 Got any good references for some better lighting stuff? Maybe I can include the default Shader fragments and go from there. Quote Link to comment Share on other sites More sharing options...
Guest Posted April 3, 2018 Share Posted April 3, 2018 yes we can do that (sorry but I do not have a lot of time recently) Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 3, 2018 Author Share Posted April 3, 2018 You are ok I understand and am patient especially when you are the only one who has been able to help me! Ill prolly try to make an extension of the standardMaterial like Nasimi did, but with less stuff. It might actual be working, I think my normal values are not in tangent space. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 4, 2018 Author Share Posted April 4, 2018 So Im not so worried about my normal map being incorrect as much as the phong model now. I set the map to just a flat normal map and still have lighting issues so it has to be the way im doing the lighting. Quote Link to comment Share on other sites More sharing options...
Guest Posted April 4, 2018 Share Posted April 4, 2018 StandardMaterial uses phong by default. What is the problem you are facing precisely? Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 5, 2018 Author Share Posted April 5, 2018 Programming my own shader that has lighting >_< lol... If the CustomMaterial extension was actually working I could use that but its so its hard to develop with, and I am not sure whats a bug and whats not with it. I am having trouble figuring out our matrices that are bound and their name convention in comparison to what the rest of the world uses. -> but it looks like you addressed this on another post, so Ill use that to reference and keep posting on here if I get any progress. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 5, 2018 Author Share Posted April 5, 2018 http://www.babylonjs-playground.com/#WWJUIG#41 really struggling trying to fix the gapping between the zones... not sure what would cause it. Kinda giving up on lighting right now and moving on to erosion and bioms. Quote Link to comment Share on other sites More sharing options...
Guest Posted April 5, 2018 Share Posted April 5, 2018 Looks like the gap is coming from a precision issue with translateUVRange function (the height is not exactly the same as vertex do no overlap) I would suggest to make sure that every tile overlap a bit with the surrounding ones Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 6, 2018 Author Share Posted April 6, 2018 hmmm that's an interesting idea. I would wanna kinda stay away from that solution though as I will probably get some depth fighting then. Any ideas on how to fix the precision? I am trying to scale the UV down to a ratio that basically ignores the gutter area but still has access to it for CLAMPING fixes on the edge of the zone. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 6, 2018 Author Share Posted April 6, 2018 http://www.babylonjs-playground.com/#WWJUIG#42 Whoa... this is crazy. http://www.babylonjs-playground.com/#WWJUIG#43 I guess it was because I was re creating the shader and not rebinding texture. 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.