Created
February 22, 2015 03:20
-
-
Save RobProductions/2ca3879a013b0a672eba to your computer and use it in GitHub Desktop.
Some ideas in 3D_model_skinned.frag for David's Jam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 330 | |
//Just some ideas | |
uniform sampler2D texture_id; | |
uniform vec4 color; | |
uniform float energy; | |
in vec3 var_view_pos; | |
in vec2 var_uv; | |
in vec3 var_normal; | |
out vec4 outputColor; | |
//you need uniforms for point light position | |
uniform vec3 pointPos; | |
//and pass in data from model_skinned.vert | |
in vec3 worldPos0; | |
//worldPos0 would be the vertex position without any perspective changes | |
//you also need point light range | |
uniform float range; | |
vec4 ApplyFog(vec4 color) { | |
vec3 fog_color = vec3(0.5,0.5,0.5); | |
float depth = length(var_view_pos); | |
return vec4(mix(color.xyz, fog_color, max(0.0, min(1.0, (depth - 10.0) * 0.1))), color.a); | |
} | |
vec4 ApplyLighting(vec4 color, vec3 normal) { | |
return vec4(color.xyz * vec3(mix((normal.y+1.0)*0.5, 1.0, 0.5)), color.a); | |
} | |
vec4 ApplyPointLighting(vec4 color, vec3 normal) { | |
vec3 lightDirection = worldPos0 - pointPos; | |
float distanceToPoint = length(lightDirection); | |
if(distanceToPoint > range) | |
return vec4(0,0,0,0); | |
lightDirection = normalize(lightDirection); | |
float diffuseFactor = dot (normal, -lightDirection); | |
//you'll need an intensity variable too o: | |
vec4 color1 = vec4(color, color.a) * intensity * diffuseFactor; | |
//sorry you'll need a falloff constant and linear and exponential amount... | |
//they can be unchanging final floats if its simplist to do so | |
float attenuation = falloffConstant + | |
linearAmount * distanceToPoint + | |
exponentialAmount * distanceToPoint * distanceToPoint | |
+ 0.0001; | |
//we add a small amount so we never divide by 0 | |
return color1 / attenuation; | |
} | |
void main() { | |
outputColor = texture(texture_id, var_uv); | |
outputColor *= color; | |
outputColor = ApplyLighting(outputColor, var_normal); | |
outputColor = ApplyFog(outputColor); | |
//outputColor.xyz = var_normal * 0.5 + vec3(0.5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment