Added capabilities for multiple light sources
parent
11679c2ffd
commit
6b98c2f0e3
@ -1,22 +1,43 @@
|
|||||||
|
#version 410 core
|
||||||
//SpriteBatch will use texture unit 0
|
//SpriteBatch will use texture unit 0
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
uniform vec2 u_screenResolution;
|
uniform vec2 u_screenResolution;
|
||||||
|
uniform vec2 u_lightCoord[50];
|
||||||
|
uniform float u_lightIntensity[50];
|
||||||
|
uniform int u_actualLights;
|
||||||
|
|
||||||
//"in" varyings from our vertex shader
|
//"in" varyings from our vertex shader
|
||||||
varying vec4 vColor;
|
varying vec4 vColor;
|
||||||
varying vec2 vTexCoord;
|
varying vec2 vTexCoord;
|
||||||
|
|
||||||
|
float getDistance(float x1, float y1, float x2, float y2){
|
||||||
|
float dx = x2 - x1;
|
||||||
|
float dy = y2 - y1;
|
||||||
|
float dis = sqrt(dx * dx + dy * dy);
|
||||||
|
return dis;
|
||||||
|
}
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//sample the texture
|
//sample the texture
|
||||||
vec4 texColor = texture2D(u_texture, vTexCoord);
|
vec4 texColor = texture2D(u_texture, vTexCoord);
|
||||||
float dx = u_screenResolution.x / 2.0 - gl_FragCoord.x;
|
|
||||||
float dy = u_screenResolution.y / 2.0 - gl_FragCoord.y;
|
float dis = getDistance(u_screenResolution.x / 2.0, u_screenResolution.y / 2.0, gl_FragCoord.x, gl_FragCoord.y);
|
||||||
float dxi = u_screenResolution.x / 2.0;
|
float disFull = getDistance(u_screenResolution.x / 2.0, u_screenResolution.y / 2.0, 0, 0);
|
||||||
float dyi = u_screenResolution.y / 2.0;
|
|
||||||
float dis = sqrt(dx * dx + dy * dy);
|
|
||||||
float disFull = sqrt(dxi * dxi + dyi * dyi);
|
|
||||||
float disSq = (1-(dis / disFull));
|
float disSq = (1-(dis / disFull));
|
||||||
texColor.rgb = texColor.rgb * disSq * disSq * disSq * disSq * disSq;
|
|
||||||
|
|
||||||
|
|
||||||
|
//Distance is measured in pixels
|
||||||
|
|
||||||
|
|
||||||
|
float brightest = 0;
|
||||||
|
for(int i = 0;i < u_actualLights;i++){
|
||||||
|
float dis2Light = getDistance(gl_FragCoord.x, gl_FragCoord.y, u_lightCoord[i].x, u_lightCoord[i].y);
|
||||||
|
float dis2Light2 = (1-(min(dis2Light/(disFull * u_lightIntensity[i]), 1)));
|
||||||
|
brightest = brightest + dis2Light2 - brightest * dis2Light2;
|
||||||
|
}
|
||||||
|
texColor.rgb = texColor.rgb * (pow(brightest, 10));
|
||||||
//final color
|
//final color
|
||||||
gl_FragColor = texColor * vColor;
|
gl_FragColor = texColor * vColor;
|
||||||
}
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.toasted.chuck;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
|
public class Light {
|
||||||
|
private static Vector2 tmp = new Vector2();
|
||||||
|
Vector2 position;
|
||||||
|
float intensity = 1;
|
||||||
|
public Light(float x, float y, float intensity){
|
||||||
|
position = new Vector2(x, y);
|
||||||
|
this.intensity = intensity;
|
||||||
|
}
|
||||||
|
public Vector2 getScreenPos(float cx, float cy){
|
||||||
|
return tmp.set(position).sub(cx, cy);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue