Add support for rim backlights
This commit is contained in:
parent
86118a34f4
commit
74ffe23551
|
@ -20,10 +20,12 @@ uniform mat4 MVnormal;
|
|||
// material
|
||||
uniform float opacity;
|
||||
uniform float shininess;
|
||||
uniform float backlight_strength;
|
||||
uniform float reflexiveness;
|
||||
uniform vec3 diffuse_color;
|
||||
uniform vec3 specular_color;
|
||||
uniform vec3 emissive_color;
|
||||
uniform vec3 backlight_color;
|
||||
|
||||
uniform bool isIlluminated;
|
||||
uniform bool isTextured;
|
||||
|
@ -97,9 +99,7 @@ vec3 get_nnormal() {
|
|||
}
|
||||
}
|
||||
|
||||
vec3 phong(vec3 basecolor) {
|
||||
vec3 nnormal = get_nnormal(); // normalized normal
|
||||
|
||||
vec3 phong(vec3 basecolor, vec3 nnormal) {
|
||||
vec3 diffuse_component = vec3(0.0);
|
||||
vec3 specular_component = vec3(0.0);
|
||||
|
||||
|
@ -139,16 +139,19 @@ vec3 phong(vec3 basecolor) {
|
|||
}
|
||||
|
||||
void main() {
|
||||
vec3 nnormal = get_nnormal(); // normalized normal
|
||||
vec4 c = vec4(vec3(1.0), opacity);
|
||||
if (isVertexColored) c *= color;
|
||||
if (isTextured) c *= texture(diffuseTexture, UV);
|
||||
if (isInverted) c.rgb = 1 - c.rgb;
|
||||
if (isIlluminated) c.rgb = phong(c.rgb);
|
||||
if (isIlluminated) c.rgb = phong(c.rgb, nnormal);
|
||||
else {
|
||||
c.rgb *= diffuse_color;
|
||||
if (isReflectionMapped)
|
||||
c.rgb = reflection(c.rgb, normalize(normal));
|
||||
}
|
||||
if (backlight_strength > 0.05)
|
||||
c.rgb += backlight_color * clamp((dot(normalize(vertex), nnormal) + backlight_strength) / backlight_strength, 0, 1);
|
||||
//c.rgb = diffuse_color;
|
||||
//c.rgb = emissive_color;
|
||||
//c.rgb = specular_color;
|
||||
|
|
|
@ -190,8 +190,10 @@ void renderNode(SceneNode* node, Gloom::Shader* parent_shader, vector<NodeDistSh
|
|||
u3fv (diffuse_color);
|
||||
u3fv (emissive_color);
|
||||
u3fv (specular_color);
|
||||
u3fv (backlight_color);
|
||||
u1f (opacity);
|
||||
u1f (shininess);
|
||||
u1f (backlight_strength);
|
||||
u1f (reflexiveness);
|
||||
u1f (displacementCoefficient);
|
||||
u1ui (isTextured);
|
||||
|
|
|
@ -114,6 +114,7 @@ void init_scene(CommandLineOptions options) {
|
|||
//{12, Material().diffuse({1.0, 1.0, 1.0})},// License_Plate_Frame
|
||||
//{13, Material().diffuse({1.0, 1.0, 1.0})},//
|
||||
});
|
||||
carNode->setMaterial(Material().backlight(vec3(0.3), 0.3).backlight_only().no_texture_reset(), true);
|
||||
carNode->position = {500, 500, 100};
|
||||
carNode->scale *= 100;
|
||||
rootNode->children.push_back(carNode);
|
||||
|
|
|
@ -66,6 +66,8 @@ void SceneNode::setMaterial(const Material& mat, bool recursive) {
|
|||
if (!mat.ignore_emissive) emissive_color = mat.emissive_color;
|
||||
if (!mat.ignore_specular) specular_color = mat.specular_color;
|
||||
if (!mat.ignore_specular) shininess = mat.shininess;
|
||||
if (!mat.ignore_backlight)backlight_color= mat.backlight_color;
|
||||
if (!mat.ignore_backlight)backlight_strength= mat.backlight_strength;
|
||||
setTexture(
|
||||
mat.diffuse_texture,
|
||||
mat.normal_texture,
|
||||
|
|
|
@ -71,10 +71,12 @@ struct SceneNode {
|
|||
// textures and materials
|
||||
float opacity = 1.0;
|
||||
float shininess = 1.0; // specular power
|
||||
float backlight_strength = 0.0;
|
||||
float reflexiveness = 0.0; // 0 is no reflection, 1 is a mirror. Negative value will have it multiply with base instead
|
||||
vec3 diffuse_color = vec3(1.0);
|
||||
vec3 emissive_color = vec3(0.5);
|
||||
vec3 specular_color = vec3(0.2);
|
||||
vec3 backlight_color = vec3(0.2);
|
||||
vec2 uvOffset = vec2(0.0, 0.0); // specular power
|
||||
uint diffuseTextureID;
|
||||
uint normalTextureID;
|
||||
|
|
|
@ -12,6 +12,7 @@ Material Material::apply(const Material& other) const {
|
|||
if (!other.ignore_diffuse) out.ignore_diffuse = false;
|
||||
if (!other.ignore_emissive) out.ignore_emissive = false;
|
||||
if (!other.ignore_specular) out.ignore_specular = false;
|
||||
if (!other.ignore_backlight)out.ignore_backlight= false;
|
||||
if (!other.texture_reset) out.texture_reset = true;
|
||||
|
||||
if (other.texture_reset || other.diffuse_texture) out.diffuse_texture = other.diffuse_texture;
|
||||
|
@ -40,6 +41,12 @@ Material Material::emissive(glm::vec3 color) const {
|
|||
out.emissive_color = color;
|
||||
return out;
|
||||
}
|
||||
Material Material::backlight(glm::vec3 color, float strength) const {
|
||||
Material out(*this);
|
||||
out.backlight_color = color;
|
||||
out.backlight_strength = strength;
|
||||
return out;
|
||||
}
|
||||
Material Material::textured(PNGImage* diffuse) const {
|
||||
Material out(*this);
|
||||
out.diffuse_texture = diffuse;
|
||||
|
@ -76,6 +83,7 @@ Material Material::no_colors() const {
|
|||
out.ignore_diffuse = true;
|
||||
out.ignore_emissive = true;
|
||||
out.ignore_specular = true;
|
||||
out.ignore_backlight = true;
|
||||
return out;
|
||||
}
|
||||
Material Material::no_diffuse() const {
|
||||
|
@ -93,12 +101,20 @@ Material Material::no_specular() const {
|
|||
out.ignore_specular = true;
|
||||
return out;
|
||||
}
|
||||
Material Material::no_backlight() const {
|
||||
Material out(*this);
|
||||
out.ignore_backlight = true;
|
||||
return out;
|
||||
}
|
||||
Material Material::diffuse_only() const {
|
||||
return this->no_emissive().no_specular();
|
||||
return this->no_emissive().no_specular().no_backlight();
|
||||
}
|
||||
Material Material::emissive_only() const {
|
||||
return this->no_diffuse().no_specular();
|
||||
return this->no_diffuse().no_specular().no_backlight();
|
||||
}
|
||||
Material Material::specular_only() const {
|
||||
return this->no_diffuse().no_emissive();
|
||||
return this->no_diffuse().no_emissive().no_backlight();
|
||||
}
|
||||
Material Material::backlight_only() const {
|
||||
return this->no_diffuse().no_emissive().no_specular();
|
||||
}
|
||||
|
|
|
@ -7,9 +7,11 @@ struct Material {
|
|||
float opacity = 1.0;
|
||||
float shininess = 1; // specular
|
||||
float reflexiveness = 0;
|
||||
float backlight_strength = 0;
|
||||
glm::vec3 diffuse_color = glm::vec3(1.0);
|
||||
glm::vec3 emissive_color = glm::vec3(0.5);
|
||||
glm::vec3 specular_color = glm::vec3(0.2);
|
||||
glm::vec3 backlight_color= glm::vec3(0.0);
|
||||
PNGImage* diffuse_texture = nullptr;
|
||||
PNGImage* normal_texture = nullptr;
|
||||
PNGImage* displacement_texture = nullptr;
|
||||
|
@ -18,6 +20,7 @@ struct Material {
|
|||
bool ignore_diffuse = false;
|
||||
bool ignore_emissive = false;
|
||||
bool ignore_specular = false;
|
||||
bool ignore_backlight= false;
|
||||
bool texture_reset = true;
|
||||
|
||||
Material apply(const Material& other) const;
|
||||
|
@ -25,6 +28,7 @@ struct Material {
|
|||
Material diffuse(glm::vec3 color) const;
|
||||
Material specular(glm::vec3 color, float shininess) const;
|
||||
Material emissive(glm::vec3 color) const;
|
||||
Material backlight(glm::vec3 color, float strength) const;
|
||||
Material textured(PNGImage* diffuse) const;
|
||||
Material normal_mapped(PNGImage* normal) const;
|
||||
Material diffuse_mapped(PNGImage* diffuse) const;
|
||||
|
@ -37,7 +41,9 @@ struct Material {
|
|||
Material no_diffuse() const;
|
||||
Material no_emissive() const;
|
||||
Material no_specular() const;
|
||||
Material diffuse_only() const; // and not the other two
|
||||
Material emissive_only() const; // and not the other two
|
||||
Material specular_only() const; // and not the other two
|
||||
Material no_backlight() const;
|
||||
Material diffuse_only() const; // and not the other three
|
||||
Material emissive_only() const; // and not the other three
|
||||
Material specular_only() const; // and not the other three
|
||||
Material backlight_only() const; // and not the other three
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue