Author Topic: Multiple textures on a terrain  (Read 14077 times)

Offline AceGIS

  • byte
  • *
  • Posts: 32
    • View Profile
Re: Multiple textures on a terrain
« Reply #15 on: September 06, 2012, 04:22:02 am »
Hi Egon,

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Multiple textures on a terrain
« Reply #16 on: September 06, 2012, 07:09:19 am »
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.

Offline AceGIS

  • byte
  • *
  • Posts: 32
    • View Profile
Re: Multiple textures on a terrain
« Reply #17 on: September 27, 2012, 11:34:48 pm »
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]

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Multiple textures on a terrain
« Reply #18 on: September 28, 2012, 09:49:15 am »
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.
« Last Edit: September 28, 2012, 09:52:46 am by K24A3 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Multiple textures on a terrain
« Reply #19 on: September 28, 2012, 08:34:44 pm »
...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.

Offline AceGIS

  • byte
  • *
  • Posts: 32
    • View Profile
Re: Multiple textures on a terrain
« Reply #20 on: October 02, 2012, 05:06:37 am »
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??
« Last Edit: October 02, 2012, 05:23:07 am by AceGIS »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Multiple textures on a terrain
« Reply #21 on: October 02, 2012, 08:11:35 pm »
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.

Offline AceGIS

  • byte
  • *
  • Posts: 32
    • View Profile
Re: Multiple textures on a terrain
« Reply #22 on: October 05, 2012, 03:43:42 am »
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?

Code: [Select]
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...
« Last Edit: October 05, 2012, 03:45:19 am by AceGIS »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Multiple textures on a terrain
« Reply #23 on: October 06, 2012, 10:03:05 am »
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.
« Last Edit: October 08, 2012, 12:24:33 pm by EgonOlsen »

Offline AceGIS

  • byte
  • *
  • Posts: 32
    • View Profile
Re: Multiple textures on a terrain
« Reply #24 on: October 08, 2012, 03:26:12 am »
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]