示例#1
0
 //  Runs once per render loop; where we provide input to shaders
 void AssignShaderInputs ()
   { Vect viewloc = Feld () -> Camera () -> ViewLoc ();
     SetShaderUniform ("fog_radius", GLOBE_RADIUS);
     SetShaderUniform ("system_distance", Loc () . DistFrom (viewloc));
     SetShaderUniform ("feld_size", Diag (Feld ()));
     SetShaderUniform ("camera_position", viewloc);
   }
示例#2
0
void RenderTexture(RenderContext *context, float x, float y, float rotation, Texture  *texture,
	float offset_x, float offset_y, float width, float height,  uint8 r, uint8 g, uint8 b, uint8 a)
{

	float32 rr = (1.0f / 255.0f)*(float32)r;
	float32 gg = (1.0f / 255.0f)*(float32)g;
	float32 bb = (1.0f / 255.0f)*(float32)b;
	float32 aa = (1.0f / 255.0f)*(float32)a;

	SetShaderUniform(&context->diffuse, "color", rr, gg, bb, aa);

	float scale_x = width / (float)texture->width;
	float scale_y = height / (float)texture->height;
	Matrix4 tex_offset = Matrix4_scale(scale_x, scale_y, 1.0f) * 
		Matrix4_translate(
		(1.0f / (float)texture->width)*offset_x, 
		(1.0f / (float)texture->height)*offset_y, 0.0f);
	SetShaderUniform(&context->diffuse, "tex_offset", tex_offset);
	
	SetShaderUniform(&context->diffuse, "using_tex", 1);
	if (context->bound_texture != texture)
	{
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, texture->id);
		context->bound_texture = texture;
	}
	Matrix4 world = Matrix4_scale(width, height, 1.0f) * Matrix4_rotate(rotation, 0.0f, 0.0f, 1.0f)
		* Matrix4_translate(x, y, 0.0f);
	SetShaderUniform(&context->diffuse, "world", world);

	// This isnt causing much lag?? must be the matrix math - got to do simd?? time to learn I guess?
	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
}
示例#3
0
void EpicShader::UpdateAttenuationUniforms(const Light* light) const
{
    float constant = 1.f, linear = 0.f, quadratic = 0.f;
    if (light) {
        light->GetAttenuation(constant, linear, quadratic);
    }

    SetShaderUniform("constantAttenuation", constant);
    SetShaderUniform("linearAttenuation", linear);
    SetShaderUniform("quadraticAttenuation", quadratic);
}
示例#4
0
void BeginRenderer(RenderContext *context, Matrix4 camera)
{
	glBindBuffer(GL_ARRAY_BUFFER, context->vbo);
	glBindVertexArray(context->vao);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, context->ebo);
	SetShaderUniform(&context->diffuse, "camera", camera);
}
示例#5
0
void RenderSquare(RenderContext *context, float x, float y, float w, float h,
	float rotation, uint8 r, uint8 g, uint8 b, uint8 a, bool outline)
{
	SetShaderUniform(&context->diffuse, "using_tex", 0);
	float32 rr = (1.0f / 255.0f)*(float32)r;
	float32 gg = (1.0f / 255.0f)*(float32)g;
	float32 bb = (1.0f / 255.0f)*(float32)b;
	float32 aa = (1.0f / 255.0f)*(float32)a;

	SetShaderUniform(&context->diffuse, "color", rr, gg, bb, aa);
	Matrix4 world = Matrix4_scale(w, h, 1.0f) * Matrix4_rotate(rotation, 0.0f, 0.0f, 1.0f)
		* Matrix4_translate(x, y, 0.0f);
	SetShaderUniform(&context->diffuse, "world", world);
	GLenum mode = GL_TRIANGLES;
	if (outline) mode = GL_LINE_LOOP;
	glDrawElements(mode, 6, GL_UNSIGNED_INT, 0);
}
void BlinnPhongShader::SetupShaderLighting(const Light* light) const
{
    if (!light) {
#ifndef DISABLE_OPENGL_SUBROUTINES
        SetShaderSubroutine("inputLightSubroutine", "globalLightSubroutine", lightingShaderStage);
#else
        SetShaderUniform("lightingType", static_cast<int>(Light::LightType::GLOBAL));
#endif
    } else {
        // Select proper lighting subroutine based on the light's type.
        switch(light->GetLightType()) {
        case Light::LightType::POINT:
#ifndef DISABLE_OPENGL_SUBROUTINES
            SetShaderSubroutine("inputLightSubroutine", "pointLightSubroutine", lightingShaderStage);
#else
            SetShaderUniform("lightingType", static_cast<int>(Light::LightType::POINT));
#endif
            break;
        default:
            std::cerr << "WARNING: Light type is not supported. Defaulting to global light. Your output may look wrong. -- Ignoring: " << static_cast<int>(light->GetLightType()) << std::endl;
#ifndef DISABLE_OPENGL_SUBROUTINES
            SetShaderSubroutine("inputLightSubroutine", "globalLightSubroutine", lightingShaderStage);
#else
            SetShaderUniform("lightingType", static_cast<int>(Light::LightType::GLOBAL));
#endif
            break;
        }

        // Get the light's properties and pass it into the shader.
        const LightProperties* lightProperty = light->GetPropertiesRaw();
        SetShaderUniform("genericLight.diffuseColor", lightProperty->diffuseColor);
        SetShaderUniform("genericLight.specularColor", lightProperty->specularColor);
        light->SetupShaderUniforms(this);
    }
    UpdateAttenuationUniforms(light);
}
void BlinnPhongShader::SetupShaderMaterials() const
{
    // Need to make sure the material buffer is bound.
    OGL_CALL(glBindBufferBase(GL_UNIFORM_BUFFER, MATERIAL_BINDING_POINT, materialBuffer));

    // Make sure the right textures are bound.
    const Texture* diffuseTexture = defaultTexture.get();
    if (textureSlotMapping.find(TextureSlots::DIFFUSE) != textureSlotMapping.end()) {
        diffuseTexture = textureSlotMapping.at(TextureSlots::DIFFUSE).get();
    }
    assert(diffuseTexture);
    diffuseTexture->BeginRender(static_cast<int>(TextureSlots::DIFFUSE));

    const Texture* specularTexture = defaultTexture.get();
    if (textureSlotMapping.find(TextureSlots::SPECULAR) != textureSlotMapping.end()) {
        specularTexture = textureSlotMapping.at(TextureSlots::SPECULAR).get();
    }
    assert(specularTexture);
    specularTexture->BeginRender(static_cast<int>(TextureSlots::SPECULAR));

    // While we're here, also setup the textures too.
    SetShaderUniform("diffuseTexture", static_cast<int>(TextureSlots::DIFFUSE));
    SetShaderUniform("specularTexture", static_cast<int>(TextureSlots::SPECULAR));
}
示例#8
0
void InitializeContext(RenderContext *context)
{
	float v = 0.5f;

	float vertices[] = {  
		//	 X	Y		U		V
			-v,	v,		0.0f,	1.0f,		// Front top left		0
			 v, v,		1.0f,	1.0f,		// Front top right		1
			 v, -v,		1.0f,	0.0f,		// Front bottom right	2
			-v, -v,		0.0f,	0.0f		// Front bottom left		3
	};

	glGenBuffers(1, &context->vbo);
	glBindBuffer(GL_ARRAY_BUFFER, context->vbo);
	glGenVertexArrays(1, &context->vao);
	glBindVertexArray(context->vao);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) * sizeof(float), vertices, GL_STATIC_DRAW);
	GLint pos = context->diffuse.attributes["position"];
	GLint tex = context->diffuse.attributes["tex_coord"];

	glVertexAttribPointer(pos, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
	glEnableVertexAttribArray(pos);

	glVertexAttribPointer(tex, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const GLvoid *)(2 * sizeof(float)));
	glEnableVertexAttribArray(tex);

	GLuint elements[] = {
		0, 1, 2,
		0, 2, 3
	};

	glGenBuffers(1, &context->ebo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, context->ebo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);

	// Camera shit
	Matrix4 projection = Matrix4_ortho(0.0f, 1920.0f, 0.0f, 1080.0f, -1.0f, 1.0f);
	SetShaderUniform(&context->diffuse, "projection", projection);

	context->font = LoadTexture("assets/font.png", GL_LINEAR);

}
示例#9
0
void EpicShader::SetupShaderLighting(const Light* light) const
{
    if (!light) {
        SetShaderUniform("lightingType", static_cast<int>(Light::LightType::GLOBAL));
    } else {
        // Get the light's properties
        const LightProperties* lightProperty = static_cast<const LightProperties*>(light->GetPropertiesRaw());

        // Select proper lighting subroutine based on the light's type.
        switch(light->GetLightType()) {
            case Light::LightType::POINT:
                SetShaderUniform("lightingType", static_cast<int>(Light::LightType::POINT));
                SetShaderUniform("pointLight.light_color", lightProperty->light_color);
                SetShaderUniform("pointLight.point_position", lightProperty->point_position);
                SetShaderUniform("pointLight.light_radius", lightProperty->light_radius);
                break;
            case Light::LightType::DIRECTIONAL:
                SetShaderUniform("lightingType", static_cast<int>(Light::LightType::DIRECTIONAL));
                SetShaderUniform(light->GetName() + ".light_color", lightProperty->light_color);
                SetShaderUniform(light->GetName() + ".forward_direction", light->GetForwardDirection());
                SetShaderUniform(light->GetName() + ".point_position", lightProperty->point_position);
                break;
            case Light::LightType::HEMISPHERE:
                SetShaderUniform("lightingType", static_cast<int>(Light::LightType::HEMISPHERE));
                SetShaderUniform(light->GetName() + ".sky_color", lightProperty->sky_color);
                SetShaderUniform(light->GetName() + ".ground_color", lightProperty->ground_color);
                break;
            default:
                std::cerr << "WARNING: Light type is not supported. Defaulting to global light. Your output may look wrong. -- Ignoring: " << static_cast<int>(light->GetLightType()) << std::endl;
                SetShaderUniform("lightingType", static_cast<int>(Light::LightType::GLOBAL));
                break;
	}
        light->SetupShaderUniforms(this);
    }
    UpdateAttenuationUniforms(light);
}
示例#10
0
void EpicShader::SetupShaderCamera(const class Camera* camera) const
{
    SetShaderUniform("cameraPosition", camera->GetPosition());
}