Update loc of Vertex.
This commit is contained in:
parent
bb723036c0
commit
4ea0101cf6
4 changed files with 55 additions and 27 deletions
|
|
@ -78,10 +78,9 @@ namespace LandblockExtraction.LandBlockExtractor {
|
||||||
private Vector3 GenerateVertexPosition(int landx, int landy, int x, int y, byte height) {
|
private Vector3 GenerateVertexPosition(int landx, int landy, int x, int y, byte height) {
|
||||||
int tmpx = (landx * BlockSize + y) * cellSize;
|
int tmpx = (landx * BlockSize + y) * cellSize;
|
||||||
int tmpy = (BlockSize * NumberLandBlocks * cellSize) - ((landy * BlockSize + x) * cellSize) - 1;
|
int tmpy = (BlockSize * NumberLandBlocks * cellSize) - ((landy * BlockSize + x) * cellSize) - 1;
|
||||||
var newX = (tmpx - (NumberLandBlocks * BlockSize * cellSize / 2));
|
var newX = (tmpx - (NumberLandBlocks * BlockSize * cellSize / 2)) - landx * cellSize;// (tmpx - (NumberLandBlocks * BlockSize * cellSize / 2));
|
||||||
var newY = (tmpy - ((NumberLandBlocks * BlockSize * cellSize) - (NumberLandBlocks * BlockSize * cellSize / 2) - 1));
|
var newY = (tmpy - ((NumberLandBlocks * BlockSize * cellSize) - (NumberLandBlocks * BlockSize * cellSize / 2) - 1)) + landy * cellSize; //(tmpy - ((NumberLandBlocks * BlockSize * cellSize) - (NumberLandBlocks * BlockSize * cellSize / 2) - 1));
|
||||||
|
return new Vector3(newX + 1020, portalEngine.landScapeDefs.landHeightTable[height], newY - 1020);
|
||||||
return new Vector3(newX, portalEngine.landScapeDefs.landHeightTable[height], newY);
|
|
||||||
}
|
}
|
||||||
private Vector4 GenerateVertexColor(uint cellInfo) {
|
private Vector4 GenerateVertexColor(uint cellInfo) {
|
||||||
var terrain = MathOperations.GetTerrainInCellInfo(cellInfo);
|
var terrain = MathOperations.GetTerrainInCellInfo(cellInfo);
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,43 @@ namespace Map3DRendering.Common {
|
||||||
|
|
||||||
return new Texture(handle);
|
return new Texture(handle);
|
||||||
}
|
}
|
||||||
|
public static Texture LoadFromArray(string[] paths) {
|
||||||
|
// Générer un identifiant de texture
|
||||||
|
int handle = GL.GenTexture();
|
||||||
|
|
||||||
|
// Activer la texture
|
||||||
|
GL.ActiveTexture(TextureUnit.Texture0);
|
||||||
|
GL.BindTexture(TextureTarget.Texture2DArray, handle);
|
||||||
|
|
||||||
|
// Ici, nous supposons que toutes les images ont les mêmes dimensions et le même format
|
||||||
|
// Charger la première image pour obtenir les dimensions
|
||||||
|
ImageResult firstImage = ImageResult.FromStream(File.OpenRead(paths[0]), ColorComponents.RedGreenBlueAlpha);
|
||||||
|
int width = firstImage.Width;
|
||||||
|
int height = firstImage.Height;
|
||||||
|
|
||||||
|
// Initialiser la texture 2D array sans lui passer de données pour l'instant
|
||||||
|
GL.TexImage3D(TextureTarget.Texture2DArray, 0, PixelInternalFormat.Rgba, width, height, paths.Length, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
|
||||||
|
|
||||||
|
// Charger chaque texture dans l'array
|
||||||
|
for (int i = 0; i < paths.Length; i++) {
|
||||||
|
using (Stream stream = File.OpenRead(paths[i])) {
|
||||||
|
ImageResult image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
|
||||||
|
GL.TexSubImage3D(TextureTarget.Texture2DArray, 0, 0, 0, i, width, height, 1, PixelFormat.Rgba, PixelType.UnsignedByte, image.Data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Paramètres de texture
|
||||||
|
GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
|
||||||
|
GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
||||||
|
GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
|
||||||
|
GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
|
||||||
|
|
||||||
|
// Générer des mipmaps pour la texture array
|
||||||
|
GL.GenerateMipmap(GenerateMipmapTarget.Texture2DArray);
|
||||||
|
|
||||||
|
return new Texture(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Texture(int glHandle) {
|
public Texture(int glHandle) {
|
||||||
Handle = glHandle;
|
Handle = glHandle;
|
||||||
|
|
@ -77,6 +114,11 @@ namespace Map3DRendering.Common {
|
||||||
GL.ActiveTexture(unit);
|
GL.ActiveTexture(unit);
|
||||||
GL.BindTexture(TextureTarget.Texture2D, Handle);
|
GL.BindTexture(TextureTarget.Texture2D, Handle);
|
||||||
}
|
}
|
||||||
|
public void UseArray(TextureUnit unit) {
|
||||||
|
GL.ActiveTexture(unit);
|
||||||
|
GL.BindTexture(TextureTarget.Texture2DArray, Handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Assign(int shader, int i) {
|
public void Assign(int shader, int i) {
|
||||||
int location = GL.GetUniformLocation(shader, "textures[" + i.ToString() + "]");
|
int location = GL.GetUniformLocation(shader, "textures[" + i.ToString() + "]");
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ out vec4 outputColor;
|
||||||
uniform vec3 viewPos;
|
uniform vec3 viewPos;
|
||||||
uniform vec3 lightPos;
|
uniform vec3 lightPos;
|
||||||
uniform vec3 lightColor;
|
uniform vec3 lightColor;
|
||||||
uniform sampler2D texture0;
|
uniform sampler2DArray texture0;
|
||||||
|
|
||||||
in vec4 FarColor;
|
in vec4 FarColor;
|
||||||
in vec3 Normal;
|
in vec3 Normal;
|
||||||
|
|
@ -16,25 +16,10 @@ in float RealType;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float tileSize = 64.0 / 512.0;
|
|
||||||
|
|
||||||
float baseWeight = 0.2;
|
|
||||||
float dominantWeight = 0.4;
|
|
||||||
|
|
||||||
vec4 weights = vec4(baseWeight);
|
|
||||||
vec2 uvOffsets[4];
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
float type = TexType[i];
|
|
||||||
uvOffsets[i] = vec2(mod(type, 8.0), floor(type / 8.0)) * tileSize;
|
|
||||||
if (type == RealType) {
|
|
||||||
weights[i] = dominantWeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 blendedColor[4];
|
vec4 blendedColor[4];
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
vec2 uv = TexCoord * tileSize + uvOffsets[i];
|
float type = TexType[i];
|
||||||
blendedColor[i] = texture(texture0, uv);
|
blendedColor[i] = texture(texture0, vec3(TexCoord, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
float weightX = TexCoord.x;
|
float weightX = TexCoord.x;
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,10 @@ namespace Map3DRendering {
|
||||||
_shader.Use();
|
_shader.Use();
|
||||||
|
|
||||||
mapRender.OnLoad(_shader);
|
mapRender.OnLoad(_shader);
|
||||||
_texture = Texture.LoadFromFile("atlas.jpg");
|
|
||||||
_texture.Use(TextureUnit.Texture0);
|
var file = Directory.EnumerateFiles(@"./terrains");
|
||||||
|
_texture = Texture.LoadFromArray(file.ToArray());
|
||||||
|
_texture.UseArray(TextureUnit.Texture0);
|
||||||
|
|
||||||
axesGizmo = new AxesGizmo();
|
axesGizmo = new AxesGizmo();
|
||||||
|
|
||||||
|
|
@ -74,7 +76,7 @@ namespace Map3DRendering {
|
||||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||||
|
|
||||||
_shader.Use();
|
_shader.Use();
|
||||||
_texture.Use(TextureUnit.Texture0);
|
_texture.UseArray(TextureUnit.Texture0);
|
||||||
|
|
||||||
_shader.SetMatrix4("view", _camera.GetViewMatrix());
|
_shader.SetMatrix4("view", _camera.GetViewMatrix());
|
||||||
_shader.SetMatrix4("projection", _camera.GetProjectionMatrix());
|
_shader.SetMatrix4("projection", _camera.GetProjectionMatrix());
|
||||||
|
|
@ -142,10 +144,10 @@ namespace Map3DRendering {
|
||||||
_camera.Position += _camera.Right * cameraSpeed * (float)e.Time; // Right
|
_camera.Position += _camera.Right * cameraSpeed * (float)e.Time; // Right
|
||||||
}
|
}
|
||||||
if (input.IsKeyDown(Keys.Space)) {
|
if (input.IsKeyDown(Keys.Space)) {
|
||||||
_camera.Position += _camera.Up * cameraSpeed * (float)e.Time; // Up
|
_camera.Position += Vector3.UnitY * cameraSpeed * (float)e.Time; // Up
|
||||||
}
|
}
|
||||||
if (input.IsKeyDown(Keys.LeftShift)) {
|
if (input.IsKeyDown(Keys.LeftShift)) {
|
||||||
_camera.Position -= _camera.Up * cameraSpeed * (float)e.Time; // Down
|
_camera.Position -= Vector3.UnitY * cameraSpeed * (float)e.Time; // Down
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the mouse state
|
// Get the mouse state
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue