Add Normal in vertex. And add light in shader.
This commit is contained in:
parent
8908ef1332
commit
0e96615b32
16 changed files with 221 additions and 85 deletions
|
|
@ -22,6 +22,7 @@ namespace Map3DRendering {
|
|||
private bool _firstMove = true;
|
||||
|
||||
private Vector2 _lastPos;
|
||||
private Vector3 _lightPosVec;
|
||||
|
||||
private double _time;
|
||||
|
||||
|
|
@ -44,6 +45,10 @@ namespace Map3DRendering {
|
|||
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
|
||||
int maxTextureUnits;
|
||||
GL.GetInteger(GetPName.MaxTextureImageUnits, out maxTextureUnits);
|
||||
Console.WriteLine($"Maximum number of texture units for fragment shaders: {maxTextureUnits}");
|
||||
|
||||
_shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag");
|
||||
_shader.Use();
|
||||
|
||||
|
|
@ -58,6 +63,7 @@ namespace Map3DRendering {
|
|||
//CursorState = CursorState.Grabbed;
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
|
||||
_lightPosVec = Vector3.UnitY * 1000;
|
||||
}
|
||||
|
||||
protected override void OnRenderFrame(FrameEventArgs e) {
|
||||
|
|
@ -73,10 +79,10 @@ namespace Map3DRendering {
|
|||
_shader.SetMatrix4("view", _camera.GetViewMatrix());
|
||||
_shader.SetMatrix4("projection", _camera.GetProjectionMatrix());
|
||||
|
||||
/*_shader.SetVector3("objectColor", new Vector3(0.5f, 0.5f, 0.5f));
|
||||
//_shader.SetVector3("objectColor", new Vector3(0.5f, 0.5f, 0.5f));
|
||||
_shader.SetVector3("lightColor", new Vector3(1.0f, 1.0f, 1.0f));
|
||||
_shader.SetVector3("lightPos", _camera.Position);
|
||||
_shader.SetVector3("viewPos", _camera.Position);*/
|
||||
_shader.SetVector3("lightPos", _lightPosVec);
|
||||
//_shader.SetVector3("viewPos", _camera.Position);
|
||||
|
||||
GL.LineWidth(5.0f);
|
||||
|
||||
|
|
@ -103,6 +109,23 @@ namespace Map3DRendering {
|
|||
Close();
|
||||
}
|
||||
|
||||
// Vitesse de déplacement de la lumière
|
||||
float lightSpeed = 300.0f; // Ajustez cette valeur selon les besoins
|
||||
|
||||
// Mise à jour de la position de la lumière en fonction des entrées utilisateur
|
||||
if (input.IsKeyDown(Keys.Down)) {
|
||||
_lightPosVec += Vector3.UnitX * lightSpeed * (float)e.Time; // Déplace la lumière vers le bas
|
||||
}
|
||||
if (input.IsKeyDown(Keys.Up)) {
|
||||
_lightPosVec -= Vector3.UnitX * lightSpeed * (float)e.Time; // Déplace la lumière vers le haut
|
||||
}
|
||||
if (input.IsKeyDown(Keys.Left)) {
|
||||
_lightPosVec -= Vector3.UnitZ * lightSpeed * (float)e.Time; // Déplace la lumière vers la gauche
|
||||
}
|
||||
if (input.IsKeyDown(Keys.Right)) {
|
||||
_lightPosVec += Vector3.UnitZ * lightSpeed * (float)e.Time; // Déplace la lumière vers la droite
|
||||
}
|
||||
|
||||
const float sensitivity = 0.2f;
|
||||
|
||||
if (input.IsKeyDown(Keys.W)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue