Browse Source

updated gl3d and adding 3d settings

meemknight 2 years ago
parent
commit
81c76c2957

+ 98 - 0
Pika/core/pikaSTD/engineLibraresSupport/engineGL3DSupport.cpp

@@ -64,3 +64,101 @@ bool defaultFileExistsCustom(const char *fileName, void *userData)
 	return data->getFileSizeBinary(fileName, s);
 }
 
+void pika::gl3d::generalSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer)
+{
+	ImGui::PushID(imguiId);
+	//ImGui::SliderFloat("Gama Corections", &gamaCorection, 1, 3);
+	ImGui::SliderFloat("Exposure", &renderer.internal.lightShader.lightPassUniformBlockCpuData.exposure, 0.1, 10);
+
+	auto normalMap = renderer.isNormalMappingEnabeled();
+	ImGui::Checkbox("Normal map", &normalMap);
+	renderer.enableNormalMapping(normalMap);
+
+	static bool lightSubScater = renderer.isLightSubScatteringEnabeled();
+	ImGui::Checkbox("Light sub scater", &lightSubScater);
+	renderer.enableLightSubScattering(lightSubScater);
+
+	ImGui::Checkbox("Adaptive resolution", &renderer.adaptiveResolution.useAdaptiveResolution);
+	ImGui::Text("Adaptive rez ratio: %.1f", renderer.adaptiveResolution.rezRatio);
+	//ImGui::Checkbox("Z pre pass", &renderer.zPrePass);
+	ImGui::Checkbox("Frustum culling", &renderer.frustumCulling);
+	
+	ImGui::PopID();
+}
+
+void pika::gl3d::fxaaSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer)
+{
+	ImGui::PushID(imguiId);
+
+	ImGui::Checkbox("FXAA", &renderer.antiAlias.usingFXAA);
+
+	auto &fxaaData = renderer.getFxaaSettings();
+
+	ImGui::DragFloat("edgeDarkTreshold", &fxaaData.edgeDarkTreshold, 0.001, 0, 1);
+	ImGui::DragFloat("edgeMinTreshold", &fxaaData.edgeMinTreshold, 0.001, 0, 1);
+	ImGui::DragFloat("quaityMultiplier", &fxaaData.quaityMultiplier, 0.001, 0, 1);
+	ImGui::DragInt("ITERATIONS", &fxaaData.ITERATIONS, 1, 1, 32);
+	ImGui::DragFloat("SUBPIXEL_QUALITY", &fxaaData.SUBPIXEL_QUALITY, 0.001, 0, 1);
+
+	ImGui::PopID();
+}
+
+void pika::gl3d::ssaoSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer)
+{
+	ImGui::PushID(imguiId);
+
+	ImGui::Checkbox("SSAO", &renderer.internal.lightShader.useSSAO);
+	ImGui::SliderFloat("SSAO bias", &renderer.internal.ssao.ssaoShaderUniformBlockData.bias, 0, 0.5);
+	ImGui::SliderFloat("SSAO radius", &renderer.internal.ssao.ssaoShaderUniformBlockData.radius, 0, 2);
+	ImGui::SliderInt("SSAO sample count", &renderer.internal.ssao.ssaoShaderUniformBlockData.samplesTestSize, 0, 64);
+	ImGui::SliderFloat("SSAO exponent", &renderer.internal.ssao.ssao_finalColor_exponent, 0, 16);
+
+	ImGui::PopID();
+}
+
+void pika::gl3d::ssrSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer)
+{
+	ImGui::PushID(imguiId);
+
+	ImGui::Checkbox("SSR", &renderer.internal.hasLastFrameTexture);
+	auto d = renderer.getSSRdata();
+
+	ImGui::SliderFloat("max ray delta", &d.maxRayDelta, 0.0001f, 2.f); //for clamping infinity
+	ImGui::SliderFloat("max ray step", &d.maxRayStep, 0.01f, 5.f);
+	ImGui::SliderInt("max steps", &d.maxSteps, 5, 150);
+	ImGui::SliderFloat("min ray step", &d.minRayStep, 0.001f, 1.f);
+	ImGui::SliderInt("binary search steps", &d.numBinarySearchSteps, 2, 20);
+
+	renderer.setSSRdata(d);
+
+	ImGui::PopID();
+}
+
+void pika::gl3d::bloomSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer)
+{
+	ImGui::PushID(imguiId);
+
+	ImGui::Checkbox("Bloom", &renderer.bloom());
+	ImGui::DragFloat("Bloom tresshold", &renderer.internal.lightShader.lightPassUniformBlockCpuData.bloomTresshold,
+		0.01, 0, 1);
+	ImGui::DragFloat("Bloom intensity", &renderer.postProcess.bloomIntensty, 0.01, 0, 10);
+	ImGui::Checkbox("High quality down sample", &renderer.bloomHighQualityDownSample());
+	ImGui::Checkbox("High quality up sample", &renderer.bloomHighQualityUpSample());
+
+	ImGui::PopID();
+}
+
+void pika::gl3d::chromaticAberationSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer)
+{
+	ImGui::PushID(imguiId);
+
+	ImGui::Checkbox("Chromatic aberation", &renderer.chromaticAberationEnabeled());
+
+	ImGui::DragFloat("Chromatic aberation strength", &renderer.postProcess.chromaticAberationStrength,
+		1, 0, 200);
+
+	ImGui::DragFloat("Chromatic aberation defocus", &renderer.postProcess.unfocusDistance,
+		0.01, 0, 100);
+
+	ImGui::PopID();
+}

+ 28 - 0
Pika/core/pikaSTD/engineLibraresSupport/engineGL3DSupport.h

@@ -8,3 +8,31 @@ void errorCallbackCustom(std::string err, void *userData);
 std::string readEntireFileCustom(const char *fileName, bool &couldNotOpen, void *userData);
 std::vector<char> readEntireFileBinaryCustom(const char *fileName, bool &couldNotOpen, void *userData);
 bool defaultFileExistsCustom(const char *fileName, void *userData);
+
+
+
+#if PIKA_SHOULD_REMOVE_IMGUI == 0
+
+#endif
+
+#include <pikaImgui/pikaImgui.h>
+
+namespace pika
+{
+	namespace gl3d
+	{
+		void generalSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer);
+
+		void fxaaSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer);
+
+		void ssaoSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer);
+
+		void ssrSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer);
+
+		void bloomSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer);
+
+		void chromaticAberationSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer);
+
+	};
+};
+

BIN
Pika/engineResources/engineSaves/options1.bin


BIN
Pika/engineResources/engineSaves/options2.bin


BIN
Pika/engineResources/engineSaves/window1.bin


BIN
Pika/engineResources/engineSaves/window2.bin


BIN
Pika/engineResources/engineSaves/windowPos1.bin


BIN
Pika/engineResources/engineSaves/windowPos2.bin


BIN
Pika/engineResources/test2.recording


BIN
Pika/engineResources/test2.snapshot


+ 4 - 4
Pika/gameplay/containers/pikaGameplay.h

@@ -64,10 +64,10 @@ struct Gameplay : public Container
 
 		glClear(GL_COLOR_BUFFER_BIT);
 
-		if (pika::shortcut(input, "Ctrl + S"))
-		{
-			requestedInfo.consoleWrite("save\n");
-		}
+		//if (pika::shortcut(input, "Ctrl + S"))
+		//{
+		//	requestedInfo.consoleWrite("save\n");
+		//}
 		
 		//if (input.buttons[pika::Button::S].released())
 		//{

+ 97 - 24
Pika/pluggins/pluggins/threeDEditor.h

@@ -14,7 +14,6 @@ struct ThreeDEditor: public Container
 {
 
 
-
 	//todo user can request imgui ids; shortcut manager context; allocators
 	static ContainerStaticInfo containerInfo()
 	{
@@ -22,7 +21,7 @@ struct ThreeDEditor: public Container
 		info.defaultHeapMemorySize = pika::MB(1000); //todo option to use global allocator
 
 		info.requestImguiFbo = true;
-		info.requestImguiIds = 1;
+		info.requestImguiIds = 100;
 
 		return info;
 	}
@@ -59,7 +58,7 @@ struct ThreeDEditor: public Container
 		//renderer.skyBox.color = {0.2,0.3,0.8};
 		
 		//helmetModel = renderer.loadModel(PIKA_RESOURCES_PATH "helmet/helmet.obj");
-		model = renderer.loadModel(PIKA_RESOURCES_PATH "/knight/uploads_files_1950170_Solus_the_knight.gltf");
+		model = renderer.loadModel(PIKA_RESOURCES_PATH "rave.glb", 0.5);
 		
 		gl3d::Transform t;
 		t.position = {0, -1, -4};
@@ -80,40 +79,114 @@ struct ThreeDEditor: public Container
 		renderer.fileOpener.readEntireFileBinaryCallback = readEntireFileBinaryCustom;
 		renderer.fileOpener.readEntireFileCallback = readEntireFileCustom;
 		renderer.fileOpener.fileExistsCallback = defaultFileExistsCustom;
-		
-		
+
+
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 		glEnable(GL_DEPTH_TEST);
-		
+
 		renderer.updateWindowMetrics(windowState.w, windowState.h);
 		renderer.camera.aspectRatio = (float)windowState.w / windowState.h; //todo do this in update
-		
+
+		if(ImGui::Begin("Settings"))
 		{
-			static glm::dvec2 lastMousePos = {};
-			if (input.rMouse.held())
-			{
-				glm::dvec2 currentMousePos = {input.mouseX, input.mouseY};
-		
-				float speed = 0.8f;
-		
-				glm::vec2 delta = lastMousePos - currentMousePos;
-				delta *= speed * input.deltaTime;
 		
-				renderer.camera.rotateCamera(delta);
-		
-				lastMousePos = currentMousePos;
+			if (ImGui::CollapsingHeader("Basic settings", ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding))
+			{
+				pika::gl3d::generalSettingsWindow(requestedInfo.requestedImguiIds, renderer);
 			}
-			else
+
+			if (ImGui::CollapsingHeader("fxaa settings", ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding))
 			{
-				lastMousePos = {input.mouseX, input.mouseY};
+				pika::gl3d::fxaaSettingsWindow(requestedInfo.requestedImguiIds, renderer);
 			}
+
+			if (ImGui::CollapsingHeader("ssao settings", ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding))
+			{
+				pika::gl3d::ssaoSettingsWindow(requestedInfo.requestedImguiIds, renderer);
+			}
+
+			if (ImGui::CollapsingHeader("ssr settings", ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding))
+			{
+				pika::gl3d::ssrSettingsWindow(requestedInfo.requestedImguiIds, renderer);
+			}
+
+			if (ImGui::CollapsingHeader("bloom settings", ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding))
+			{
+				pika::gl3d::bloomSettingsWindow(requestedInfo.requestedImguiIds, renderer);
+			}
+
+			if (ImGui::CollapsingHeader("chromatic aberation settings", ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding))
+			{
+				pika::gl3d::chromaticAberationSettingsWindow(requestedInfo.requestedImguiIds, renderer);
+			}
+			
 		}
-		
+		ImGui::End();
 
 
-		renderer.setEntityAnimate(entity, true);
+	#pragma region input
+
+	{
+		float speed = 4;
+		glm::vec3 dir = {};
+		if (GetAsyncKeyState('W'))
+		{
+			dir.z -= speed * input.deltaTime;
+		}
+		if (GetAsyncKeyState('S'))
+		{
+			dir.z += speed * input.deltaTime;
+		}
+
+		if (GetAsyncKeyState('A'))
+		{
+			dir.x -= speed * input.deltaTime;
+		}
+		if (GetAsyncKeyState('D'))
+		{
+			dir.x += speed * input.deltaTime;
+		}
+
+		if (GetAsyncKeyState('Q'))
+		{
+			dir.y -= speed * input.deltaTime;
+		}
+		if (GetAsyncKeyState('E'))
+		{
+			dir.y += speed * input.deltaTime;
+		}
+
+		renderer.camera.moveFPS(dir);
+	}
+
+	{
+		static glm::dvec2 lastMousePos = {};
+		if (input.rMouse.held())
+		{
+			glm::dvec2 currentMousePos = {input.mouseX, input.mouseY};
+
+			float speed = 0.8f;
+
+			glm::vec2 delta = lastMousePos - currentMousePos;
+			delta *= speed * input.deltaTime;
+
+			renderer.camera.rotateCamera(delta);
+
+			lastMousePos = currentMousePos;
+		}
+		else
+		{
+			lastMousePos = {input.mouseX, input.mouseY};
+		}
+	}
+
+	#pragma endregion
+
+		if (input.buttons[pika::Button::P].pressed())
+		{
+			renderer.setEntityAnimate(entity, true);
+		}
 
-		
 		renderer.render(input.deltaTime);
 		glDisable(GL_DEPTH_TEST);
 

+ 4 - 5
Pika/resources/logs.txt

@@ -1,5 +1,4 @@
-#2023-01-27 17:41:05: Created container: Gameplay
-#2023-01-27 17:44:20: Destroyed continer: Gameplay #1
-#2023-01-27 17:44:30: Created container: ThreeDEditor
-#2023-01-27 17:46:24: Reloaded dll
-#2023-01-27 17:46:36: Destroyed continer: ThreeDEditor #2
+#2023-02-13 13:46:53: Created container: Gameplay
+#2023-02-13 13:47:09: Created container: ThreeDEditor
+#2023-02-13 13:48:27: Destroyed continer: Gameplay #1
+#2023-02-13 13:48:27: Destroyed continer: ThreeDEditor #2

BIN
Pika/resources/mario/map1.mario


BIN
Pika/resources/rave.glb


File diff suppressed because it is too large
+ 530 - 187
Pika/thirdparty/gl3d/gl3d.cpp


+ 60 - 40
Pika/thirdparty/gl3d/gl3d.h

@@ -1,6 +1,6 @@
 ////////////////////////////////////////////////
 //gl32 --Vlad Luta -- 
-//built on 2023-01-23
+//built on 2023-02-13
 ////////////////////////////////////////////////
 
 
@@ -33963,7 +33963,6 @@ namespace gl3d
 
 		GLint light_u_normals = -1;
 		GLint light_u_skyboxFiltered = -1;
-		GLint light_u_positions = -1;
 		GLint light_u_eyePosition = -1;
 		GLint light_u_pointLightCount = -1;
 		GLint light_u_directionalLightCount = -1;
@@ -33976,8 +33975,13 @@ namespace gl3d
 		GLint light_u_materialIndex = -1;
 		GLint light_u_textureUV = -1;
 		GLint light_u_textureDerivates = -1;
+		GLint light_u_lastTexture = -1;
+		GLint light_u_positionViewSpace = -1;
 		GLint light_u_transparentPass = -1;
-
+		GLint light_u_hasLastFrameTexture = -1;
+		GLint light_u_cameraProjection = -1;
+		GLint light_u_view = -1;
+		GLint light_u_inverseView = -1;
 		
 		GLint light_materialBlockLocation = GL_INVALID_INDEX;
 
@@ -34025,6 +34029,27 @@ namespace gl3d
 			float exposure = 1.7;
 			int skyBoxPresent = 0;
 
+			struct SSRdata
+			{
+				float minRayStep = 0.4;
+				int maxSteps = 20;
+				int	numBinarySearchSteps = 7;
+				float maxRayStep = 1.75;
+				float maxRayDelta = 0.6;
+
+				void setLowQuality()
+				{ *this = SSRdata(); };
+
+				void setMediumQuality()
+				{
+					minRayStep = 0.4;
+					maxSteps = 40;
+					numBinarySearchSteps = 5;
+					maxRayStep = 1.2;
+					maxRayDelta = 0.6;
+				};
+
+			}SSR;
 		}lightPassUniformBlockCpuData;
 
 		struct
@@ -34062,7 +34087,7 @@ namespace gl3d
 
 		GpuTexture brdfTexture;
 
-		//todo clear
+		void clear();
 	};
 
 
@@ -34288,6 +34313,7 @@ namespace gl3d
 		std::vector < char* > subModelsNames; //for imgui
 		std::vector <Material> createdMaterials;
 		void clear(Renderer3D &renderer);
+		void internalClear();
 
 		std::vector<gl3d::Animation> animations;
 		std::vector<gl3d::Joint> joints;
@@ -34304,7 +34330,7 @@ namespace gl3d
 		Transform transform;
 
 		std::vector < GraphicModel >models;
-		std::vector < char* > subModelsNames; //for imgui
+		std::vector < char* > subModelsNames; //for imgui 
 		void clear();
 
 		void allocateGpuData();
@@ -34440,6 +34466,7 @@ namespace gl3d
 		void drawBefore(const glm::mat4 &viewProjMat, SkyBox &skyBox, float exposure,
 			glm::vec3 ambient);
 
+		void clear();
 	};
 
 	/*
@@ -34786,12 +34813,18 @@ namespace gl3d
 		void setBloomIntensisy(float b);
 		bool &bloomHighQualityDownSample();
 		bool &bloomHighQualityUpSample();
+		
+		//SSR
+		LightShader::LightPassData::SSRdata &getSSRdata();
+		void setSSRdata(LightShader::LightPassData::SSRdata data);
+		void ebableSSR(bool enable = true);
+		bool isSSRenabeled();
 
 		//
 		float &getDirectionalShadowCascadesFrustumSplit(int cascadeIndex);
 
 		//chromatic aberation
-		bool &chromaticAberation();
+		bool &chromaticAberationEnabeled();
 		//in pixels
 		float getChromaticAberationStrength();
 		//in pixels
@@ -34828,16 +34861,6 @@ namespace gl3d
 
 	#pragma endregion
 			
-		//todo export settings; import settings
-		//todo clear all
-
-		//todo move remove?
-		struct VAO
-		{
-			//this is not used yet
-			GLuint posNormalTexture;
-			void createVAOs();
-		}vao;
 
 		Camera camera;
 		SkyBox skyBox;
@@ -34870,6 +34893,8 @@ namespace gl3d
 				GLuint createRMAtexture(
 					GpuTexture roughness, GpuTexture metallic, GpuTexture ambientOcclusion, 
 					GLuint quadVAO, int &RMA_loadedTextures, GLuint frameBuffer);
+				
+				void clear();
 
 			}pBRtextureMaker;
 
@@ -34952,6 +34977,8 @@ namespace gl3d
 				void create(int w, int h, ErrorReporter &errorReporter, FileOpener &fileOpener, GLuint frameBuffer);
 				void resize(int w, int h);
 
+				void clear();
+
 				glm::ivec2 currentDimensions = {};
 
 				GLuint noiseTexture;
@@ -34976,11 +35003,6 @@ namespace gl3d
 				GLint u_texNoise = -1;
 				GLint u_samples = -1;
 				GLuint u_SSAODATA;
-				GLint u_depthBuffer = -1;
-				GLint u_aspectRatio = -1;
-				GLint u_tanHalfFOV = -1;
-				GLint u_farPlane = -1;
-				GLint u_closePlane = -1;
 
 
 				std::vector<glm::vec3> ssaoKernel;
@@ -34998,6 +35020,7 @@ namespace gl3d
 				//https://developer.download.nvidia.com/presentations/2008/SIGGRAPH/HBAO_SIG08b.pdf
 
 				void create(ErrorReporter &errorReporter, FileOpener &fileOpener, GLuint frameBuffer);
+				void clear();
 				Shader shader;
 
 				GLint u_projection = -1;
@@ -35013,10 +35036,11 @@ namespace gl3d
 				void create(int w, int h, ErrorReporter &errorReporter, GLuint frameBuffer);
 				void resize(int w, int h);
 
+				void clear();
+
 				enum bufferTargers
 				{
-					position = 0,
-					normal,
+					normal = 0,
 					textureDerivates,
 					//albedo,
 					//material,
@@ -35037,11 +35061,10 @@ namespace gl3d
 			}gBuffer;
 
 			#pragma endregion
-			
 
+			bool hasLastFrameTexture = 1;
 
 		}internal;
-
 		
 
 		struct PostProcess
@@ -35109,10 +35132,11 @@ namespace gl3d
 			GLuint filterFbo;
 			GLuint blurFbo[2];
 
-			GLuint colorBuffers[2]; // 0 for color, 1 for bloom
+			GLuint colorBuffers[3]; // 0 for color, 1 for bloom, 2 last frame
 			GLuint bluredColorBuffer[2];
 			void create(int w, int h, ErrorReporter &errorReporter, FileOpener &fileOpener, GLuint frameBuffer);
 			void resize(int w, int h);
+			void clear();
 			glm::ivec2 currentDimensions = {};
 			int currentMips = 1;
 
@@ -35133,6 +35157,7 @@ namespace gl3d
 		{
 			void create(int w, int h);
 			void resize(int w, int h);
+			void clear();
 
 			static constexpr int timeSamplesCount = 20;
 			float msSampled[timeSamplesCount] = {};
@@ -35160,6 +35185,7 @@ namespace gl3d
 			Shader shader;
 			Shader noAAshader;
 			void create(int w, int h, ErrorReporter &errorReporter, FileOpener &fileOpener);
+			void clear();
 
 			GLuint u_texture;
 			GLuint noAAu_texture;
@@ -35175,6 +35201,7 @@ namespace gl3d
 		{
 			void create(GLuint frameBuffer);
 			void allocateTextures(int count);
+			void clear();
 
 			constexpr static int CASCADES = 3;
 
@@ -35196,6 +35223,7 @@ namespace gl3d
 		{
 			void create(GLuint frameBuffer);
 			void allocateTextures(int count);
+			void clear();
 			int textureCount = 0;
 
 			GLuint shadowTextures;
@@ -35212,6 +35240,7 @@ namespace gl3d
 		{
 			void create(GLuint frameBuffer);
 			void allocateTextures(int count);
+			void clear();
 			int textureCount = 0;
 
 			int shadowSize = 1024;
@@ -35225,23 +35254,14 @@ namespace gl3d
 
 		}pointShadows;
 
-		//todo remove or implement properly
-		struct RenderDepthMap
-		{
-			void create(ErrorReporter &errorReporter, FileOpener &fileOpener, GLuint frameBuffer);
-
-			Shader shader;
-			GLint u_depth = -1;
-
-			GLuint fbo;
-			GLuint texture;
-
-		}renderDepthMap;
-		void renderADepthMap(GLuint texture, GLuint frameBuffer);
-
 		void render(float deltaTime);
 		void updateWindowMetrics(int x, int y);
 
+		void clearAllLoadedResource();
+
+		//only cleares the current skybox!, other user created skyboxes won't be cleared
+		void clearAllRendererResources();
+
 		bool frustumCulling = 1;
 		bool zPrePass = 0;
 

Some files were not shown because too many files changed in this diff