Exemplo n.º 1
0
	// ==================================================================================================================
	int mainloop() {
		this->render.BeginScene();
		{
			this->t = timer->GetTime();

			ShaderRef fragmentShader = this->m_fragmentShader->Get();

			float2 rot_rp;
			float3 rot_rpy;
			
			rot_rpy = trk_rotate_root->Get(); m_rootActor->Matrix().Identity(); m_rootActor->Matrix().RotateRPY(rot_rpy.x, rot_rpy.y, rot_rpy.z);


			for (int i = 0; i < 6; i++) {
				rot_rp = trk_rotate[i]->Get(); 
				modelActors[i]->Transform().Identity(); 
				modelActors[i]->Transform().RotateRPY(rot_rp.x, rot_rp.y, 0);
			}

			fragmentShader->SetSamplerSatate(render, "SampleType", m_textureSampler->GetSamplerState());

			scene->PreRender(render);
			scene->Render(render);

			timer->Update();

		}

		this->render.EndScene();
		return 0;
	};
Exemplo n.º 2
0
		// ==================================================================================================================
		int mainloop() {
			this->render.BeginScene();
			{		
				Matrix worldMatrix;
				worldMatrix.Identity();
				worldMatrix.RotateRPY(t, .3455*t, .7346*t);

				struct {
					matrix worldMatrix;
					matrix viewMatrix;
					matrix projectionMatrix;
				} viewMatrices;

				m_camera->Calculate(render);

				viewMatrices.worldMatrix = XMMatrixTranspose(worldMatrix.Get());
				viewMatrices.viewMatrix = XMMatrixTranspose(m_camera->GetViewMatrix().Get());
				viewMatrices.projectionMatrix = XMMatrixTranspose(m_camera->GetProjectionMatrix().Get());

				m_vertexShader->GetParam("MatrixBuffer").SetP(&viewMatrices);

				m_fragmentShader->GetBRes("diffuse").Set(m_texture->GetTextureResource());
				m_fragmentShader->GetBRes("SampleType").Set(m_textureSampler->GetSamplerState());

				m_vertexShader->Render(this->render);
				m_fragmentShader->Render(this->render);

				m_model->RenderMesh(this->render);

				this->t += 0.01;
			}

			this->render.EndScene();
			return 0;
		};
Exemplo n.º 3
0
ShaderRef Shader::create(ShaderType type, DataSourceRef dataSrc, const std::string& entryName)
{
    ShaderRef shader;

    switch (type)
    {
    case Shader_VS: shader = ShaderRef(new VertexShader);   break;
    case Shader_PS: shader = ShaderRef(new PixelShader);    break;
    case Shader_GS: shader = ShaderRef(new GeometryShader); break;
    default: throw std::runtime_error("unexpected shader type");
    }

    HR( shader->setup(dataSrc, entryName) );

    return shader;
}
Exemplo n.º 4
0
LightManager::LightManager(ShaderRef shader, ShaderRef light_shader)
	: shader_(shader), light_shader_(light_shader) {
	auto unif_map = shader->GetUniformMap();
	num_lights_unif_ = unif_map.at(Uniform::NUM_LIGHTS);
	front_light_unif_ = unif_map.at(Uniform::LIGHT_POSITION);

	light_mvp_unif_ = light_shader_->GetUniformMap().at(Uniform::MVP_MATRIX);
}
Exemplo n.º 5
0
		void valueChanged (const std::string& value)
		{
			if (value.empty()) {
				setDefault();
			} else {
				m_shader.setName(value);
			}
			SceneChangeNotify();
		}
bool ShaderProgram::addShader(const char *name, const GLenum type) {
    ShaderLibrary *lib;
    ShaderRef newShader;

    if (_program == 0) {
        //First time this is called, create the program.
        _program = glCreateProgram();
    }

    lib = ShaderLibrary::getLibrary();
    newShader = lib->getShader(name, type);
    Logger::logprintf(Logger::LOG_VERBOSEINFO, Logger::LOG_SHADERS, "Attaching shader %s [%i] to GL Program %i\n", name, newShader.getShader(), _program);

    if (newShader.isValid()) {
        _shaders.push_back( newShader );

        return true;
    } else {
        return false;
    }
}
Exemplo n.º 7
0
		// ==================================================================================================================
		int mainloop() {

			m_postfx->BindInput(render);

			// pre fx-pass
			this->render.BeginScene();
			{
				ShaderRef fragmentShader = this->m_fragmentShader->Get();
				ShaderRef fxaaShader = this->m_fxFXAA->Get();
				ShaderRef fishEyeShader = this->m_fxFishEye->Get();

				m_rootActor->Matrix().Identity();
				m_rootActor->Matrix().RotateRPY(t,0,0);

				fragmentShader->GetBRes("SampleType").Set(m_textureSampler->GetSamplerState());
				
				float2 res = float2();
				render.GetScreenSizef(res.x, res.y);
				fxaaShader->GetParam("FXAA").Get("resolution").SetF(res.x, res.y);

				fishEyeShader->GetParam("Fisheye").Get("theta").SetF(0.5);

				scene->PreRender(render);
				scene->Render(render);

				this->t += 0.01;
			}

			// render fx chain 
			m_postfx->Render(render);
			
			this->render.EndScene();

			return 0;
		};
Exemplo n.º 8
0
		Shader* get () const
		{
			return m_shader.get();
		}
Exemplo n.º 9
0
		void setDefault ()
		{
			m_shader.setName("");
		}
	UberShaderInstance* UberShaderPreprocessor::Get(const ParameterList& parameters) const
	{
		// Première étape, transformer les paramètres en un flag
		UInt32 flags = 0;
		for (auto it = m_flags.begin(); it != m_flags.end(); ++it)
		{
			if (parameters.HasParameter(it->first))
			{
				bool value;
				if (parameters.GetBooleanParameter(it->first, &value) && value)
					flags |= it->second;
			}
		}

		// Le shader fait-il partie du cache ?
		auto shaderIt = m_cache.find(flags);

		// Si non, il nous faut le construire
		if (shaderIt == m_cache.end())
		{
			try
			{
				// Une exception sera lancée à la moindre erreur et celle-ci ne sera pas enregistrée dans le log (car traitée dans le bloc catch)
				ErrorFlags errFlags(ErrorFlag_Silent | ErrorFlag_ThrowException, true);

				ShaderRef shader = Shader::New();
				shader->Create();

				for (unsigned int i = 0; i <= ShaderStageType_Max; ++i)
				{
					const CachedShader& shaderStage = m_shaders[i];

					// Le shader stage est-il activé dans cette version du shader ?
					if (shaderStage.present && (flags & shaderStage.requiredFlags) == shaderStage.requiredFlags)
					{
						UInt32 stageFlags = 0;
						for (auto it = shaderStage.flags.begin(); it != shaderStage.flags.end(); ++it)
						{
							if (parameters.HasParameter(it->first))
							{
								bool value;
								if (parameters.GetBooleanParameter(it->first, &value) && value)
									stageFlags |= it->second;
							}
						}

						auto stageIt = shaderStage.cache.find(stageFlags);
						if (stageIt == shaderStage.cache.end())
						{
							ShaderStage stage;
							stage.Create(static_cast<ShaderStageType>(i));

							unsigned int glslVersion = OpenGL::GetGLSLVersion();

							StringStream code;
							code << "#version " << glslVersion << "\n\n";

							code << "#define GLSL_VERSION " << glslVersion << "\n\n";

							code << "#define EARLY_FRAGMENT_TESTS " << ((glslVersion >= 420 || OpenGL::IsSupported(OpenGLExtension_Shader_ImageLoadStore)) ? '1' : '0') << "\n\n";

							for (auto it = shaderStage.flags.begin(); it != shaderStage.flags.end(); ++it)
								code << "#define " << it->first << ' ' << ((stageFlags & it->second) ? '1' : '0') << '\n';

							code << "\n#line 1\n"; // Pour que les éventuelles erreurs du shader se réfèrent à la bonne ligne
							code << shaderStage.source;

							stage.SetSource(code);

							try
							{
								stage.Compile();
							}
							catch (const std::exception&)
							{
								ErrorFlags errFlags2(ErrorFlag_ThrowExceptionDisabled);

								NazaraError("Shader code failed to compile (" + stage.GetLog() + ")\n" + code.ToString());
								throw;
							}

							stageIt = shaderStage.cache.emplace(flags, std::move(stage)).first;
						}

						shader->AttachStage(static_cast<ShaderStageType>(i), stageIt->second);
					}
				}

				shader->Link();

				// On construit l'instant
				shaderIt = m_cache.emplace(flags, shader.Get()).first;
			}
			catch (const std::exception&)
			{
				ErrorFlags errFlags(ErrorFlag_ThrowExceptionDisabled);

				NazaraError("Failed to build UberShader instance: " + Error::GetLastError());
				throw;
			}
		}

		return &shaderIt->second;
	}