Hello, i want to convert plane surface ShaderTerrainMesh to sphere with use mercator projection
in python i use math library for convert all 2d point for my map like this :
import math
def y2lat(a):
return 180.0/math.pi*(2.0*math.atan(math.exp(a*math.pi/180.0))-math.pi/2.0)
def lat2y(a):
return 180.0/math.pi*math.log(math.tan(math.pi/4.0+a*(math.pi/180.0)/2.0))
firstpoint_x=y2lat(0)
firstpoint_y=lat2y(0)
print(firstpoint_x)
print(firstpoint_y)
but for use ShaderTerrainMesh, i think that i must modify glsl file.
My question is, how modify coordinate of point in glsl code for apply mercator projection
my glsl file :
#version 150
// This is the terrain fragment shader. There is a lot of code in here
// which is not necessary to render the terrain, but included for convenience -
// Like generating normals from the heightmap or a simple fog effect.
// Most of the time you want to adjust this shader to get your terrain the look
// you want. The vertex shader most likely will stay the same.
// ADDED TEXTUR SPLATTING!
in vec2 terrain_uv;
in vec3 vtx_pos;
out vec4 color;
int count = 0;
uniform struct {
sampler2D data_texture;
sampler2D heightfield;
int view_index;
int terrain_size;
int chunk_size;
} ShaderTerrainMesh;
uniform sampler2D detail_tex1;
uniform sampler2D detail_tex2;
uniform sampler2D detail_tex3;
uniform sampler2D detail_tex4;
uniform sampler2D attribute_tex;
uniform vec3 wspos_camera;
// Compute normal from the heightmap, this assumes the terrain is facing z-up
vec3 get_terrain_normal() {
const float terrain_height = 50.0;
vec3 pixel_size = vec3(1.0, -1.0, 0) / textureSize(ShaderTerrainMesh.heightfield, 0).xxx;
float u0 = texture(ShaderTerrainMesh.heightfield, terrain_uv + pixel_size.yz).x * terrain_height;
float u1 = texture(ShaderTerrainMesh.heightfield, terrain_uv + pixel_size.xz).x * terrain_height;
float v0 = texture(ShaderTerrainMesh.heightfield, terrain_uv + pixel_size.zy).x * terrain_height;
float v1 = texture(ShaderTerrainMesh.heightfield, terrain_uv + pixel_size.zx).x * terrain_height;
vec3 tangent = normalize(vec3(1.0, 0, u1 - u0));
vec3 binormal = normalize(vec3(0, 1.0, v1 - v0));
return normalize(cross(tangent, binormal));
}
void main() {
vec3 diffuse = texture(detail_tex1, terrain_uv * 16.0).rgb * texture(attribute_tex, terrain_uv).r;
diffuse += texture(detail_tex2, terrain_uv * 16.0).rgb * texture(attribute_tex, terrain_uv).g;
diffuse += texture(detail_tex3, terrain_uv * 16.0).rgb * texture(attribute_tex, terrain_uv).b;
diffuse += texture(detail_tex4, terrain_uv * 16.0).rgb * texture(attribute_tex, terrain_uv).a;
vec3 normal = get_terrain_normal();
// Add some fake lighting - you usually want to use your own lighting code here
vec3 fake_sun = normalize(vec3(0.7, 0.2, 0.6));
vec3 shading = max(0.0, dot(normal, fake_sun)) * diffuse;
shading += vec3(0.07, 0.07, 0.1);
// Fake fog
/*float dist = distance(vtx_pos, wspos_camera);
float fog_factor = smoothstep(0, 1, dist / 1000.0);
shading = mix(shading, vec3(0.7, 0.7, 0.8), fog_factor);*/
color = vec4(shading, 1.0);
}
for get height of point i add this code in main function :
float height = texture(ShaderTerrainMesh.heightfield, terrain_uv).x;
but how get and modify x,y and z coordinate ? for apply mercator projection
thanks for advance for your help
for mercator convertion, i think use this implementation :