diff --git a/metadrive/engine/core/light.py b/metadrive/engine/core/light.py index d1a42c762..ab2658409 100644 --- a/metadrive/engine/core/light.py +++ b/metadrive/engine/core/light.py @@ -8,7 +8,7 @@ class Light(BaseObject): """ It is dynamic element since it will follow the camera """ - direction_pos = (-100, 100, 120) + direction_pos = (-100, 100, 100) def __init__(self): super(Light, self).__init__(random_seed=0) diff --git a/metadrive/engine/core/terrain.py b/metadrive/engine/core/terrain.py index 748ec76f5..bc84f4422 100644 --- a/metadrive/engine/core/terrain.py +++ b/metadrive/engine/core/terrain.py @@ -389,7 +389,7 @@ def _load_mesh_terrain_textures(self, engine, anisotropic_degree=16, filter_type self.grass_rough = self.loader.loadTexture( AssetLoader.file_path("textures", "grass1", "GroundGrassGreen002_BUMP_1K.jpg") ) - self.grass_tex_ratio = 128.0 + self.grass_tex_ratio = 64.0 v_wrap = Texture.WMRepeat u_warp = Texture.WMMirror diff --git a/metadrive/shaders/terrain.frag.glsl b/metadrive/shaders/terrain.frag.glsl index 0dae14aef..40760e1f2 100644 --- a/metadrive/shaders/terrain.frag.glsl +++ b/metadrive/shaders/terrain.frag.glsl @@ -76,16 +76,10 @@ vec3 project(mat4 mvp, vec3 p) { } -vec3 get_color(vec3 diffuse, sampler2D normal_tex, sampler2D rough_tex, float tex_ratio, mat3 tbn){ -// float roughness = texture(rough_tex, terrain_uv * tex_ratio).r; - vec3 normal = normalize(texture(normal_tex, terrain_uv * tex_ratio).rgb*2.0-1.0) * p3d_NormalMatrix; -// normal = normalize(normal + (roughness - 0.5) * 2.0); - vec3 basecolor = diffuse.xyz; +vec3 get_normal(sampler2D normal_tex, sampler2D rough_tex, float tex_ratio, mat3 tbn){ + vec3 normal = texture(normal_tex, terrain_uv * tex_ratio).rgb*2.0-1.0; normal = normalize(tbn * normal); - vec3 light_dir = normalize(light_direction); - vec3 shading = max(0.0, dot(normal, light_dir)) * diffuse; - - return shading; + return normal; } void main() { @@ -104,31 +98,14 @@ void main() { vec3 tangent = normalize(vec3(1, 0, h_u1 - h_u0)); vec3 binormal = normalize(vec3(0, 1, h_v1 - h_v0)); vec3 terrain_normal = normalize(cross(tangent, binormal)); - vec3 normal = normalize(p3d_NormalMatrix * terrain_normal); - // normal.x *= -1; - - mat3 tbn = mat3(tangent, binormal, normal); - vec3 shading = vec3(0.0); + // tbn is calulated in world space + mat3 tbn = mat3(tangent, binormal, terrain_normal); - // Calculate the shading of each light in the scene - for (int i = 0; i < p3d_LightSource.length(); ++i) { - vec3 diff = p3d_LightSource[i].position.xyz - vtx_pos * p3d_LightSource[i].position.w; - vec3 light_vector = normalize(diff); - vec3 light_shading = clamp(dot(normal, light_vector), 0.0, 1.0) * p3d_LightSource[i].color; - // If PSSM is not used, use the shadowmap from the light - // This is deeply ineficient, it's only to be able to compare the rendered shadows - if (!use_pssm) { - vec4 projected = projecteds[i]; - // Apply a bias to remove some of the self-shadow acne - projected.z -= fixed_bias * 0.01 * projected.w; - light_shading *= textureProj(p3d_LightSource[i].shadowMap, projected); - } - shading += light_shading; - } - vec3 color_origin; + // get the color and terrain normal in world space + vec3 diffuse; + vec3 tex_normal_world; if ((attri.r > 0.01) && terrain_uv.x>r_min && terrain_uv.y > r_min && terrain_uv.x