Esempio n. 1
0
void AlphaMaskTextureShader::load() {
    addVertexShader("ark2d/shaders/alphamask/texture-glsl150-vertex.txt");
    addFragmentShader("ark2d/shaders/alphamask/texture-glsl150-fragment.txt");

    bindAttributeLocation(0, "ark_TextureId");
    bindAttributeLocation(1, "ark_VertexPositionIn");
    bindAttributeLocation(2, "ark_VertexNormalIn");
    bindAttributeLocation(3, "ark_VertexTexCoordIn");
    bindAttributeLocation(4, "ark_VertexColorIn");
    bindFragmentDataLocation(0, "ark_FragColor");
    link();
    linkDX();

    showAnyGlErrorAndExitMacro();
    ShaderStore::getInstance()->addShader(m_programId, this);

    RendererState::start(RendererState::SHADER, getId());

    ark_ModelMatrix = getUniformVariable("ark_ModelMatrix");
    ark_ViewMatrix = getUniformVariable("ark_ViewMatrix");
    ark_ProjectionMatrix = getUniformVariable("ark_ProjectionMatrix");
    ark_NormalMatrix = getUniformVariable("ark_NormalMatrix");

    ark_TextureId = getUniformVariable("ark_TextureId");
    ark_VertexPositionIn = 1;
    ark_VertexNormalIn = 2;
    ark_VertexTexCoordIn = 3;
    ark_VertexColorIn = 4;

    RendererState::start(RendererState::NONE);
}
Esempio n. 2
0
    void initShader(Vec3 &pos, Mat4 &perspective, Mat4 &cameraTranslation, Mat4 &cameraRotation, PhongMaterial &mat)
    {

      BasicShader::initShader();

      addVertexShader("../../shaders/light_shadow_v.glsl");
      addFragmentShader("../../shaders/light_shadow_f.glsl");

      linkShader();

      addUniform(std::string("transform"));
      addUniform(std::string("perspective"));
      addUniform(std::string("camera"));
      addUniform(std::string("cameraRotation"));
      addUniform(std::string("lightMatrix"));

      addUniform(std::string("specularIntensity"));
      addUniform(std::string("specularExponent"));

      addUniform(std::string("eyePos"));

      addUniform(std::string("dirLight.diffuseIntensity"));
      addUniform(std::string("dirLight.dir"));
      addUniform(std::string("dirLight.color"));
      addUniform(std::string("dirLight.ambientIntensity"));

      addUniform(std::string("pointLight.color"));
      addUniform(std::string("pointLight.ambientIntensity"));
      addUniform(std::string("pointLight.diffuseIntensity"));
      addUniform(std::string("pointLight.position"));

      addUniform(std::string("pointLight.att.constant"));
      addUniform(std::string("pointLight.att.linear"));
      addUniform(std::string("pointLight.att.exp"));

      addUniform(std::string("spotLight.color"));
      addUniform(std::string("spotLight.position"));
      addUniform(std::string("spotLight.dir"));
      addUniform(std::string("spotLight.ambientIntensity"));
      addUniform(std::string("spotLight.diffuseIntensity"));
      addUniform(std::string("spotLight.cutoff"));


      addUniform(std::string("spotLight.att.constant"));
      addUniform(std::string("spotLight.att.linear"));
      addUniform(std::string("spotLight.att.exp"));

      addUniform(std::string("sampler"));
      addUniform(std::string("samplerShadow"));

      material_ = &mat;

      perspective_ = &perspective;
      cameraTranslation_ = &cameraTranslation;
      cameraRotation_ = &cameraRotation;
      eyePos_ = pos;

    }
Esempio n. 3
0
Shader::Shader(const char* vsource, const char* fsource)
{
	m_Program = glCreateProgram();
	
	addVertexShader(vsource);
	addFragmentShader(fsource);
	bindAttributeLocations();
	compileProgram();
}
Esempio n. 4
0
		void StencilShader::load() {

			if (ARK2D::getPlatform() == ARK2D::PLATFORM_ANDROID) {
				addVertexShader("ark2d/shaders/stencil/texture-glsles100-vertex.txt");
				addFragmentShader("ark2d/shaders/stencil/texture-glsles100-fragment.txt");
			} else {
				addVertexShader("ark2d/shaders/stencil/texture-glsl150-vertex.txt");
				bool err1 = hasError();
				addFragmentShader("ark2d/shaders/stencil/texture-glsl150-fragment.txt");
				bool err2 = hasError();

				if (err1 || err2) { 
					addVertexShader("ark2d/shaders/stencil/texture-glsl130-vertex.txt");
					addFragmentShader("ark2d/shaders/stencil/texture-glsl130-fragment.txt");
				}
			}

			bindAttributeLocation(0, "ark_TextureId");
			bindAttributeLocation(1, "ark_VertexPositionIn");
			bindAttributeLocation(2, "ark_VertexNormalIn");
			bindAttributeLocation(3, "ark_VertexTexCoordIn");
			bindAttributeLocation(4, "ark_VertexColorIn");
			bindFragmentDataLocation(0, "ark_FragColor");
			link(); 
			linkDX(); 

			ShaderStore::getInstance()->addShader(m_programId, this);

			RendererState::start(RendererState::SHADER, getId());

			ark_ModelMatrix = getUniformVariable("ark_ModelMatrix");
			ark_ViewMatrix = getUniformVariable("ark_ViewMatrix");
			ark_ProjectionMatrix = getUniformVariable("ark_ProjectionMatrix");
			ark_NormalMatrix = getUniformVariable("ark_NormalMatrix");
			
			ark_TextureId = getUniformVariable("ark_TextureId");
			ark_VertexPositionIn = 1;
			ark_VertexNormalIn = 2;
			ark_VertexTexCoordIn = 3;
			ark_VertexColorIn = 4;
			
			RendererState::start(RendererState::NONE);
		}
Esempio n. 5
0
Shader::Shader(const char* vsource, const char* fsource, const char* gsource)
{
	m_Program = glCreateProgram();

	addVertexShader(vsource);
	addFragmentShader(fsource);
	if(gsource!=NULL)
	{
		addGeometryShader(gsource);
	}
	bindAttributeLocations();
	compileProgram();
}
Esempio n. 6
0
StelQGLGLSLShader::StelQGLGLSLShader(StelQGL2Renderer* renderer, bool internal) 
	: StelGLSLShader()
	, renderer(renderer)
	, program(NULL)
	, state(State_Unlocked)
	, bound(false)
	, useUnprojectedPosition_(false)
	, internal(internal)
	, uniformStorageUsed(0)
	, uniformCount(0)
	, uniformStorageStackSize(0)
{
	renderer->getStatistics()[SHADERS_CREATED] += 1.0;
	if(!addVertexShader("DefaultProjector",
		"vec4 project(in vec4 v){return v;}\n"))
	{
		qWarning() << "Failed to add default projection vertex shader: " << log();
	}
}
Esempio n. 7
0
PhongShader::PhongShader(glm::vec3 ambientLight) : ambientLight(ambientLight)
{
	addVertexShader("phongVertex.vs");
	addFragmentShader("phongFragment.fs");
	compileShader();
	addUniform("directionalLight.base.intensity");
	addUniform("transform");
	addUniform("transformProjected");
	addUniform("sampler");
	addUniform("baseColor");
	addUniform("ambientLight");


	addUniform("specularIntensity");
	addUniform("specularPower");
	addUniform("eyePos");

	addUniform("directionalLight.base.color");

	addUniform("directionalLight.direction");
}
Esempio n. 8
0
    void initShader(Vec3 &pos, Mat4 &perspective, Mat4 &cameraTranslation, Mat4 &cameraRotation)
    {

      BasicShader::initShader();

      addVertexShader("../../shaders/simple_v.glsl");
      addFragmentShader("../../shaders/simple_f.glsl");

      linkShader();

      addUniform(std::string("transform"));
      addUniform(std::string("perspective"));
      addUniform(std::string("camera"));
      addUniform(std::string("cameraRotation"));

      //addUniform(std::string("model_col"));

      perspective_ = &perspective;
      cameraTranslation_ = &cameraTranslation;
      cameraRotation_ = &cameraRotation;
      eyePos_ = pos;

    }
		void PointLightingGeometryShader::load() {
			setName("point-lighting-geometry");

			bool err1 = false;
			bool err2 = false;
			if (ARK2D::getPlatform() == ARK2D::PLATFORM_ANDROID) {
				addVertexShader("ark2d/shaders/point-lighting/geometry/glsles100-vertex.txt");
				addFragmentShader("ark2d/shaders/point-lighting/geometry/glsles100-fragment.txt");
			} else {
				//addVertexShader("ark2d/shaders/point-lighting/geometry/glsl330-vertex.txt");
				//bool err1 = hasError();
				//addFragmentShader("ark2d/shaders/point-lighting/geometry/glsl330-fragment.txt");
				//bool err2 = hasError();

				//if (err1 || err2) { 
					err1 = false;
					err2 = false;

					addVertexShader("ark2d/shaders/point-lighting/geometry/glsl150-vertex.txt");
					err1 = hasError();
					addFragmentShader("ark2d/shaders/point-lighting/geometry/glsl150-fragment.txt");
					err2 = hasError();

					if (err1 || err2) { 
						addVertexShader("ark2d/shaders/point-lighting/geometry/glsl130-vertex.txt");
						addFragmentShader("ark2d/shaders/point-lighting/geometry/glsl130-fragment.txt");
					}
				//}
			}

			ShaderStore::getInstance()->addShader(m_programId, this);
			
			bindAttributeLocation(0, "ark_VertexPositionIn");
			bindAttributeLocation(1, "ark_VertexNormalIn");
			bindAttributeLocation(2, "ark_VertexColorIn");
			bindFragmentDataLocation(0, "ark_FragColor");
			link(); 
			linkDX(); 

			RendererState::start(RendererState::SHADER, getId());

			ark_ModelMatrix = getUniformVariable("ark_ModelMatrix");
			ark_ViewMatrix = getUniformVariable("ark_ViewMatrix");
			ark_ProjectionMatrix = getUniformVariable("ark_ProjectionMatrix");
			ark_NormalMatrix = getUniformVariable("ark_NormalMatrix");

			_LightColor = getUniformVariable("u_sunlight.vColor");
			_LightDirection = getUniformVariable("u_sunlight.vDirection");
			_LightAmbientIntensity = getUniformVariable("u_sunlight.fAmbientIntensity");
			_LightStrength = getUniformVariable("u_sunlight.fStrength");

			_PointLightColor = getUniformVariable("u_pointlight.vColor");
			_PointLightPosition = getUniformVariable("u_pointlight.vPosition");
			_PointLightAmbient = getUniformVariable("u_pointlight.fAmbient");
			_PointLightConstantAtt = getUniformVariable("u_pointlight.fConstantAtt");
			_PointLightLinearAtt = getUniformVariable("u_pointlight.fLinearAtt");
			_PointLightExpAtt = getUniformVariable("u_pointlight.fExpAtt");
			
			ark_VertexPositionIn = 0;
			ark_VertexNormalIn = 1;
			ark_VertexColorIn = 2;
			
			RendererState::start(RendererState::NONE);
		}
Esempio n. 10
0
void Shader::addVertexShaderFromFile(const std::string& text)
{
	addVertexShader(*loadShader(text));
}