Update for AtlasBuilder ok
Need to improuve duplicate vertex for mapping texture.
This commit is contained in:
parent
4777783ffb
commit
b9a2b87fe9
11 changed files with 160 additions and 33 deletions
|
|
@ -163,6 +163,10 @@ namespace Map3DRendering.Common {
|
|||
/// </summary>
|
||||
/// <param name="name">The name of the uniform</param>
|
||||
/// <param name="data">The data to set</param>
|
||||
public void SetVector2(string name, Vector2 data) {
|
||||
GL.UseProgram(Handle);
|
||||
GL.Uniform2(_uniformLocations[name], data);
|
||||
}
|
||||
public void SetVector3(string name, Vector3 data) {
|
||||
GL.UseProgram(Handle);
|
||||
GL.Uniform3(_uniformLocations[name], data);
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ namespace Map3DRendering {
|
|||
private PortalEngine portalEngine;
|
||||
private CellEngine cellEngine;
|
||||
private LandBlockExtrator landblockExtraction;
|
||||
private TerrainAtlasManager terrainAtlasManager;
|
||||
|
||||
private readonly int NumberLandBlocks = 255;
|
||||
private readonly int BlockSize = 17;
|
||||
private readonly int allBlocks = 255 * 17 * 255 * 17;
|
||||
private readonly int cellSize = 8;
|
||||
private readonly int radius = 0x10; // Rayon du voisinage
|
||||
private readonly int radius = 0x5; // Rayon du voisinage
|
||||
|
||||
public int[,] _vertexArrayObject;
|
||||
public int[,] _vertexBufferObject;
|
||||
|
|
@ -31,10 +31,6 @@ namespace Map3DRendering {
|
|||
public MapRender() {
|
||||
portalEngine = new PortalEngine();
|
||||
cellEngine = new CellEngine();
|
||||
|
||||
terrainAtlasManager = new(portalEngine);
|
||||
terrainAtlasManager.ExtractTexture();
|
||||
terrainAtlasManager.GenerateAtlas();
|
||||
|
||||
landblockExtraction = new(portalEngine, cellEngine);
|
||||
|
||||
|
|
@ -74,7 +70,7 @@ namespace Map3DRendering {
|
|||
}
|
||||
}
|
||||
private void InitializeBlock(int x, int y, BlockStruct block, Shader _shader) {
|
||||
int lenghPacket = 11;
|
||||
int lenghPacket = 13;
|
||||
// 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 +100,10 @@ namespace Map3DRendering {
|
|||
var farcolorLocation = _shader.GetAttribLocation("aColorFar");
|
||||
GL.EnableVertexAttribArray(farcolorLocation);
|
||||
GL.VertexAttribPointer(farcolorLocation, 4, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 7 * sizeof(float));
|
||||
|
||||
var texturecoordLocation = _shader.GetAttribLocation("aTexCoord");
|
||||
GL.EnableVertexAttribArray(texturecoordLocation);
|
||||
GL.VertexAttribPointer(texturecoordLocation, 2, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 11 * sizeof(float));
|
||||
}
|
||||
public void Render(Shader shader) {
|
||||
for (int y = startY; y <= endY; y++) {
|
||||
|
|
@ -112,7 +112,7 @@ namespace Map3DRendering {
|
|||
var model = Matrix4.Identity;//CreateTranslation(x * BlockSize, 0, y * BlockSize); // Ajustez selon votre système de coordonnées
|
||||
shader.SetMatrix4("model", model);
|
||||
GL.BindVertexArray(_vertexArrayObject[x, y]);
|
||||
GL.DrawElements(PrimitiveType.Lines, GetIndiceLenght(), DrawElementsType.UnsignedInt, 0);
|
||||
GL.DrawElements(PrimitiveType.Triangles, GetIndiceLenght(), DrawElementsType.UnsignedInt, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,17 @@
|
|||
out vec4 outputColor;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform sampler2D texture0;
|
||||
|
||||
in vec4 Color;
|
||||
in vec4 FarColor;
|
||||
in vec3 FragPos;
|
||||
in vec2 TexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
float distance = length(viewPos - FragPos);
|
||||
float interpolationFactor = clamp(distance / 1000, 0.0, 1.0);
|
||||
float interpolationFactor = clamp(distance / 1000.0, 0.0, 1.0);
|
||||
|
||||
outputColor = mix(Color, FarColor, interpolationFactor);
|
||||
vec4 textureColor = texture(texture0, TexCoord);
|
||||
outputColor = mix(textureColor, FarColor, interpolationFactor);
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec4 aColor;
|
||||
layout (location = 2) in vec4 aColorFar;
|
||||
layout (location = 3) in vec2 aTexCoord;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
|
|
@ -10,6 +11,7 @@ uniform mat4 projection;
|
|||
out vec3 FragPos;
|
||||
out vec4 Color;
|
||||
out vec4 FarColor;
|
||||
out vec2 TexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
@ -17,4 +19,5 @@ void main()
|
|||
FragPos = vec3(vec4(aPos, 1.0) * model);
|
||||
Color = aColor;
|
||||
FarColor = aColorFar;
|
||||
TexCoord = aTexCoord;
|
||||
}
|
||||
|
|
@ -48,14 +48,16 @@ namespace Map3DRendering {
|
|||
_shader.Use();
|
||||
|
||||
mapRender.OnLoad(_shader);
|
||||
//_texture = Texture.LoadFromFile("atlas.jpg");
|
||||
//_texture.Use(TextureUnit.Texture0);
|
||||
_texture = Texture.LoadFromFile("atlas.jpg");
|
||||
_texture.Use(TextureUnit.Texture0);
|
||||
|
||||
axesGizmo = new AxesGizmo();
|
||||
|
||||
_camera = new Camera(Vector3.UnitY * 300, Size.X / (float)Size.Y);
|
||||
_camera.Fov = 60;
|
||||
//CursorState = CursorState.Grabbed;
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
|
||||
}
|
||||
|
||||
protected override void OnRenderFrame(FrameEventArgs e) {
|
||||
|
|
@ -66,7 +68,7 @@ namespace Map3DRendering {
|
|||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
_shader.Use();
|
||||
//_texture.Use(TextureUnit.Texture0);
|
||||
_texture.Use(TextureUnit.Texture0);
|
||||
|
||||
_shader.SetMatrix4("view", _camera.GetViewMatrix());
|
||||
_shader.SetMatrix4("projection", _camera.GetProjectionMatrix());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue