Kaynağa Gözat

Albedo rendering in the deferred renderer working

BearishSun 10 yıl önce
ebeveyn
işleme
7b9fe8d212

+ 12 - 3
BansheeCore/Source/BsMaterialParam.cpp

@@ -66,6 +66,9 @@ namespace BansheeEngine
 	template<bool Core>
 	void TMaterialParamTexture<Core>::set(const TextureType& texture)
 	{
+		if (mParams == nullptr)
+			return;
+
 		for (auto& param : *mParams)
 			param.set(texture);
 	}
@@ -73,7 +76,7 @@ namespace BansheeEngine
 	template<bool Core>
 	typename TMaterialParamTexture<Core>::TextureType TMaterialParamTexture<Core>::get()
 	{
-		if (mParams->size() == 0)
+		if (mParams == nullptr || mParams->size() == 0)
 			return TextureType();
 
 		return (*mParams)[0].get(); // They should all have the same value
@@ -87,6 +90,9 @@ namespace BansheeEngine
 	template<bool Core>
 	void TMaterialParamLoadStoreTexture<Core>::set(const TextureType& texture, const TextureSurface& surface)
 	{
+		if (mParams == nullptr)
+			return;
+
 		for (auto& param : *mParams)
 			param.set(texture, surface);
 	}
@@ -94,7 +100,7 @@ namespace BansheeEngine
 	template<bool Core>
 	typename TMaterialParamLoadStoreTexture<Core>::TextureType TMaterialParamLoadStoreTexture<Core>::get()
 	{
-		if (mParams->size() == 0)
+		if (mParams == nullptr || mParams->size() == 0)
 			return TextureType();
 
 		return (*mParams)[0].get(); // They should all have the same value
@@ -108,6 +114,9 @@ namespace BansheeEngine
 	template<bool Core>
 	void TMaterialParamSampState<Core>::set(const SamplerType& sampState)
 	{
+		if (mParams == nullptr)
+			return;
+
 		for (auto& param : *mParams)
 			param.set(sampState);
 	}
@@ -115,7 +124,7 @@ namespace BansheeEngine
 	template<bool Core>
 	typename TMaterialParamSampState<Core>::SamplerType TMaterialParamSampState<Core>::get()
 	{
-		if (mParams->size() == 0)
+		if (mParams == nullptr || mParams->size() == 0)
 			return SamplerType();
 
 		return (*mParams)[0].get(); // They should all have the same value

+ 3 - 7
BansheeCore/Source/BsRendererUtility.cpp

@@ -152,7 +152,7 @@ namespace BansheeEngine
 		vertices[0] = Vector3((float)viewArea.x, (float)viewArea.y, 0.0f);
 		vertices[1] = Vector3((float)viewArea.x + (float)viewArea.width, (float)viewArea.y, 0.0f);
 		vertices[2] = Vector3((float)viewArea.x, (float)viewArea.y + (float)viewArea.height, 0.0f);
-		vertices[3] = Vector3((float)viewArea.x + (float)viewArea.width, (float)viewArea.y + (float)viewArea.width, 0.0f);
+		vertices[3] = Vector3((float)viewArea.x + (float)viewArea.width, (float)viewArea.y + (float)viewArea.height, 0.0f);
 
 		Vector2 uvs[4];
 		uvs[0] = Vector2(uv.x, uv.y);
@@ -176,11 +176,11 @@ namespace BansheeEngine
 
 		auto vecIter = meshData->getVec3DataIter(VES_POSITION);
 		for (UINT32 i = 0; i < 4; i++)
-			vecIter.setValue(vertices[i]);
+			vecIter.addValue(vertices[i]);
 
 		auto uvIter = meshData->getVec2DataIter(VES_TEXCOORD);
 		for (UINT32 i = 0; i < 4; i++)
-			uvIter.setValue(uvs[i]);
+			uvIter.addValue(uvs[i]);
 
 		auto indices = meshData->getIndices32();
 		indices[0] = 0;
@@ -191,10 +191,6 @@ namespace BansheeEngine
 		indices[5] = 2;
 
 		mFullScreenQuadMesh->writeSubresource(0, *meshData, true, false);
-
-		SPtr<VertexBufferCore> vb = mFullScreenQuadMesh->getVertexData()->getBuffer(0);
-		vb->writeData(0, sizeof(vertices), vertices, BufferWriteType::Discard);
-
 		draw(mFullScreenQuadMesh, mFullScreenQuadMesh->getProperties().getSubMesh());
 	}
 

+ 2 - 2
BansheeCore/Source/BsTexture.cpp

@@ -16,7 +16,7 @@ namespace BansheeEngine
 		mHwGamma(false), mMultisampleCount(0), mTextureType(TEX_TYPE_2D),
 		mFormat(PF_UNKNOWN), mUsage(TU_DEFAULT)
 	{
-		mFormat = TextureManager::instance().getNativeFormat(mTextureType, mFormat, mUsage, mHwGamma);
+
 	}
 
 	TextureProperties::TextureProperties(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
@@ -25,7 +25,7 @@ namespace BansheeEngine
 		mHwGamma(hwGamma), mMultisampleCount(multisampleCount), mTextureType(textureType),
 		mFormat(format), mUsage(usage)
 	{
-		mFormat = TextureManager::instance().getNativeFormat(mTextureType, mFormat, mUsage, mHwGamma);
+
 	}
 
 	bool TextureProperties::hasAlpha() const

+ 1 - 1
BansheeD3D11RenderAPI/Include/BsD3D11Texture.h

@@ -148,7 +148,7 @@ namespace BansheeEngine
 		/**
 		 * @brief	Creates an empty and uninitialized texture view object.
 		 */
-		TextureViewPtr createView(const SPtr<TextureCore>& texture, const TEXTURE_VIEW_DESC& desc);
+		TextureViewPtr createView(const SPtr<TextureCore>& texture, const TEXTURE_VIEW_DESC& desc) override;
 
 	protected:
 		ID3D11Texture1D* m1DTex;

+ 3 - 3
BansheeD3D11RenderAPI/Source/BsD3D11Texture.cpp

@@ -710,7 +710,7 @@ namespace BansheeEngine
 				desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
 				desc.Usage = D3D11_USAGE_STAGING;
 
-				device.getD3D11Device()->CreateTexture1D(&desc, NULL, (ID3D11Texture1D**)(&mStagingBuffer));
+				device.getD3D11Device()->CreateTexture1D(&desc, nullptr, (ID3D11Texture1D**)(&mStagingBuffer));
 			} 					
 			break;
 		case TEX_TYPE_2D:
@@ -724,7 +724,7 @@ namespace BansheeEngine
 				desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
 				desc.Usage = D3D11_USAGE_STAGING;
 
-				device.getD3D11Device()->CreateTexture2D(&desc, NULL, (ID3D11Texture2D**)(&mStagingBuffer));
+				device.getD3D11Device()->CreateTexture2D(&desc, nullptr, (ID3D11Texture2D**)(&mStagingBuffer));
 			}
 			break;
 		case TEX_TYPE_3D:
@@ -737,7 +737,7 @@ namespace BansheeEngine
 				desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
 				desc.Usage = D3D11_USAGE_STAGING;
 
-				device.getD3D11Device()->CreateTexture3D(&desc, NULL, (ID3D11Texture3D**)(&mStagingBuffer));
+				device.getD3D11Device()->CreateTexture3D(&desc, nullptr, (ID3D11Texture3D**)(&mStagingBuffer));
 			}
 			break;
 		}

+ 4 - 3
README.md

@@ -1,6 +1,6 @@
 # BansheeEngine
 
-A free & modern multi-platform game development toolkit. It aims to provide simple yet powerful environment for creating games and other graphical applications. A wide range of features are available, ranging from a math and utility library, to DirectX 11 and OpenGL render systems all the way to asset processing, fully featured editor and C# scripting.
+A modern open-source game development toolkit. It aims to provide simple yet powerful environment for creating games and other graphical applications. A wide range of features are available, ranging from a math and utility library, to DirectX 11 and OpenGL render systems all the way to asset processing, fully featured editor and C# scripting.
 
 Banshee aims to become a standard in game development by providing rock solid implementations of known and widely used techniques while also being flexible enough to implement constantly changing cutting edge techniques. Built from ground up to be a modern library using modern design principles - everything is modular, layered and decoupled as much as possible, making it easier to modify, replace or add functionality. Platform specific functionality is kept at a minimum making porting as easy as possible. Additionally every non-trivial method, class and field is documented.
 
@@ -65,7 +65,7 @@ To compile DirectX render systems you will also need a separately installed Dire
    
 * Core
   * Design
-    * Built using C++11 and modern design principles
+    * Built using C++14 and modern design principles
     * Clean layered design
     * Fully documented
     * Modular & plugin based
@@ -110,8 +110,9 @@ To compile DirectX render systems you will also need a separately installed Dire
     * CPU & GPU profiler
     * Virtual input
     * Advanced RTTI system
-    * Automatic object serialization/deserialization
+    * Native object serialization
     * Debug drawing
+	* Crash reporting
     * Utility library
       * Math, file system, events, thread pool, task scheduler, logging, memory allocators and more
     

+ 1 - 1
RenderBeast/Include/BsRenderBeastOptions.h

@@ -38,7 +38,7 @@ namespace BansheeEngine
 		 *			seriously increase fillrate and memory consumption on the GPU.
 		 */
 
-		UINT32 msaa = 4;
+		UINT32 msaa = 1;
 		/** 
 		 * All colors output from shaders will be automatically converted to gamma 
 		 * space when written to render target(s). Normally used when the renderer

+ 10 - 15
RenderBeast/Source/BsRenderBeast.cpp

@@ -541,18 +541,8 @@ namespace BansheeEngine
 
 			camData.gbuffer->bind();
 
-			UINT32 clearBuffers = 0;
-			if (viewport->getRequiresColorClear())
-				clearBuffers |= FBT_COLOR;
-
-			if (viewport->getRequiresDepthClear())
-				clearBuffers |= FBT_DEPTH;
-
-			if (viewport->getRequiresStencilClear())
-				clearBuffers |= FBT_STENCIL;
-
-			if (clearBuffers != 0)
-				RenderAPICore::instance().clearViewport(clearBuffers, viewport->getClearColor(), viewport->getClearDepthValue(), viewport->getClearStencilValue());
+			UINT32 clearBuffers = FBT_COLOR | FBT_DEPTH | FBT_STENCIL;
+			RenderAPICore::instance().clearViewport(clearBuffers, Color::ZERO, 0.0f, 0);
 
 			for (auto iter = opaqueElements.begin(); iter != opaqueElements.end(); ++iter)
 			{
@@ -590,12 +580,12 @@ namespace BansheeEngine
 		// Prepare final render target
 		SPtr<RenderTargetCore> target = rtData.target;
 
+		RenderAPICore::instance().setRenderTarget(target);
+		RenderAPICore::instance().setViewport(viewport->getNormArea());
+
 		// If first camera in render target, prepare the render target
 		if (camIdx == 0)
 		{
-			RenderAPICore::instance().setRenderTarget(target);
-			RenderAPICore::instance().setViewport(viewport->getNormArea());
-
 			UINT32 clearBuffers = 0;
 			if (viewport->getRequiresColorClear())
 				clearBuffers |= FBT_COLOR;
@@ -640,6 +630,9 @@ namespace BansheeEngine
 					continue;
 
 				mDirLightMat->setParameters(light.internal);
+
+				// TODO - Bind parameters to the pipeline manually as I don't need to re-bind gbuffer textures for every light
+				setPassParams(dirMaterial->getPassParameters(0), nullptr);
 				gRendererUtility().drawScreenQuad(*viewport);
 			}
 
@@ -657,6 +650,8 @@ namespace BansheeEngine
 
 				mPointLightMat->setParameters(light.internal);
 
+				// TODO - Bind parameters to the pipeline manually as I don't need to re-bind gbuffer textures for every light
+				setPassParams(dirMaterial->getPassParameters(0), nullptr);
 				SPtr<MeshCore> mesh = light.internal->getMesh();
 				gRendererUtility().draw(mesh, mesh->getProperties().getSubMesh(0));
 			}

+ 2 - 2
RenderBeast/Source/BsRenderTargets.cpp

@@ -16,9 +16,9 @@ namespace BansheeEngine
 		if (hdr)
 			mDiffuseFormat = PF_FLOAT_R11G11B10;
 		else
-			mDiffuseFormat = PF_R8G8B8X8;
+			mDiffuseFormat = PF_B8G8R8X8;
 
-		mNormalFormat = PF_FLOAT_R11G11B10;
+		mNormalFormat = PF_UNORM_R10G10B10A2;
 	}
 
 	SPtr<RenderTargets> RenderTargets::create(const ViewportCore& viewport, bool hdr, UINT32 numSamples)

+ 12 - 0
TODOExperimentation.txt

@@ -14,6 +14,18 @@ Assign ViewOrigin, PreViewTranslation, TransViewProj
  - Do this after I have basic rendering working, to avoid additional issues when I'm initially trying to get it to work
  
 Next week:
+ - Modify default shaders so they use deferred base pass and properly render to albedo/normal textures
+ - With no light in the scene nothing renders, but it should at least render everything as black (or ambient probably)
+ - Get rid of old code path
+
+Later:
+ - I changed how unsupported texture formats work, I should test if I didn't break OpenGL
+ - Positioning of meshes seems slightly broken (selecting the dragon will sometimes select the wall behind it, and handle is displayed at wrong position)
+ - When rendering lights right now I need to bind Gbuffer and light parameters to material, and then bind the material parameters to the pipeline
+  - Either unify these two processes by finding a better way, or hide the binding in light material class
+ - Too many depth buffers. Main render surface has one, game viewport has one and gbuffer has one
+  - Disable main depth buffer by default, disable depth buffer in SceneWindow and GameWindow RT's
+  - When rendering to scene target use the gbuffers depth buffer (what if their sizes don't match due to quantization?)
  - Default(dummy) shaders need to render to gbuffer
  - Finish up DefferedPointLightPass by generating cone geometry in shader
  - Modify Light so it generated adequate number of vertices required for cone geometry, without actually creating the cone