Success to blend 4 texture
Need improuve for angle.
This commit is contained in:
parent
b9a2b87fe9
commit
664eb5872a
8 changed files with 186 additions and 105 deletions
|
|
@ -70,7 +70,7 @@ namespace Map3DRendering {
|
|||
}
|
||||
}
|
||||
private void InitializeBlock(int x, int y, BlockStruct block, Shader _shader) {
|
||||
int lenghPacket = 13;
|
||||
int lenghPacket = 18;
|
||||
// Initialisez le VAO, VBO et EBO pour le bloc à (x, y)...
|
||||
// Utilisez le code de votre méthode OnLoad originale pour configurer le VAO, VBO et EBO.
|
||||
int tempVertexArray = GL.GenVertexArray();
|
||||
|
|
@ -104,6 +104,14 @@ namespace Map3DRendering {
|
|||
var texturecoordLocation = _shader.GetAttribLocation("aTexCoord");
|
||||
GL.EnableVertexAttribArray(texturecoordLocation);
|
||||
GL.VertexAttribPointer(texturecoordLocation, 2, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 11 * sizeof(float));
|
||||
|
||||
var terraintypeLocation = _shader.GetAttribLocation("aTexType");
|
||||
GL.EnableVertexAttribArray(terraintypeLocation);
|
||||
GL.VertexAttribPointer(terraintypeLocation, 4, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 13 * sizeof(float));
|
||||
|
||||
var realterraintypeLocation = _shader.GetAttribLocation("aRealTexType");
|
||||
GL.EnableVertexAttribArray(realterraintypeLocation);
|
||||
GL.VertexAttribPointer(realterraintypeLocation, 1, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 13 * sizeof(float));
|
||||
}
|
||||
public void Render(Shader shader) {
|
||||
for (int y = startY; y <= endY; y++) {
|
||||
|
|
|
|||
|
|
@ -8,12 +8,26 @@ uniform sampler2D texture0;
|
|||
in vec4 FarColor;
|
||||
in vec3 FragPos;
|
||||
in vec2 TexCoord;
|
||||
in vec4 TexType;
|
||||
in float RealType;
|
||||
|
||||
void main()
|
||||
{
|
||||
float tileSize = 64.0 / 512.0;
|
||||
|
||||
vec2 uvOffsets[4];
|
||||
uvOffsets[0] = vec2(mod(TexType.x, 8.0), floor(TexType.x / 8.0)) * tileSize;
|
||||
uvOffsets[1] = vec2(mod(TexType.y, 8.0), floor(TexType.y / 8.0)) * tileSize;
|
||||
uvOffsets[2] = vec2(mod(TexType.z, 8.0), floor(TexType.z / 8.0)) * tileSize;
|
||||
uvOffsets[3] = vec2(mod(TexType.w, 8.0), floor(TexType.w / 8.0)) * tileSize;
|
||||
|
||||
vec4 blendedColor = vec4(0.0);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
vec2 uv = TexCoord * tileSize + uvOffsets[i];
|
||||
blendedColor += texture(texture0, uv) * 0.25;
|
||||
}
|
||||
|
||||
float distance = length(viewPos - FragPos);
|
||||
float interpolationFactor = clamp(distance / 1000.0, 0.0, 1.0);
|
||||
|
||||
vec4 textureColor = texture(texture0, TexCoord);
|
||||
outputColor = mix(textureColor, FarColor, interpolationFactor);
|
||||
outputColor = mix(blendedColor, FarColor, interpolationFactor);
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@ layout (location = 0) in vec3 aPos;
|
|||
layout (location = 1) in vec4 aColor;
|
||||
layout (location = 2) in vec4 aColorFar;
|
||||
layout (location = 3) in vec2 aTexCoord;
|
||||
layout (location = 4) in vec4 aTexType;
|
||||
layout (location = 5) in float aRealTexType;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
|
|
@ -12,6 +14,8 @@ out vec3 FragPos;
|
|||
out vec4 Color;
|
||||
out vec4 FarColor;
|
||||
out vec2 TexCoord;
|
||||
out vec4 TexType;
|
||||
out float RealType;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
@ -20,4 +24,6 @@ void main()
|
|||
Color = aColor;
|
||||
FarColor = aColorFar;
|
||||
TexCoord = aTexCoord;
|
||||
TexType = aTexType;
|
||||
RealType = aRealTexType;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue