init
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#version 460
|
||||
/*
|
||||
* Copyright 2023 Nintendo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
layout (binding = 2) uniform sampler2D samplerHeight;
|
||||
layout (binding = 3) uniform sampler2DArray samplerLayers;
|
||||
|
||||
layout (location = 0) out vec4 outColor;
|
||||
|
||||
layout (location = 0) in TerrainVertexData {
|
||||
vec2 uv;
|
||||
vec3 pos;
|
||||
vec3 normal;
|
||||
} vertex_in;
|
||||
|
||||
vec3 sampleTerrainLayer()
|
||||
{
|
||||
// Define some layer ranges for sampling depending on terrain height
|
||||
vec2 layers[6];
|
||||
layers[0] = vec2(-10.0, 10.0);
|
||||
layers[1] = vec2(5.0, 45.0);
|
||||
layers[2] = vec2(45.0, 80.0);
|
||||
layers[3] = vec2(75.0, 100.0);
|
||||
layers[4] = vec2(95.0, 150.0);
|
||||
layers[5] = vec2(140.0, 290.0);
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
// Get height from displacement map
|
||||
float height = 255.0f - vertex_in.pos.y;//textureLod(samplerHeight, vertex_in.uv, 0.0).r * 255.0;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
float range = layers[i].y - layers[i].x;
|
||||
float weight = (range - abs(height - layers[i].y)) / range;
|
||||
weight = max(0.0, weight);
|
||||
color += weight * texture(samplerLayers, vec3(vertex_in.uv * 16.0, i)).rgb;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
float fog(float density)
|
||||
{
|
||||
const float LOG2 = -1.442695;
|
||||
float dist = gl_FragCoord.z / gl_FragCoord.w * 0.1;
|
||||
float d = density * dist;
|
||||
return 1.0 - clamp(exp2(d * d * LOG2), 0.0, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 N = normalize(vertex_in.normal);
|
||||
vec3 L = normalize(vec3(0,-1,1));
|
||||
vec3 ambient = vec3(0.5);
|
||||
vec3 diffuse = max(dot(N, L), 0.0) * vec3(1.0);
|
||||
|
||||
vec4 color = vec4((ambient + diffuse) * sampleTerrainLayer(), 1.0);
|
||||
|
||||
const vec4 fogColor = vec4(0.47, 0.5, 0.67, 0.0);
|
||||
outColor = mix(color, fogColor, fog(0.25));
|
||||
}
|
||||
Reference in New Issue
Block a user