当前位置: 首页>>代码示例>>C++>>正文


C++ GLProgramUniform类代码示例

本文整理汇总了C++中GLProgramUniform的典型用法代码示例。如果您正苦于以下问题:C++ GLProgramUniform类的具体用法?C++ GLProgramUniform怎么用?C++ GLProgramUniform使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GLProgramUniform类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SPADES_MARK_FUNCTION

 GLColorBuffer GLLensDustFilter::GaussianBlur(GLColorBuffer tex, bool vertical) {
     SPADES_MARK_FUNCTION();
     GLProgram *program = gauss1d;
     IGLDevice *dev = renderer->GetGLDevice();
     GLQuadRenderer qr(dev);
     int w = tex.GetWidth();
     int h = tex.GetHeight();
     
     static GLProgramAttribute blur_positionAttribute("positionAttribute");
     static GLProgramUniform blur_textureUniform("mainTexture");
     static GLProgramUniform blur_unitShift("unitShift");
     program->Use();
     blur_positionAttribute(program);
     
     blur_textureUniform(program);
     blur_textureUniform.SetValue(0);
     dev->ActiveTexture(0);
     dev->BindTexture(IGLDevice::Texture2D, tex.GetTexture());
     
     blur_unitShift(program);
     blur_unitShift.SetValue(vertical ? 0.f : 1.f / w,
                             vertical ? 1.f / h : 0.f);
     
     qr.SetCoordAttributeIndex(blur_positionAttribute());
     dev->Enable(IGLDevice::Blend, false);
     
     GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, false);
     dev->Viewport(0, 0, buf2.GetWidth(), buf2.GetHeight());
     dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
     qr.Draw();
     return buf2;
 }
开发者ID:VelocityRa,项目名称:openspades,代码行数:32,代码来源:GLLensDustFilter.cpp

示例2: SPADES_MARK_FUNCTION

		GLColorBuffer GLDepthOfFieldFilter::FinalMix(GLColorBuffer tex,
													 GLColorBuffer blur1,
													 GLColorBuffer blur2,
													 GLColorBuffer coc) {
			SPADES_MARK_FUNCTION();
			// do gaussian blur
			GLProgram *program = finalMix;
			IGLDevice *dev = renderer->GetGLDevice();
			GLQuadRenderer qr(dev);
			int w = tex.GetWidth();
			int h = tex.GetHeight();
			
			static GLProgramAttribute blur_positionAttribute("positionAttribute");
			static GLProgramUniform blur_textureUniform1("texture");
			static GLProgramUniform blur_textureUniform2("blurTexture1");
			static GLProgramUniform blur_textureUniform3("blurTexture2");
			static GLProgramUniform blur_textureUniform4("cocTexture");
			program->Use();
			blur_positionAttribute(program);
			
			blur_textureUniform1(program);
			blur_textureUniform1.SetValue(3);
			dev->ActiveTexture(3);
			dev->BindTexture(IGLDevice::Texture2D, tex.GetTexture());
			
			blur_textureUniform2(program);
			blur_textureUniform2.SetValue(2);
			dev->ActiveTexture(2);
			dev->BindTexture(IGLDevice::Texture2D, blur1.GetTexture());
			
			blur_textureUniform3(program);
			blur_textureUniform3.SetValue(1);
			dev->ActiveTexture(1);
			dev->BindTexture(IGLDevice::Texture2D, blur2.GetTexture());
			
			blur_textureUniform4(program);
			blur_textureUniform4.SetValue(0);
			dev->ActiveTexture(0);
			dev->BindTexture(IGLDevice::Texture2D, coc.GetTexture());
			
			
			qr.SetCoordAttributeIndex(blur_positionAttribute());
			dev->Enable(IGLDevice::Blend, false);
			
			// x-direction
			GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, false);
			dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
			qr.Draw();
			return buf2;
		}
开发者ID:2mac,项目名称:openspades,代码行数:50,代码来源:GLDepthOfFieldFilter.cpp

示例3: SPADES_MARK_FUNCTION

		GLColorBuffer GLLensFilter::Filter(GLColorBuffer input) {
			SPADES_MARK_FUNCTION();
			
			IGLDevice *dev = renderer->GetGLDevice();
			GLQuadRenderer qr(dev);
			
			static GLProgramAttribute lensPosition("positionAttribute");
			static GLProgramUniform lensTexture("mainTexture");
			static GLProgramUniform lensFov("fov");
			
			dev->Enable(IGLDevice::Blend, false);
			
			lensPosition(lens);
			lensTexture(lens);
			lensFov(lens);
			
			lens->Use();
			
			client::SceneDefinition def = renderer->GetSceneDef();
			lensFov.SetValue(tanf(def.fovX * .5f),
							 tanf(def.fovY * .5f));
			lensTexture.SetValue(0);
			
			// composite to the final image
			GLColorBuffer output = input.GetManager()->CreateBufferHandle();
			
			
			qr.SetCoordAttributeIndex(lensPosition());
			dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
			dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
			dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
			qr.Draw();
			dev->BindTexture(IGLDevice::Texture2D, 0);
			
			
			return output;
		}
开发者ID:VelocityRa,项目名称:openspades,代码行数:37,代码来源:GLLensFilter.cpp

示例4: SPADES_MARK_FUNCTION

		GLColorBuffer GLCameraBlurFilter::Filter(GLColorBuffer input, float radialBlur) {
			SPADES_MARK_FUNCTION();
			
			if(radialBlur > 0.f)
				radialBlur = 1.f - radialBlur;
			else
				radialBlur = 1.f;
			
			bool hasRadialBlur = radialBlur < .9999f;
			
			IGLDevice *dev = renderer->GetGLDevice();
			GLQuadRenderer qr(dev);
			
			
			
			dev->Enable(IGLDevice::Blend, false);
			
			static GLProgramAttribute programPosition("positionAttribute");
			static GLProgramUniform programTexture("texture");
			static GLProgramUniform programDepthTexture("depthTexture");
			static GLProgramUniform programReverseMatrix("reverseMatrix");
			static GLProgramUniform programShutterTimeScale("shutterTimeScale");
			
			programPosition(program);
			programTexture(program);
			programDepthTexture(program);
			programReverseMatrix(program);
			programShutterTimeScale(program);
			
			const client::SceneDefinition& def = renderer->GetSceneDef();
			Matrix4 newMatrix = Matrix4::Identity();
			newMatrix.m[0] = def.viewAxis[0].x;
			newMatrix.m[1] = def.viewAxis[1].x;
			newMatrix.m[2] = def.viewAxis[2].x;
			newMatrix.m[4] = def.viewAxis[0].y;
			newMatrix.m[5] = def.viewAxis[1].y;
			newMatrix.m[6] = def.viewAxis[2].y;
			newMatrix.m[8] = def.viewAxis[0].z;
			newMatrix.m[9] = def.viewAxis[1].z;
			newMatrix.m[10] = def.viewAxis[2].z;
			
			// othrogonal matrix can be reversed fast
			Matrix4 inverseNewMatrix = newMatrix.Transposed();
			Matrix4 diffMatrix = prevMatrix * inverseNewMatrix;
			prevMatrix = newMatrix;
			Matrix4 reverseMatrix = ReverseMatrix(diffMatrix);
			
			if(diffMatrix.m[0] < .3f ||
			   diffMatrix.m[5] < .3f ||
			   diffMatrix.m[10] < .3f){
				// too much change
				if(hasRadialBlur) {
					diffMatrix = Matrix4::Identity();
				}else{
					// skip blur
					return input;
				}
			}
			
			float movePixels = MyACos(diffMatrix.m[0]);
			float shutterTimeScale = .3f;
			movePixels = std::max(movePixels, MyACos(diffMatrix.m[5]));
			movePixels = std::max(movePixels, MyACos(diffMatrix.m[10]));
			movePixels = tanf(movePixels) / tanf(def.fovX * .5f);
			movePixels *= (float)dev->ScreenWidth() * .5f;
			movePixels *= shutterTimeScale;
			
			movePixels = std::max(movePixels,
								  (1.f - radialBlur) * dev->ScreenWidth() * 0.5f);
			
			if(movePixels < 1.f){
				// too less change, skip camera blur
				return input;
			}
			
			int levels = (int)ceilf(logf(movePixels) / logf(5.f));
			if(levels <= 0)
				levels = 1;
			
			if(hasRadialBlur)
				radialBlur *= radialBlur;
			reverseMatrix = Matrix4::Scale(radialBlur, radialBlur, 1.f)
				* reverseMatrix;
			
			program->Use();
			
			programTexture.SetValue(0);
			programDepthTexture.SetValue(1);
			programReverseMatrix.SetValue(reverseMatrix);
			
			// composite to the final image
			GLColorBuffer buf = input;
			
			qr.SetCoordAttributeIndex(programPosition());
			dev->ActiveTexture(1);
			dev->BindTexture(IGLDevice::Texture2D, renderer->GetFramebufferManager()->GetDepthTexture());
			dev->ActiveTexture(0);
			
			for(int i = 0; i < levels; i++){
				GLProfiler measure(dev, "Apply [%d / %d]", i+1,levels);
//.........这里部分代码省略.........
开发者ID:2mac,项目名称:openspades,代码行数:101,代码来源:GLCameraBlurFilter.cpp

示例5: SPADES_MARK_FUNCTION

		GLColorBuffer GLBloomFilter::Filter(GLColorBuffer input) {
			SPADES_MARK_FUNCTION();
			
			
			
			std::vector<Level> levels;
			
			IGLDevice *dev = renderer->GetGLDevice();
			GLQuadRenderer qr(dev);
			
			static GLProgramAttribute thruPosition("positionAttribute");
			static GLProgramUniform thruColor("colorUniform");
			static GLProgramUniform thruTexture("texture");
			static GLProgramUniform thruTexCoordRange("texCoordRange");
			
			thruPosition(thru);
			thruColor(thru);
			thruTexture(thru);
			thruTexCoordRange(thru);
			
			GLProgram *gammaMix = renderer->RegisterProgram("Shaders/PostFilters/GammaMix.program");
			static GLProgramAttribute gammaMixPosition("positionAttribute");
			static GLProgramUniform gammaMixTexture1("texture1");
			static GLProgramUniform gammaMixTexture2("texture2");
			static GLProgramUniform gammaMixMix1("mix1");
			static GLProgramUniform gammaMixMix2("mix2");
			
			gammaMixPosition(gammaMix);
			gammaMixTexture1(gammaMix);
			gammaMixTexture2(gammaMix);
			gammaMixMix1(gammaMix);
			gammaMixMix2(gammaMix);
			
			thru->Use();
			thruColor.SetValue(1.f, 1.f, 1.f, 1.f);
			thruTexture.SetValue(0);
			dev->Enable(IGLDevice::Blend, false);
			
			// create downsample levels
			for(int i = 0; i < 6; i++){
				GLColorBuffer prevLevel;
				if(i == 0){
					prevLevel = input;
				}else{
					prevLevel = levels.back().buffer;
				}
				
				int prevW = prevLevel.GetWidth();
				int prevH = prevLevel.GetHeight();
				int newW = (prevW + 1) / 2;
				int newH = (prevH + 1) / 2;
				GLColorBuffer newLevel = input.GetManager()->CreateBufferHandle(newW, newH);
				
				thru->Use();
				qr.SetCoordAttributeIndex(thruPosition());
				dev->BindTexture(IGLDevice::Texture2D, prevLevel.GetTexture());
				dev->BindFramebuffer(IGLDevice::Framebuffer, newLevel.GetFramebuffer());
				dev->Viewport(0, 0, newLevel.GetWidth(), newLevel.GetHeight());
				thruTexCoordRange.SetValue(0.f, 0.f,
										   (float)newLevel.GetWidth() * 2.f / (float)prevW,
										   (float)newLevel.GetHeight() * 2.f / (float)prevH);
				qr.Draw();
				dev->BindTexture(IGLDevice::Texture2D, 0);
				
				Level lv;
				lv.w = newW; lv.h = newH;
				lv.buffer = newLevel;
				levels.push_back(lv);
			}
			
			dev->Enable(IGLDevice::Blend, true);
			dev->BlendFunc(IGLDevice::SrcAlpha,
						   IGLDevice::OneMinusSrcAlpha);
			
			// composite levels in the opposite direction
			thruTexCoordRange.SetValue(0.f, 0.f, 1.f, 1.f);
			for(int i = (int)levels.size() - 1; i >= 1; i--){
				int cnt = (int)levels.size() - i;
				float alpha = (float)cnt / (float)(cnt + 1);
				alpha = sqrtf(alpha);
				GLColorBuffer curLevel = levels[i].buffer;
				GLColorBuffer targLevel = levels[i - 1].buffer;
			
				thru->Use();
				qr.SetCoordAttributeIndex(thruPosition());
				dev->BindTexture(IGLDevice::Texture2D, curLevel.GetTexture());
				dev->BindFramebuffer(IGLDevice::Framebuffer, targLevel.GetFramebuffer());
				dev->Viewport(0, 0, targLevel.GetWidth(), targLevel.GetHeight());
				thruColor.SetValue(1.f, 1.f, 1.f, alpha);
				qr.Draw();
				dev->BindTexture(IGLDevice::Texture2D, 0);
			}
			
			// composite to the final image
			GLColorBuffer output = input.GetManager()->CreateBufferHandle();
			GLColorBuffer topLevel = levels[0].buffer;
			
			gammaMix->Use();
			qr.SetCoordAttributeIndex(gammaMixPosition());
			dev->ActiveTexture(0);
//.........这里部分代码省略.........
开发者ID:2mac,项目名称:openspades,代码行数:101,代码来源:GLBloomFilter.cpp

示例6: SPADES_MARK_FUNCTION

		void GLVoxelModel::RenderSunlightPass(std::vector<client::ModelRenderParam> params) {
			SPADES_MARK_FUNCTION();

			device->ActiveTexture(0);
			aoImage->Bind(IGLDevice::Texture2D);
			device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
			                     IGLDevice::Linear);

			device->Enable(IGLDevice::CullFace, true);
			device->Enable(IGLDevice::DepthTest, true);

			program->Use();

			static GLShadowShader shadowShader;
			shadowShader(renderer, program, 1);

			static GLProgramUniform fogDistance("fogDistance");
			fogDistance(program);
			fogDistance.SetValue(renderer->GetFogDistance());

			static GLProgramUniform fogColor("fogColor");
			fogColor(program);
			Vector3 fogCol = renderer->GetFogColorForSolidPass();
			fogCol *= fogCol;
			fogColor.SetValue(fogCol.x, fogCol.y, fogCol.z);

			static GLProgramUniform aoUniform("ambientOcclusionTexture");
			aoUniform(program);
			aoUniform.SetValue(0);

			static GLProgramUniform modelOrigin("modelOrigin");
			modelOrigin(program);
			modelOrigin.SetValue(origin.x, origin.y, origin.z);

			static GLProgramUniform sunLightDirection("sunLightDirection");
			sunLightDirection(program);
			Vector3 sunPos = MakeVector3(0, -1, -1);
			sunPos = sunPos.Normalize();
			sunLightDirection.SetValue(sunPos.x, sunPos.y, sunPos.z);

			static GLProgramUniform viewOriginVector("viewOriginVector");
			viewOriginVector(program);
			const auto &viewOrigin = renderer->GetSceneDef().viewOrigin;
			viewOriginVector.SetValue(viewOrigin.x, viewOrigin.y, viewOrigin.z);

			// setup attributes
			static GLProgramAttribute positionAttribute("positionAttribute");
			static GLProgramAttribute textureCoordAttribute("textureCoordAttribute");
			static GLProgramAttribute colorAttribute("colorAttribute");
			static GLProgramAttribute normalAttribute("normalAttribute");

			positionAttribute(program);
			textureCoordAttribute(program);
			colorAttribute(program);
			normalAttribute(program);

			device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
			device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
			                            sizeof(Vertex), (void *)0);
			device->VertexAttribPointer(textureCoordAttribute(), 2, IGLDevice::UnsignedShort, false,
			                            sizeof(Vertex), (void *)4);
			device->VertexAttribPointer(colorAttribute(), 4, IGLDevice::UnsignedByte, true,
			                            sizeof(Vertex), (void *)8);
			device->VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
			                            sizeof(Vertex), (void *)12);
			device->BindBuffer(IGLDevice::ArrayBuffer, 0);

			device->EnableVertexAttribArray(positionAttribute(), true);
			device->EnableVertexAttribArray(textureCoordAttribute(), true);
			device->EnableVertexAttribArray(colorAttribute(), true);
			device->EnableVertexAttribArray(normalAttribute(), true);

			device->BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);

			for (size_t i = 0; i < params.size(); i++) {
				const client::ModelRenderParam &param = params[i];

				// frustrum cull
				float rad = radius;
				rad *= param.matrix.GetAxis(0).GetLength();
				if (!renderer->SphereFrustrumCull(param.matrix.GetOrigin(), rad)) {
					continue;
				}

				static GLProgramUniform customColor("customColor");
				customColor(program);
				customColor.SetValue(param.customColor.x, param.customColor.y, param.customColor.z);

				Matrix4 modelMatrix = param.matrix;
				static GLProgramUniform projectionViewModelMatrix("projectionViewModelMatrix");
				projectionViewModelMatrix(program);
				projectionViewModelMatrix.SetValue(renderer->GetProjectionViewMatrix() *
				                                   modelMatrix);

				static GLProgramUniform viewModelMatrix("viewModelMatrix");
				viewModelMatrix(program);
				viewModelMatrix.SetValue(renderer->GetViewMatrix() * modelMatrix);

				static GLProgramUniform modelMatrixU("modelMatrix");
				modelMatrixU(program);
//.........这里部分代码省略.........
开发者ID:Rootmars,项目名称:openspades,代码行数:101,代码来源:GLVoxelModel.cpp

示例7: SPADES_MARK_FUNCTION

		GLColorBuffer GLColorCorrectionFilter::Filter(GLColorBuffer input, Vector3 tintVal) {
			SPADES_MARK_FUNCTION();

			IGLDevice *dev = renderer->GetGLDevice();
			GLQuadRenderer qr(dev);

			static GLProgramAttribute lensPosition("positionAttribute");
			static GLProgramUniform lensTexture("mainTexture");

			static GLProgramUniform saturation("saturation");
			static GLProgramUniform enhancement("enhancement");
			static GLProgramUniform tint("tint");

			saturation(lens);
			enhancement(lens);
			tint(lens);

			dev->Enable(IGLDevice::Blend, false);

			lensPosition(lens);
			lensTexture(lens);

			lens->Use();

			tint.SetValue(tintVal.x, tintVal.y, tintVal.z);

			const client::SceneDefinition &def = renderer->GetSceneDef();

			if (settings.r_hdr) {
				// when HDR is enabled ACES tone mapping is applied first, so
				// lower enhancement value is required
				if (settings.r_bloom) {
					saturation.SetValue(0.8f * def.saturation * settings.r_saturation);
					enhancement.SetValue(0.1f);
				} else {
					saturation.SetValue(0.9f * def.saturation * settings.r_saturation);
					enhancement.SetValue(0.0f);
				}
			} else {
				if (settings.r_bloom) {
					// make image sharper
					saturation.SetValue(.85f * def.saturation * settings.r_saturation);
					enhancement.SetValue(0.7f);
				} else {
					saturation.SetValue(1.f * def.saturation * settings.r_saturation);
					enhancement.SetValue(0.3f);
				}
			}

			lensTexture.SetValue(0);

			// composite to the final image
			GLColorBuffer output = input.GetManager()->CreateBufferHandle();

			qr.SetCoordAttributeIndex(lensPosition());
			dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
			dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
			dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
			qr.Draw();
			dev->BindTexture(IGLDevice::Texture2D, 0);

			return output;
		}
开发者ID:Rootmars,项目名称:openspades,代码行数:63,代码来源:GLColorCorrectionFilter.cpp

示例8: SPADES_MARK_FUNCTION

		GLColorBuffer GLFogFilter::Filter(GLColorBuffer input) {
			SPADES_MARK_FUNCTION();
			
			IGLDevice *dev = renderer->GetGLDevice();
			GLQuadRenderer qr(dev);
			
			GLProgram *lens = renderer->RegisterProgram("Shaders/PostFilters/Fog.program");
			static GLProgramAttribute lensPosition("positionAttribute");
			static GLProgramUniform lensShadowMapTexture("shadowMapTexture");
			static GLProgramUniform lensCoarseShadowMapTexture("coarseShadowMapTexture");
			static GLProgramUniform lensColorTexture("colorTexture");
			static GLProgramUniform lensDepthTexture("depthTexture");
			static GLProgramUniform lensFov("fov");
			static GLProgramUniform lensViewOrigin("viewOrigin");
			static GLProgramUniform lensViewAxisUp("viewAxisUp");
			static GLProgramUniform lensViewAxisSide("viewAxisSide");
			static GLProgramUniform lensViewAxisFront("viewAxisFront");
			static GLProgramUniform zNearFar("zNearFar");;
			static GLProgramUniform fogColor("fogColor");
			static GLProgramUniform fogDistance("fogDistance");
			
			dev->Enable(IGLDevice::Blend, false);
			
			lensPosition(lens);
			lensShadowMapTexture(lens);
			lensCoarseShadowMapTexture(lens);
			lensColorTexture(lens);
			lensDepthTexture(lens);
			lensFov(lens);
			lensViewOrigin(lens);
			lensViewAxisUp(lens);
			lensViewAxisSide(lens);
			lensViewAxisFront(lens);
			zNearFar(lens);
			fogColor(lens);
			fogDistance(lens);
			
			lens->Use();
			
			client::SceneDefinition def = renderer->GetSceneDef();
			lensFov.SetValue(tanf(def.fovX * .5f),
							 tanf(def.fovY * .5f));
			lensViewOrigin.SetValue(def.viewOrigin.x,
									def.viewOrigin.y,
									def.viewOrigin.z);
			lensViewAxisUp.SetValue(def.viewAxis[1].x,
									def.viewAxis[1].y,
									def.viewAxis[1].z);
			lensViewAxisSide.SetValue(def.viewAxis[0].x,
									def.viewAxis[0].y,
									  def.viewAxis[0].z);
			lensViewAxisFront.SetValue(def.viewAxis[2].x,
									  def.viewAxis[2].y,
									   def.viewAxis[2].z);
			zNearFar.SetValue(def.zNear, def.zFar);
			
			
			Vector3 fogCol = renderer->GetFogColor();
			fogCol *= fogCol; // linearize
			fogColor.SetValue(fogCol.x, fogCol.y, fogCol.z);
			
			fogDistance.SetValue(128.f);
			
			lensColorTexture.SetValue(0);
			lensDepthTexture.SetValue(1);
			lensShadowMapTexture.SetValue(2);
			lensCoarseShadowMapTexture.SetValue(3);
			
			// composite to the final image
			GLColorBuffer output = input.GetManager()->CreateBufferHandle();
			
			
			dev->Enable(IGLDevice::Blend, false);
			qr.SetCoordAttributeIndex(lensPosition());
			dev->ActiveTexture(0);
			dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
			dev->ActiveTexture(1);
			dev->BindTexture(IGLDevice::Texture2D, input.GetManager()->GetDepthTexture());
			dev->ActiveTexture(2);
			dev->BindTexture(IGLDevice::Texture2D, renderer->GetMapShadowRenderer()->GetTexture());
			dev->ActiveTexture(3);
			dev->BindTexture(IGLDevice::Texture2D, renderer->GetMapShadowRenderer()->GetCoarseTexture());
			dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
			dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
			qr.Draw();
			dev->ActiveTexture(0);
			dev->BindTexture(IGLDevice::Texture2D, 0);
			
			
			return output;
		}
开发者ID:insanity54,项目名称:openspades,代码行数:91,代码来源:GLFogFilter.cpp

示例9: SPADES_MARK_FUNCTION

		void GLMapRenderer::RenderSunlightPass() {
			SPADES_MARK_FUNCTION();
			GLProfiler profiler(device, "Map");
			
			Vector3 eye = renderer->GetSceneDef().viewOrigin;
			
			// draw back face to avoid cheating.
			// without this, players can see through blocks by
			// covering themselves by ones.
			RenderBackface();
			
			device->ActiveTexture(0);
			aoImage->Bind(IGLDevice::Texture2D);
			device->TexParamater(IGLDevice::Texture2D,
								 IGLDevice::TextureMinFilter,
								 IGLDevice::Linear);
			
			device->ActiveTexture(1);
			detailImage->Bind(IGLDevice::Texture2D);
			
			
			device->Enable(IGLDevice::CullFace, true);
			device->Enable(IGLDevice::DepthTest, true);
			
			basicProgram->Use();
			
			static GLShadowShader shadowShader;
			shadowShader(renderer, basicProgram, 2);
			
			static GLProgramUniform fogDistance("fogDistance");
			fogDistance(basicProgram);
			fogDistance.SetValue(renderer->GetFogDistance());
			
			static GLProgramUniform viewSpaceLight("viewSpaceLight");
			viewSpaceLight(basicProgram);
			Vector3 vspLight = (renderer->GetViewMatrix() * MakeVector4(0, -1, -1, 0)).GetXYZ();
			viewSpaceLight.SetValue(vspLight.x, vspLight.y, vspLight.z);
			
			static GLProgramUniform fogColor("fogColor");
			fogColor(basicProgram);
			Vector3 fogCol = renderer->GetFogColorForSolidPass();
			fogCol *= fogCol; // linearize
			fogColor.SetValue(fogCol.x, fogCol.y, fogCol.z);
			
			static GLProgramUniform aoUniform("ambientOcclusionTexture");
			aoUniform(basicProgram);
			aoUniform.SetValue(0);
			
			static GLProgramUniform detailTextureUnif("detailTexture");
			detailTextureUnif(basicProgram);
			detailTextureUnif.SetValue(1);
			
			device->BindBuffer(IGLDevice::ArrayBuffer, 0);
			
			static GLProgramAttribute positionAttribute("positionAttribute");
			static GLProgramAttribute ambientOcclusionCoordAttribute("ambientOcclusionCoordAttribute");
			static GLProgramAttribute colorAttribute("colorAttribute");
			static GLProgramAttribute normalAttribute("normalAttribute");
			static GLProgramAttribute fixedPositionAttribute("fixedPositionAttribute");
			
			positionAttribute(basicProgram);
			ambientOcclusionCoordAttribute(basicProgram);
			colorAttribute(basicProgram);
			normalAttribute(basicProgram);
			fixedPositionAttribute(basicProgram);
			
			device->EnableVertexAttribArray(positionAttribute(), true);
			if(ambientOcclusionCoordAttribute() != -1)
				device->EnableVertexAttribArray(ambientOcclusionCoordAttribute(), true);
			device->EnableVertexAttribArray(colorAttribute(), true);
			if(normalAttribute() != -1)
				device->EnableVertexAttribArray(normalAttribute(), true);
			device->EnableVertexAttribArray(fixedPositionAttribute(), true);
			
			static GLProgramUniform projectionViewMatrix("projectionViewMatrix");
			projectionViewMatrix(basicProgram);
			projectionViewMatrix.SetValue(renderer->GetProjectionViewMatrix());
			
			static GLProgramUniform viewMatrix("viewMatrix");
			viewMatrix(basicProgram);
			viewMatrix.SetValue(renderer->GetViewMatrix());
			
			RealizeChunks(eye);
			
			// draw from nearest to farthest
			int cx = (int)floorf(eye.x) / GLMapChunk::Size;
			int cy = (int)floorf(eye.y) / GLMapChunk::Size;
			int cz = (int)floorf(eye.z) / GLMapChunk::Size;
			DrawColumnSunlight(cx, cy, cz, eye);
			for(int dist = 1; dist <= 128 / GLMapChunk::Size; dist++) {
				for(int x = cx - dist; x <= cx + dist; x++){
					DrawColumnSunlight(x, cy + dist, cz, eye);
					DrawColumnSunlight(x, cy - dist, cz, eye);
				}
				for(int y = cy - dist + 1; y <= cy + dist - 1; y++){
					DrawColumnSunlight(cx + dist, y, cz, eye);
					DrawColumnSunlight(cx - dist, y, cz, eye);
				}
			}
			
//.........这里部分代码省略.........
开发者ID:2mac,项目名称:openspades,代码行数:101,代码来源:GLMapRenderer.cpp

示例10: SPADES_MARK_FUNCTION


//.........这里部分代码省略.........
					v.sx = 1;
					v.sy = 1;
					vertices.push_back(v);

					indices.push_back(idx);
					indices.push_back(idx + 1);
					indices.push_back(idx + 2);
					indices.push_back(idx + 1);
					indices.push_back(idx + 3);
					indices.push_back(idx + 2);
				}
				Flush();
			}

			// finalize

			device->ActiveTexture(1);
			device->BindTexture(IGLDevice::Texture2D, 0);
			device->ActiveTexture(0);
			device->BindTexture(IGLDevice::Texture2D, 0);
			device->EnableVertexAttribArray(positionAttribute(), false);
			device->EnableVertexAttribArray(spritePosAttribute(), false);
			device->EnableVertexAttribArray(colorAttribute(), false);

			// composite downsampled sprite
			device->BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
			if (numLowResSprites > 0) {
				GLProfiler::Context measure(renderer->GetGLProfiler(), "Finalize");
				GLQuadRenderer qr(device);

				// do gaussian blur
				GLProgram *program =
				  renderer->RegisterProgram("Shaders/PostFilters/Gauss1D.program");
				static GLProgramAttribute blur_positionAttribute("positionAttribute");
				static GLProgramUniform blur_textureUniform("mainTexture");
				static GLProgramUniform blur_unitShift("unitShift");
				program->Use();
				blur_positionAttribute(program);
				blur_textureUniform(program);
				blur_unitShift(program);
				blur_textureUniform.SetValue(0);
				device->ActiveTexture(0);
				qr.SetCoordAttributeIndex(blur_positionAttribute());
				device->Enable(IGLDevice::Blend, false);

				// x-direction
				GLColorBuffer buf2 =
				  renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
				device->BindTexture(IGLDevice::Texture2D, buf.GetTexture());
				device->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
				blur_unitShift.SetValue(1.f / lW, 0.f);
				qr.Draw();
				buf.Release();

				// x-direction
				GLColorBuffer buf3 =
				  renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
				device->BindTexture(IGLDevice::Texture2D, buf2.GetTexture());
				device->BindFramebuffer(IGLDevice::Framebuffer, buf3.GetFramebuffer());
				blur_unitShift.SetValue(0.f, 1.f / lH);
				qr.Draw();
				buf2.Release();

				buf = buf3;

				device->Enable(IGLDevice::Blend, true);

				// composite
				program = renderer->RegisterProgram("Shaders/PostFilters/PassThrough.program");
				static GLProgramAttribute positionAttribute("positionAttribute");
				static GLProgramUniform colorUniform("colorUniform");
				static GLProgramUniform textureUniform("mainTexture");
				static GLProgramUniform texCoordRange("texCoordRange");

				positionAttribute(program);
				textureUniform(program);
				texCoordRange(program);
				colorUniform(program);

				program->Use();

				textureUniform.SetValue(0);
				texCoordRange.SetValue(0.f, 0.f, 1.f, 1.f);
				colorUniform.SetValue(1.f, 1.f, 1.f, 1.f);

				qr.SetCoordAttributeIndex(positionAttribute());
				device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);
				device->BindTexture(IGLDevice::Texture2D, buf.GetTexture());
				device->Viewport(0, 0, sW, sH);
				qr.Draw();
				device->BindTexture(IGLDevice::Texture2D, 0);

			} else {
				device->Viewport(0, 0, sW, sH);

				device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);
			}

			buf.Release();
		}
开发者ID:Rootmars,项目名称:openspades,代码行数:101,代码来源:GLSoftSpriteRenderer.cpp

示例11: profiler

		void GLMapRenderer::RenderBackface() {
			GLProfiler profiler(device, "Back-face");
			
			IntVector3 eye = renderer->GetSceneDef().viewOrigin.Floor();
			std::vector<BFVertex> vertices;
			std::vector<uint16_t> indices;
			client::GameMap *m = gameMap;
			
			int x, y, z;
			const int range = 1;
			for(x = eye.x - range; x <= eye.x + range; x++) {
				for(y = eye.y - range; y <= eye.y + range; y++) {
					for(z = eye.z - range; z <= eye.z + range; z++) {
						if(z >= 63) continue;
						if(z < 0) continue;
						if(!m->IsSolidWrapped(x, y, z))
							continue;
						SPAssert(m->IsSolidWrapped(x, y, z));
						
						if(m->IsSolidWrapped(x-1, y, z)) {
							EmitBackFace(x, y, z,
										 0, 1, 0,
										 0, 0, 1,
										 vertices, indices);
						}
						if(m->IsSolidWrapped(x+1, y, z)) {
							EmitBackFace(x+1, y, z,
										 0, 1, 0,
										 0, 0, 1,
										 vertices, indices);
						}
						if(m->IsSolidWrapped(x, y-1, z)) {
							EmitBackFace(x, y, z,
										 1, 0, 0,
										 0, 0, 1,
										 vertices, indices);
						}
						if(m->IsSolidWrapped(x, y+1, z)) {
							EmitBackFace(x, y+1, z,
										 1, 0, 0,
										 0, 0, 1,
										 vertices, indices);
						}
						if(m->IsSolidWrapped(x, y, z-1)) {
							EmitBackFace(x, y, z,
										 1, 0, 0,
										 0, 1, 0,
										 vertices, indices);
						}
						if(m->IsSolidWrapped(x, y, z+1)) {
							EmitBackFace(x, y, z+1,
										 1, 0, 0,
										 0, 1, 0,
										 vertices, indices);
						}
					}
				}
			}
			
			if(vertices.empty())
				return;
			
			device->Enable(IGLDevice::CullFace, false);
			
			backfaceProgram->Use();
			
			static GLProgramAttribute positionAttribute("positionAttribute");
			static GLProgramUniform projectionViewMatrix("projectionViewMatrix");
			
			positionAttribute(backfaceProgram);
			projectionViewMatrix(backfaceProgram);
			
			projectionViewMatrix.SetValue(renderer->GetProjectionViewMatrix());
			
			device->BindBuffer(IGLDevice::ArrayBuffer, 0);
			device->VertexAttribPointer(positionAttribute(),
										3, IGLDevice::Short,
										false, sizeof(BFVertex),
										vertices.data());
			
			device->EnableVertexAttribArray(positionAttribute(), true);
			
			device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
			device->DrawElements(IGLDevice::Triangles, indices.size(),
								 IGLDevice::UnsignedShort, indices.data());
			
			device->EnableVertexAttribArray(positionAttribute(), false);
			
			device->Enable(IGLDevice::CullFace, true);
			
		}
开发者ID:2mac,项目名称:openspades,代码行数:91,代码来源:GLMapRenderer.cpp


注:本文中的GLProgramUniform类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。