Exemplo 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);
}
Exemplo 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;

    }
Exemplo n.º 3
0
Shader::Shader(const char* vsource, const char* fsource)
{
	m_Program = glCreateProgram();
	
	addVertexShader(vsource);
	addFragmentShader(fsource);
	bindAttributeLocations();
	compileProgram();
}
Exemplo 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);
		}
Exemplo 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();
}
Exemplo n.º 6
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");
}
Exemplo n.º 7
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;

    }
Exemplo n.º 8
0
		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);
		}
Exemplo n.º 9
0
void Shader::addFragmentShaderFromFile(const std::string& text)
{
	addFragmentShader(*loadShader(text));
}