Jump to content

Get Normal's from Texture that includes overflow


Pryme8
 Share

Recommended Posts

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.


 

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...