Multiple textures on a terrain

Started by AceGIS, August 24, 2012, 06:26:26 AM

Previous topic - Next topic

AceGIS

Hi Egon,

Disregard the transformToGL() request. The engine already applies this to my model? Is this correct?

EgonOlsen

tranformToGL is meant for the case where you want to use a jPCT-Matrix directly in OpenGL, for example in a shader. You usually don't have to care about it.

AceGIS

Hi Egon,

I have made some great progress with my AR app. I finally understand the OpenGL coordinate system and have created a Lat/Long to OpenGL coordinate converter method to handle the live navigation.

I would now like to improve the rendering of my model. As you can see in the attached screen shot (you told me this would be the case) my model is jagged due to assigning a texture based on the vertex height.

I would now like to try a shader approach. I need to assign different textures based on the terrains height value. Could you please show me an example of shading a terrain using only the height values (or does the shader need x, y values also?).

[attachment deleted by admin]

K24A3

#18
What you could do is create a thin mixed color layer between the main colors.

For example you could put a strip of Orange between Red  and Yellow to blend them in better which should relieve the harshness of the jaggies.

between 300 and 398 = Red
between 398 and 402 = Orange
between 402 and up = Yellow

...or you could simply modify the textures themselves to contain the color transition at the top and bottom of the texture.

EgonOlsen

Quote from: K24A3 on September 28, 2012, 09:49:15 AM
...or you could simply modify the textures themselves to contain the color transition at the top and bottom of the texture.
That's a neat idea IMHO. You could create some large texture that contains all the colors incl. the transitions and just map u/v accordingly to the height.

AceGIS

#20
Hi Egon,

How do you mean "map u/v accordingly to the height"?

I tried adding the transition colors to the textures but the transitions are not where I expected them to be? The textures seem to be rotated on their side?

I also had the thaught that I could create a scaled/graduated jpeg containing all the colors I need and then use some algorithm to select colors based on the models height. Is this what you are suggesting Egon? How would I do this?

I also thaught I may be able to use the pixel values similar to how jPCT-AE uses the Blit class??

EgonOlsen

Quote from: AceGIS on October 02, 2012, 05:06:37 AM
I also had the thaught that I could create a scaled/graduated jpeg containing all the colors I need and then use some algorithm to select colors based on the models height. Is this what you are suggesting Egon? How would I do this?
Yes, that's the idea. It the texture's orientation isn't correct, either swap u/v or rotate your texture. Anyway, the basic idea is to normalize the height, i.e. for each vertex calculate the normalized height by (height-min)/(max-min). Use the result as either u or v (depending on your texture's orientation) on that particular vertex. Do that for all vertices.

AceGIS

#22
Hi Egon,

I have normalized the height values (correctly? snippet below) to values between 0 - 1. How do I set the texture using these values? I understand the u/v as texture coords but how do I assign values from the single texture?


for (Object3D obj : models) {
PolygonManager objPolyManager = obj.getPolygonManager();
Logger.log("Max poly ID " + obj.getName() + ": " + objPolyManager.getMaxPolygonID());

// for each polygon set texture according to vertex elevation
for (int i = 0; i < objPolyManager.getMaxPolygonID(); i++) {
Logger.log("Poly num: " + i);

for (int j = 0; j < 3; j++) {
SimpleVector height = objPolyManager.getTransformedVertex(i, j);
float tempMin = (float) 2.7523;
float tempMax = (float) 555.413025;
float normHeight = (height.z - tempMin)/(tempMax - tempMin);

Logger.log("Normalised vertex height #: " + j + " - " + normHeight);
}


Thank you for your help with this task. I will endeavour to repay you some way, some day...

EgonOlsen

#23
You can use the PolygonManager to assign new texture coordinates. You already know how to access the single vertices to extract the height. You can then use this normalized height to create a new TextureInfo per polygon and assign it.

AceGIS

Thanks Egon. Perfect!

I now have a scaled color applied to my terrain.  :D

Now I need to fix my onPause and onResume from my master activity... :P

[attachment deleted by admin]