Exemple #1
0
void CSMFGroundDrawer::CreateBorderShader() {
	std::string vsCode = std::move(Shader::GetShaderSource("GLSL/SMFBorderVertProg4.glsl"));
	std::string fsCode = std::move(Shader::GetShaderSource("GLSL/SMFBorderFragProg4.glsl"));

	Shader::GLSLShaderObject shaderObjs[2] = {{GL_VERTEX_SHADER, vsCode.c_str(), ""}, {GL_FRAGMENT_SHADER, fsCode.c_str(), ""}};
	Shader::IProgramObject* shaderProg = &borderShader;

	borderShader.AttachShaderObject(&shaderObjs[0]);
	borderShader.AttachShaderObject(&shaderObjs[1]);
	borderShader.ReloadShaderObjects();
	borderShader.CreateAndLink();
	borderShader.RecalculateShaderHash();
	borderShader.ClearAttachedShaderObjects();
	borderShader.Validate();

	shaderProg->Enable();
	shaderProg->SetUniformMatrix4x4<const char*, float>("u_movi_mat", false, CMatrix44f::Identity());
	shaderProg->SetUniformMatrix4x4<const char*, float>("u_proj_mat", false, CMatrix44f::Identity());
	shaderProg->SetUniform("u_diffuse_tex_sqr", -1, -1);
	shaderProg->SetUniform("u_diffuse_tex", 0);
	shaderProg->SetUniform("u_detail_tex", 2);
	shaderProg->Disable();
}
Exemple #2
0
void CSMFGroundDrawer::DrawWaterPlane(bool drawWaterReflection) {
	if (drawWaterReflection)
		return;

	GL::RenderDataBuffer& buffer = waterPlaneBuffers[1 - (camera->GetPos().IsInBounds() && !mapRendering->voidWater)];
	Shader::IProgramObject* shader = &buffer.GetShader();

	shader->Enable();
	shader->SetUniformMatrix4x4<const char*, float>("u_movi_mat", false, camera->GetViewMatrix());
	shader->SetUniformMatrix4x4<const char*, float>("u_proj_mat", false, camera->GetProjectionMatrix());
	shader->SetUniform("planeOffset", std::min(-200.0f, smfMap->GetCurrMinHeight() - 400.0f));
	buffer.Submit(GL_TRIANGLE_STRIP, 0, buffer.GetNumElems<VA_TYPE_C>());
	shader->Disable();
}
Exemple #3
0
void CSMFGroundDrawer::CreateWaterPlanes(bool camOutsideMap) {
	{
		const float xsize = (smfMap->mapSizeX) >> 2;
		const float ysize = (smfMap->mapSizeZ) >> 2;
		const float size = std::min(xsize, ysize);
		const float alphainc = math::TWOPI / 32.0f;

		static std::vector<VA_TYPE_C> verts;

		verts.clear();
		verts.reserve(4 * (32 + 1) * 2);

		const unsigned char fogColor[4] = {
			(unsigned char)(255 * sky->fogColor[0]),
			(unsigned char)(255 * sky->fogColor[1]),
			(unsigned char)(255 * sky->fogColor[2]),
			 255
		};

		const unsigned char planeColor[4] = {
			(unsigned char)(255 * waterRendering->planeColor[0]),
			(unsigned char)(255 * waterRendering->planeColor[1]),
			(unsigned char)(255 * waterRendering->planeColor[2]),
			 255
		};

		float alpha;
		float r1;
		float r2;

		float3 p;

		for (int n = (camOutsideMap) ? 0 : 1; n < 4; ++n) {
			if ((n == 1) && !camOutsideMap) {
				// don't render vertices under the map
				r1 = 2.0f * size;
			} else {
				r1 = n * n * size;
			}

			if (n == 3) {
				// last stripe: make it thinner (looks better with fog)
				r2 = (n + 0.5) * (n + 0.5) * size;
			} else {
				r2 = (n + 1) * (n + 1) * size;
			}

			for (alpha = 0.0f; (alpha - math::TWOPI) < alphainc; alpha += alphainc) {
				p.x = r1 * fastmath::sin(alpha) + 2.0f * xsize;
				p.z = r1 * fastmath::cos(alpha) + 2.0f * ysize;

				verts.push_back(VA_TYPE_C{p, {planeColor}});

				p.x = r2 * fastmath::sin(alpha) + 2.0f * xsize;
				p.z = r2 * fastmath::cos(alpha) + 2.0f * ysize;

				verts.push_back(VA_TYPE_C{p, {(n == 3)? fogColor : planeColor}});
			}
		}

		waterPlaneBuffers[camOutsideMap].Init();
		waterPlaneBuffers[camOutsideMap].UploadC(verts.size(), 0, verts.data(), nullptr);
	}
	{
		char vsBuf[65536];
		char fsBuf[65536];

		const char* vsVars = "uniform float planeOffset;\n";
		const char* vsCode =
			"\tgl_Position = u_proj_mat * u_movi_mat * vec4(a_vertex_xyz + vec3(0.0, planeOffset, 0.0), 1.0);\n"
			"\tv_color_rgba = a_color_rgba;\n";
		const char* fsVars = "const float v_color_mult = 1.0 / 255.0;\n";
		const char* fsCode = "\tf_color_rgba = v_color_rgba * v_color_mult;\n";

		GL::RenderDataBuffer::FormatShaderC(vsBuf, vsBuf + sizeof(vsBuf), "", vsVars, vsCode, "VS");
		GL::RenderDataBuffer::FormatShaderC(fsBuf, fsBuf + sizeof(fsBuf), "", fsVars, fsCode, "FS");
		GL::RenderDataBuffer& renderDataBuffer = waterPlaneBuffers[camOutsideMap];

		Shader::GLSLShaderObject shaderObjs[2] = {{GL_VERTEX_SHADER, &vsBuf[0], ""}, {GL_FRAGMENT_SHADER, &fsBuf[0], ""}};
		Shader::IProgramObject* shaderProg = renderDataBuffer.CreateShader((sizeof(shaderObjs) / sizeof(shaderObjs[0])), 0, &shaderObjs[0], nullptr);

		shaderProg->Enable();
		shaderProg->SetUniformMatrix4x4<const char*, float>("u_movi_mat", false, CMatrix44f::Identity());
		shaderProg->SetUniformMatrix4x4<const char*, float>("u_proj_mat", false, CMatrix44f::Identity());
		shaderProg->SetUniform("planeOffset", 0.0f);
		shaderProg->Disable();
	}
}