From 7fc9a5e5d60feeb755cab552ea582fe0b9fa99a0 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Sun, 9 Jun 2024 21:42:23 +0300 Subject: [PATCH] light working --- Template/log.txt | 222 ++++++++++--------- Template/main.cpp | 64 +++++- Template/main.h | 1 + resources/shaders/directlight2.fragment | 46 ++++ resources/shaders/directlight2.vertex | 26 +++ resources/shaders/directlight3.fragment | 47 ++++ resources/shaders/directlight3.vertex | 26 +++ resources/shaders/env_reverse_night.fragment | 21 ++ resources/shaders/env_reverse_night.vertex | 14 ++ 9 files changed, 356 insertions(+), 111 deletions(-) create mode 100644 resources/shaders/directlight2.fragment create mode 100644 resources/shaders/directlight2.vertex create mode 100644 resources/shaders/directlight3.fragment create mode 100644 resources/shaders/directlight3.vertex create mode 100644 resources/shaders/env_reverse_night.fragment create mode 100644 resources/shaders/env_reverse_night.vertex diff --git a/Template/log.txt b/Template/log.txt index 0902d25..ac980c0 100644 --- a/Template/log.txt +++ b/Template/log.txt @@ -1,139 +1,159 @@ -2024-Jun-09 10:36:12: Log started -2024-Jun-09 10:36:13: OpenGL Window created -2024-Jun-09 10:36:13: Script manager ready -2024-Jun-09 10:36:13: Render::OpenGL glVersion = 4.6.0 - Build 31.0.101.4887 -2024-Jun-09 10:36:13: Render::OpenGL glVersion above 2.0 ok -2024-Jun-09 10:36:13: Render::OpenGL GL_ARB_framebuffer_object supported ok -2024-Jun-09 10:36:13: Render::OpenGL GL_ARB_uniform_buffer_object supported ok -2024-Jun-09 10:36:13: Prepare to add shader GUI -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: Log started +2024-Jun-09 21:40:20: OpenGL Window created +2024-Jun-09 21:40:20: Script manager ready +2024-Jun-09 21:40:20: Render::OpenGL glVersion = 4.6.0 - Build 31.0.101.4887 +2024-Jun-09 21:40:20: Render::OpenGL glVersion above 2.0 ok +2024-Jun-09 21:40:20: Render::OpenGL GL_ARB_framebuffer_object supported ok +2024-Jun-09 21:40:20: Render::OpenGL GL_ARB_uniform_buffer_object supported ok +2024-Jun-09 21:40:20: Prepare to add shader GUI +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: Shader program is - 3 -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader -2024-Jun-09 10:36:13: ResourceManager::ShaderManager shader loaded: GUI -2024-Jun-09 10:36:13: Prepare to add shader Parallax -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: Shader program is - 3 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: GUI +2024-Jun-09 21:40:20: Prepare to add shader Parallax +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing WARNING: 0:27: 'assign' : implicit type conversion allowed from GLSL 1.20 WARNING: 0:27: 'assign' : implicit type conversion allowed from GLSL 1.20 WARNING: 0:27: 'assign' : implicit type conversion allowed -2024-Jun-09 10:36:13: Shader program is - 6 -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader -2024-Jun-09 10:36:13: ResourceManager::ShaderManager shader loaded: Parallax -2024-Jun-09 10:36:13: Prepare to add shader Directlight -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: Shader program is - 6 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: Parallax +2024-Jun-09 21:40:20: Prepare to add shader Directlight +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: Shader program is - 9 -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader -2024-Jun-09 10:36:13: ResourceManager::ShaderManager shader loaded: Directlight -2024-Jun-09 10:36:13: Prepare to add shader Env -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: Shader program is - 9 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: Directlight +2024-Jun-09 21:40:20: Prepare to add shader Directlight2 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: Shader program is - 12 -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader -2024-Jun-09 10:36:13: ResourceManager::ShaderManager shader loaded: Env -2024-Jun-09 10:36:13: Prepare to add shader EnvReverse -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: Shader program is - 12 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: Directlight2 +2024-Jun-09 21:40:20: Prepare to add shader Env +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: Shader program is - 15 -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader -2024-Jun-09 10:36:13: ResourceManager::ShaderManager shader loaded: EnvReverse -2024-Jun-09 10:36:13: Prepare to add shader Water -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: Shader program is - 15 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: Env +2024-Jun-09 21:40:20: Prepare to add shader EnvReverse +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing + + +2024-Jun-09 21:40:20: Shader program is - 18 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: EnvReverse +2024-Jun-09 21:40:20: Prepare to add shader EnvReverseNight +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing + + +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing + + +2024-Jun-09 21:40:20: Shader program is - 21 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: EnvReverseNight +2024-Jun-09 21:40:20: Prepare to add shader Water +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing + + +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing WARNING: 0:29: 'assign' : implicit type conversion allowed from GLSL 1.20 -2024-Jun-09 10:36:13: Shader program is - 18 -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader -2024-Jun-09 10:36:13: ResourceManager::ShaderManager shader loaded: Water -2024-Jun-09 10:36:13: Prepare to add shader Frame -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: Shader program is - 24 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: Water +2024-Jun-09 21:40:20: Prepare to add shader Frame +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: Shader program is - 21 -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader -2024-Jun-09 10:36:13: ResourceManager::ShaderManager shader loaded: Frame -2024-Jun-09 10:36:13: Prepare to add shader Lightview -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:5: '' : #version directive missing +2024-Jun-09 21:40:20: Shader program is - 27 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: Frame +2024-Jun-09 21:40:20: Prepare to add shader Lightview +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:5: '' : #version directive missing -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: Shader program is - 24 -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader -2024-Jun-09 10:36:13: ResourceManager::ShaderManager shader loaded: Lightview -2024-Jun-09 10:36:13: Prepare to add shader Simple3D -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: Shader program is - 30 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: Lightview +2024-Jun-09 21:40:20: Prepare to add shader Simple3D +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-09 10:36:13: Shader program is - 27 -2024-Jun-09 10:36:13: ResourceManager::ShaderManager::Shader -2024-Jun-09 10:36:13: ResourceManager::ShaderManager shader loaded: Simple3D -2024-Jun-09 10:36:13: ResourceManager::TexList Texture added: bt_box_yellow.bmp with id = 1 -2024-Jun-09 10:36:13: ResourceManager::TexList Texture added: bt_box_norm.bmp32 with id = 2 -2024-Jun-09 10:36:13: Lite model added successfully: models/bt_box_yellow.lm1 -2024-Jun-09 10:36:13: ResourceManager::TexList Texture added: bt_box_red000.bmp with id = 3 -2024-Jun-09 10:36:13: ResourceManager::TexList Texture reference added: bt_box_norm.bmp32 -2024-Jun-09 10:36:13: Lite model added successfully: models/bt_box_red.lm1 -2024-Jun-09 10:36:13: ResourceManager::TexList Texture added: bt_box_blue00.bmp with id = 4 -2024-Jun-09 10:36:13: ResourceManager::TexList Texture reference added: bt_box_norm.bmp32 -2024-Jun-09 10:36:13: Lite model added successfully: models/bt_box_blue.lm1 -2024-Jun-09 10:36:13: ResourceManager::TexList Texture added: bt_cone.bmp with id = 5 -2024-Jun-09 10:36:13: Lite model added successfully: models/bt_cone.lm1 -2024-Jun-09 10:36:13: Lite model added successfully: models/girl.lm1 -2024-Jun-09 10:36:14: Lite model added successfully: models/bonemodel.lm1 -2024-Jun-09 10:36:16: ResourceManager::TexList Texture added: out.bmp with id = 6 -2024-Jun-09 10:36:16: FrameManager:: frame buffer added: Skybox -2024-Jun-09 10:36:16: ResourceManager::TexList Texture added: normalmap.bmp with id = 8 -2024-Jun-09 10:36:16: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/posx.bmp -2024-Jun-09 10:36:16: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/negx.bmp -2024-Jun-09 10:36:17: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/posy.bmp -2024-Jun-09 10:36:17: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/negy.bmp -2024-Jun-09 10:36:17: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/posz.bmp -2024-Jun-09 10:36:17: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/negz.bmp -2024-Jun-09 10:36:17: ResourceManager::TexList texture added succesfuly: posx.bmp -2024-Jun-09 10:36:17: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_rt.bmp -2024-Jun-09 10:36:17: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_lf.bmp -2024-Jun-09 10:36:17: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_dn.bmp -2024-Jun-09 10:36:17: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_up.bmp -2024-Jun-09 10:36:18: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_bk.bmp -2024-Jun-09 10:36:18: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_ft.bmp -2024-Jun-09 10:36:18: ResourceManager::TexList texture added succesfuly: yavin_rt.bmp -2024-Jun-09 10:36:18: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_rt.bmp -2024-Jun-09 10:36:18: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_lf.bmp -2024-Jun-09 10:36:19: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_up.bmp -2024-Jun-09 10:36:19: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_dn.bmp -2024-Jun-09 10:36:19: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_bk.bmp -2024-Jun-09 10:36:19: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_ft.bmp -2024-Jun-09 10:36:20: ResourceManager::TexList texture added succesfuly: space_rt.bmp -2024-Jun-09 10:36:20: FrameManager:: frame buffer added: ScreenBlur -2024-Jun-09 10:36:20: FrameManager:: frame buffer added: ShadowBufferGlobal -2024-Jun-09 10:36:20: FrameManager:: frame buffer added: ShadowBufferLocal +2024-Jun-09 21:40:20: Shader program is - 33 +2024-Jun-09 21:40:20: ResourceManager::ShaderManager::Shader +2024-Jun-09 21:40:20: ResourceManager::ShaderManager shader loaded: Simple3D +2024-Jun-09 21:40:20: ResourceManager::TexList Texture added: bt_box_yellow.bmp with id = 1 +2024-Jun-09 21:40:20: ResourceManager::TexList Texture added: bt_box_norm.bmp32 with id = 2 +2024-Jun-09 21:40:20: Lite model added successfully: models/bt_box_yellow.lm1 +2024-Jun-09 21:40:20: ResourceManager::TexList Texture added: bt_box_red000.bmp with id = 3 +2024-Jun-09 21:40:20: ResourceManager::TexList Texture reference added: bt_box_norm.bmp32 +2024-Jun-09 21:40:20: Lite model added successfully: models/bt_box_red.lm1 +2024-Jun-09 21:40:20: ResourceManager::TexList Texture added: bt_box_blue00.bmp with id = 4 +2024-Jun-09 21:40:20: ResourceManager::TexList Texture reference added: bt_box_norm.bmp32 +2024-Jun-09 21:40:20: Lite model added successfully: models/bt_box_blue.lm1 +2024-Jun-09 21:40:20: ResourceManager::TexList Texture added: bt_cone.bmp with id = 5 +2024-Jun-09 21:40:20: Lite model added successfully: models/bt_cone.lm1 +2024-Jun-09 21:40:20: Lite model added successfully: models/girl.lm1 +2024-Jun-09 21:40:20: Lite model added successfully: models/bonemodel.lm1 +2024-Jun-09 21:40:21: ResourceManager::TexList Texture added: out.bmp with id = 6 +2024-Jun-09 21:40:21: FrameManager:: frame buffer added: Skybox +2024-Jun-09 21:40:21: ResourceManager::TexList Texture added: normalmap.bmp with id = 8 +2024-Jun-09 21:40:21: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/posx.bmp +2024-Jun-09 21:40:21: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/negx.bmp +2024-Jun-09 21:40:21: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/posy.bmp +2024-Jun-09 21:40:21: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/negy.bmp +2024-Jun-09 21:40:21: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/posz.bmp +2024-Jun-09 21:40:21: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/negz.bmp +2024-Jun-09 21:40:21: ResourceManager::TexList texture added succesfuly: posx.bmp +2024-Jun-09 21:40:21: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_rt.bmp +2024-Jun-09 21:40:22: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_lf.bmp +2024-Jun-09 21:40:22: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_dn.bmp +2024-Jun-09 21:40:22: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_up.bmp +2024-Jun-09 21:40:22: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_bk.bmp +2024-Jun-09 21:40:22: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/yavin_ft.bmp +2024-Jun-09 21:40:22: ResourceManager::TexList texture added succesfuly: yavin_rt.bmp +2024-Jun-09 21:40:22: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_rt.bmp +2024-Jun-09 21:40:22: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_lf.bmp +2024-Jun-09 21:40:22: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_up.bmp +2024-Jun-09 21:40:22: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_dn.bmp +2024-Jun-09 21:40:23: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_bk.bmp +2024-Jun-09 21:40:23: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/sky/space_ft.bmp +2024-Jun-09 21:40:23: ResourceManager::TexList texture added succesfuly: space_rt.bmp +2024-Jun-09 21:40:23: FrameManager:: frame buffer added: ScreenBlur +2024-Jun-09 21:40:23: FrameManager:: frame buffer added: ShadowBufferGlobal +2024-Jun-09 21:40:23: FrameManager:: frame buffer added: ShadowBufferLocal diff --git a/Template/main.cpp b/Template/main.cpp index d058b14..7fb4b32 100644 --- a/Template/main.cpp +++ b/Template/main.cpp @@ -14,53 +14,68 @@ void TMyApplication::DrawToCubemap() Renderer->SwitchToCubemapBuffer("Skybox",0); Renderer->SetGlPosXView(false, true); - DrawCubemapDay(); + //DrawCubemapDay(); + DrawCubemapNight(); + Renderer->PushShader("Directlight2"); Renderer->SetGlPosXView(true, true); GameMap.DrawVBO(); + Renderer->PopShader(); //glClearColor() //glClearColor(1.0f, 0.0f, 0.0f, 1.0f); //glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); Renderer->SwitchToCubemapBuffer("Skybox",1); Renderer->SetGlNegXView(false, true); - DrawCubemapDay(); + //DrawCubemapDay(); + DrawCubemapNight(); + Renderer->PushShader("Directlight2"); Renderer->SetGlNegXView(true, true); //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); GameMap.DrawVBO(); + Renderer->PopShader(); Renderer->SwitchToCubemapBuffer("Skybox",2); Renderer->SetGlPosYView(false, true); - DrawCubemapDay(); + //DrawCubemapDay(); + DrawCubemapNight(); + Renderer->PushShader("Directlight2"); Renderer->SetGlPosYView(true, true); GameMap.DrawVBO(); //glClearColor(0.0f, 1.0f, 0.0f, 1.0f); //glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - + Renderer->PopShader(); Renderer->SwitchToCubemapBuffer("Skybox",3); Renderer->SetGlNegYView(false, true); - DrawCubemapDay(); + //DrawCubemapDay(); + DrawCubemapNight(); + Renderer->PushShader("Directlight2"); Renderer->SetGlNegYView(true, true); //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); GameMap.DrawVBO(); - + Renderer->PopShader(); Renderer->SwitchToCubemapBuffer("Skybox",4); Renderer->SetGlPosZView(false, true); - DrawCubemapDay(); + //DrawCubemapDay(); + DrawCubemapNight(); + Renderer->PushShader("Directlight2"); Renderer->SetGlPosZView(true, true); GameMap.DrawVBO(); //glClearColor(0.0f, 0.0f, 1.0f, 1.0f); //glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - + Renderer->PopShader(); Renderer->SwitchToCubemapBuffer("Skybox",5); Renderer->SetGlNegZView(false, true); - DrawCubemapDay(); + //DrawCubemapDay(); + DrawCubemapNight(); + Renderer->PushShader("Directlight2"); Renderer->SetGlNegZView(true, true); //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); GameMap.DrawVBO(); + Renderer->PopShader(); Renderer->SwitchToScreen(); @@ -84,9 +99,12 @@ void TMyApplication::DrawToShadowMap() void TMyApplication::DrawSceneWithoutWater() { Renderer->SetGLCamAngleView(); - DrawCubemapDay(); + //DrawCubemapDay(); + DrawCubemapNight(); + Renderer->PushShader("Directlight2"); Renderer->SetGLCamView(); GameMap.DrawVBO(); + Renderer->PopShader(); } void TMyApplication::DrawWaterSurface() @@ -160,6 +178,30 @@ void TMyApplication::DrawCubemapDay() Renderer->PopShader(); } + +void TMyApplication::DrawCubemapNight() +{ + Renderer->PushShader("EnvReverseNight"); + //Renderer->SetGLCamAngleView(); + //Renderer->SetGLCamAngleView(); + //Renderer->LoadIdentity(); + RenderUniformMatrix3fv(CONST_STRING_MODELROTATEMATRIX_UNIFORM, false, (float*)IdentityMatrix.m); + RenderUniform3fv(CONST_STRING_MODELTRANSLATEVECTOR_UNIFORM, (float*)ZeroVec3.v); + + //glBindTexture(GL_TEXTURE_CUBE_MAP, ResourceManager->FrameManager.GetFrameTexture("Skybox")); + glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTextureNight); + + EnableVertexAttribArray("vPosition"); + + DrawVertexDataStruct(cubemapVertexDataStruct); + + DisableVertexAttribArray("vPosition"); + + glClear(GL_DEPTH_BUFFER_BIT); + + Renderer->PopShader(); +} + void TMyApplication::DrawFrameFullScreen() { @@ -176,8 +218,10 @@ void TMyApplication::InnerInit() ResourceManager->ShaderManager.AddShader("GUI", "shaders/gui_transparent.vertex", "shaders/gui_transparent.fragment"); ResourceManager->ShaderManager.AddShader("Parallax", "shaders/directlight_parallax_shadow.vertex", "shaders/directlight_parallax_shadow.fragment"); ResourceManager->ShaderManager.AddShader("Directlight", "shaders/directlight.vertex", "shaders/directlight.fragment"); + ResourceManager->ShaderManager.AddShader("Directlight2", "shaders/directlight2.vertex", "shaders/directlight2.fragment"); ResourceManager->ShaderManager.AddShader("Env", "shaders/env.vertex", "shaders/env.fragment"); ResourceManager->ShaderManager.AddShader("EnvReverse", "shaders/env_reverse.vertex", "shaders/env_reverse.fragment"); + ResourceManager->ShaderManager.AddShader("EnvReverseNight", "shaders/env_reverse_night.vertex", "shaders/env_reverse_night.fragment"); ResourceManager->ShaderManager.AddShader("Water", "shaders/water.vertex", "shaders/water.fragment"); ResourceManager->ShaderManager.AddShader("Frame", "shaders/frame.vertex", "shaders/frame.fragment"); ResourceManager->ShaderManager.AddShader("Lightview", "shaders/lightview.vertex", "shaders/lightview.fragment"); diff --git a/Template/main.h b/Template/main.h index 5de0798..1bd2ee9 100644 --- a/Template/main.h +++ b/Template/main.h @@ -40,6 +40,7 @@ class TMyApplication : public SE::TApplication void DrawCubemap(); void DrawCubemapDay(); + void DrawCubemapNight(); void DrawFrameFullScreen(); diff --git a/resources/shaders/directlight2.fragment b/resources/shaders/directlight2.fragment new file mode 100644 index 0000000..f20b8cf --- /dev/null +++ b/resources/shaders/directlight2.fragment @@ -0,0 +1,46 @@ +uniform sampler2D Texture; +uniform float FogBeginDistance; +uniform float FogEndDistance; + +varying vec2 texCoord; +varying vec3 vertexPos; +varying vec3 normal; +varying vec3 absoluteVertexPos; + +void main() +{ + //vec3 norm = normalize(normal)*0.5 + vec3(0.5, 0.5, 0.5); + //gl_FragColor = vec4(norm, 1.0); + + vec3 norm = normalize(normal); + + vec3 lightPos = vec3(-2, 5, 0); + + vec3 lightVec = absoluteVertexPos - lightPos; + + float coef = max(dot(-normalize(lightVec),norm),0.2); + + float coef2 = clamp((15.0 - length(lightVec))/10.0, 0.2, 1.0); + + vec4 texColor = texture2D(Texture,texCoord).rgba; + + gl_FragColor = vec4(texColor.rgb*coef2*coef, 1.0); + + + + /* + //Night + //vec4 fogColor = vec4(0.25, 0.55, 1.0, 1.0); + vec4 fogColor = vec4(0.05, 0.05, 0.1, 1.0); + + + + float fogDistCoef = (vertexPos.z - FogBeginDistance) / (FogEndDistance - FogBeginDistance); + + fogDistCoef = clamp(fogDistCoef, 0.0, 1.0); + + vec4 resultColor = mix(texColor*coef2, fogColor, fogDistCoef); + + gl_FragColor = vec4(resultColor.rgb, 1.0);*/ + +} \ No newline at end of file diff --git a/resources/shaders/directlight2.vertex b/resources/shaders/directlight2.vertex new file mode 100644 index 0000000..35fea4d --- /dev/null +++ b/resources/shaders/directlight2.vertex @@ -0,0 +1,26 @@ +attribute vec3 vPosition; +attribute vec2 vTexCoord; +attribute vec3 vNormal; + +uniform mat4 ProjectionMatrix; +uniform mat3 ModelRotateMatrix; +uniform vec3 ModelTranslateVector; + +varying vec2 texCoord; +varying vec3 vertexPos; +varying vec3 absoluteVertexPos; +varying vec3 normal; + +void main() +{ + vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0); + gl_Position = ProjectionMatrix * realVertexPos; + vertexPos = gl_Position.xyz; + + absoluteVertexPos = vPosition; + + texCoord = vTexCoord.st; + + normal = vNormal; + +} \ No newline at end of file diff --git a/resources/shaders/directlight3.fragment b/resources/shaders/directlight3.fragment new file mode 100644 index 0000000..94e25e7 --- /dev/null +++ b/resources/shaders/directlight3.fragment @@ -0,0 +1,47 @@ +uniform sampler2D Texture; +uniform sampler2D NormalMap; +uniform float FogBeginDistance; +uniform float FogEndDistance; + +varying vec2 texCoord; +varying vec3 vertexPos; +varying vec3 normal; +varying vec3 absoluteVertexPos; + +void main() +{ + //vec3 norm = normalize(normal)*0.5 + vec3(0.5, 0.5, 0.5); + //gl_FragColor = vec4(norm, 1.0); + + vec3 norm = normalize(normal); + + vec3 lightPos = vec3(-2, 5, 0); + + vec3 lightVec = absoluteVertexPos - lightPos; + + float coef = max(dot(-normalize(lightVec),norm),0.2); + + float coef2 = clamp((15.0 - length(lightVec))/10.0, 0.2, 1.0); + + vec4 texColor = texture2D(NormalMap,texCoord).rgba; + + gl_FragColor = vec4(texColor.rgb*coef2*coef, 1.0); + + + + /* + //Night + //vec4 fogColor = vec4(0.25, 0.55, 1.0, 1.0); + vec4 fogColor = vec4(0.05, 0.05, 0.1, 1.0); + + + + float fogDistCoef = (vertexPos.z - FogBeginDistance) / (FogEndDistance - FogBeginDistance); + + fogDistCoef = clamp(fogDistCoef, 0.0, 1.0); + + vec4 resultColor = mix(texColor*coef2, fogColor, fogDistCoef); + + gl_FragColor = vec4(resultColor.rgb, 1.0);*/ + +} \ No newline at end of file diff --git a/resources/shaders/directlight3.vertex b/resources/shaders/directlight3.vertex new file mode 100644 index 0000000..35fea4d --- /dev/null +++ b/resources/shaders/directlight3.vertex @@ -0,0 +1,26 @@ +attribute vec3 vPosition; +attribute vec2 vTexCoord; +attribute vec3 vNormal; + +uniform mat4 ProjectionMatrix; +uniform mat3 ModelRotateMatrix; +uniform vec3 ModelTranslateVector; + +varying vec2 texCoord; +varying vec3 vertexPos; +varying vec3 absoluteVertexPos; +varying vec3 normal; + +void main() +{ + vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0); + gl_Position = ProjectionMatrix * realVertexPos; + vertexPos = gl_Position.xyz; + + absoluteVertexPos = vPosition; + + texCoord = vTexCoord.st; + + normal = vNormal; + +} \ No newline at end of file diff --git a/resources/shaders/env_reverse_night.fragment b/resources/shaders/env_reverse_night.fragment new file mode 100644 index 0000000..0703ce6 --- /dev/null +++ b/resources/shaders/env_reverse_night.fragment @@ -0,0 +1,21 @@ +uniform samplerCube Env; + +varying vec3 dir; + +void main(){ + gl_FragColor = textureCube(Env, normalize(dir)); + + vec4 fogColor = vec4(0.05, 0.05, 0.1, 1.0); + + float coef = dir.y+1.0; + coef = clamp(coef, 0.0, 1.0); + + gl_FragColor = mix(gl_FragColor,fogColor, coef); + + //if (dir.z < 0) + //{ + // gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); + //} + //gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); + +} \ No newline at end of file diff --git a/resources/shaders/env_reverse_night.vertex b/resources/shaders/env_reverse_night.vertex new file mode 100644 index 0000000..d4a4d03 --- /dev/null +++ b/resources/shaders/env_reverse_night.vertex @@ -0,0 +1,14 @@ +attribute vec3 vPosition; + +uniform mat4 ProjectionMatrix; +uniform mat3 ModelRotateMatrix; +uniform vec3 ModelTranslateVector; + +varying vec3 dir; + +void main(){ + vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0); + gl_Position = ProjectionMatrix * realVertexPos; + + dir = -vPosition; +} \ No newline at end of file