working on the point light shader edge representation

This commit is contained in:
Sam Gateau 2015-02-02 16:31:36 -08:00
parent 2eb3c92e1d
commit 16f12dd267
5 changed files with 24 additions and 16 deletions

View file

@ -48,11 +48,11 @@ void Light::setOrientation(const glm::quat& orientation) {
}
void Light::setDirection(const Vec3& direction) {
editSchema()._direction = Vec4(direction, 0.f);
editSchema()._direction = direction;
}
const Vec3& Light::getDirection() const {
return Vec3(getSchema()._direction);
return getSchema()._direction;
}
void Light::setColor(const Color& color) {

View file

@ -88,7 +88,8 @@ public:
class Schema {
public:
Vec4 _position;
Vec4 _direction;
Vec3 _direction;
float _spare0;
Color _color;
float _intensity;
Vec4 _attenuation;
@ -99,7 +100,8 @@ public:
Schema() :
_position(0.0f, 0.0f, 0.0f, 1.0f),
_direction(0.0f, 0.0f, -1.0f, 0.f),
_direction(0.0f, 0.0f, -1.0f),
_spare0(0.f),
_color(1.0f),
_intensity(1.0f),
_attenuation(1.0f, 1.0f, 1.0f, 1.0f),

View file

@ -52,6 +52,10 @@ float getLightSquareRadius(Light l) {
return l._attenuation.w * l._attenuation.w;
}
float getLightRadius(Light l) {
return l._attenuation.w;
}
float getLightAttenuationCutoff(Light l) {
return l._attenuation.z;
}

View file

@ -66,10 +66,12 @@ void main(void) {
dot(eyeDir, wHalfDir));
vec3 specularColor = pow(specularPower, frag.gloss * 128.0) * frag.specular;
// add specular contribution
float ring = (lightAttenuation / (0.2 * getLightAttenuationCutoff(light))) - 1;
if (ring < 1) {
gl_FragColor = vec4(ring * ring * getLightColor(light), 0.0);
// Show edge
float maxRadius = getLightRadius(light);
float edge = abs(2.0 * ((maxRadius - lightDistance) / (0.1)) - 1.0);
if (edge < 1) {
float edgeCoord = exp2(-8.0*edge*edge);
gl_FragColor = vec4(edgeCoord * edgeCoord * getLightColor(light), 0.0);
} else {
gl_FragColor = vec4((diffuseColor + specularColor) * lightAttenuation * getLightColor(light) * getLightIntensity(light), 0.0);
}

View file

@ -39,27 +39,27 @@ void main(void) {
// Make the Light vector going from fragment to light center in world space
vec4 wPos;
wPos = invViewMat * frag.position;
vec3 lightVector = wPos.xyz - getLightPosition(light);
vec3 fragLightVec = getLightPosition(light) - wPos.xyz;
// Kill if too far from the light center
if (dot(lightVector, lightVector) > getLightSquareRadius(light)) {
if (dot(fragLightVec, fragLightVec) > getLightSquareRadius(light)) {
discard;
}
// Allright we re valid in the volume
float lightDistance = length(lightVector);
float lightAttenuation = evalLightAttenuation(light, lightDistance);
float fragLightDistance = length(fragLightVec);
float lightAttenuation = evalLightAttenuation(light, fragLightDistance);
vec3 lightDir = lightVector / lightDistance;
vec3 fragLightDir = fragLightVec / fragLightDistance;
gl_FragColor = vec4(getLightColor(light), 0.0);
// Kill if not in the spot light (ah ah !)
vec3 lightSpotDir = getLightDirection(light);
float cosSpotAngle = max(-dot(lightDir, lightSpotDir), 0.0);
float cosSpotAngle = max(-dot(fragLightDir, lightSpotDir), 0.0);
if (cosSpotAngle < getLightSpotAngleCos(light)) {
// discard;
gl_FragColor = vec4(vec3(1.0, 0.0, 0.0), 0.0);
discard;
//gl_FragColor = vec4(vec3(1.0, 0.0, 0.0), 0.0);
}
/*