aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.cpp5
-rw-r--r--src/gameplay.cpp1
-rw-r--r--src/world.cpp40
-rw-r--r--test.frag23
4 files changed, 41 insertions, 28 deletions
diff --git a/main.cpp b/main.cpp
index d5b9f78..9cc135d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -719,7 +719,7 @@ void render(){
ui::putText(offset.x-SCREEN_WIDTH/2,
(offset.y+SCREEN_HEIGHT/2)-ui::fontSize,
- "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nTc: %u\nHA: %+.2f",
+ "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nTc: %u\nHA: %+.2f\nPl: %d",
fps,
player->ground,
SCREEN_WIDTH, // Window dimensions
@@ -728,7 +728,8 @@ void render(){
player->loc.x, // The player's x coordinate
debugY, // The player's y coordinate
tickCount,
- handAngle
+ handAngle,
+ player->light
);
if(ui::posFlag){
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index e8436e7..e4fb000 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -179,6 +179,7 @@ void initEverything(void){
worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill2_Building1);
worldSpawnHill2->addLight({300,100},{1.0f,1.0f,1.0f});
+ worldSpawnHill2->addLight({500,100},{1.0f,1.0f,1.0f});
worldSpawnHill2->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest1,false);
worldFirstVillage->addVillage(5,0,0,STRUCTURET,worldSpawnHill2_Building1);
diff --git a/src/world.cpp b/src/world.cpp
index a52e3f3..e97ec56 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -669,22 +669,26 @@ LOOP2:
glActiveTexture(GL_TEXTURE0);
bgTex->bindNext();
+ GLfloat pointArray[light.size()][2];
+ for(uint w = 0; w < light.size(); w++){
+ pointArray[w][0] = light[w].loc.x - offset.x;
+ pointArray[w][1] = light[w].loc.y;
+ }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
glUseProgram(shaderProgram);
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glUniform1f(glGetUniformLocation(shaderProgram, "amb"), float(shade+50.0f)/100.0f);
if(p->light){
- glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), p->loc.x - offset.x+SCREEN_WIDTH/2,p->loc.y);
+ glUniform1i(glGetUniformLocation(shaderProgram, "numLight"), 1);
+ glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), p->loc.x - offset.x+SCREEN_WIDTH/2, p->loc.y);
glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1.0f,1.0f,1.0f);
- }else if(light.size() == 0){
- glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 0,-1000);
- glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0.0f,0.0f,0.0f);
+ }else if(!light.size()){
+ glUniform1i(glGetUniformLocation(shaderProgram, "numLight"), 0);
}else{
- for(auto &l : light){
- glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), l.loc.x-offset.x,l.loc.y);
- glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), l.color.red,l.color.green,l.color.blue);
- }
+ glUniform1i(glGetUniformLocation(shaderProgram, "numLight"), light.size());
+ glUniform2fv(glGetUniformLocation(shaderProgram, "lightLocation"), light.size(), (GLfloat *)&pointArray);
+ glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1.0f,1.0f,1.0f);
}
glBegin(GL_QUADS);
@@ -1268,20 +1272,24 @@ void IndoorWorld::draw(Player *p){
*/
glEnable(GL_TEXTURE_2D);
+ GLfloat pointArray[light.size()][2];
+ for(uint w = 0; w < light.size(); w++){
+ pointArray[w][0] = light[w].loc.x - offset.x;
+ pointArray[w][1] = light[w].loc.y;
+ }
glUseProgram(shaderProgram);
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glUniform1f(glGetUniformLocation(shaderProgram, "amb"), 0.0f);
if(p->light){
- glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), p->loc.x - offset.x+SCREEN_WIDTH/2,p->loc.y);
+ glUniform1i(glGetUniformLocation(shaderProgram, "numLight"), 1);
+ glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), p->loc.x - offset.x+SCREEN_WIDTH/2, p->loc.y);
glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1.0f,1.0f,1.0f);
- }else if(light.size() == 0){
- glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 0,-1000);
- glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0.0f,0.0f,0.0f);
+ }else if(!light.size()){
+ glUniform1i(glGetUniformLocation(shaderProgram, "numLight"), 0);
}else{
- for(auto &l : light){
- glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), l.loc.x-offset.x,l.loc.y);
- glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), l.color.red,l.color.green,l.color.blue);
- }
+ glUniform1i(glGetUniformLocation(shaderProgram, "numLight"), light.size());
+ glUniform2fv(glGetUniformLocation(shaderProgram, "lightLocation"), light.size(), (GLfloat *)&pointArray);
+ glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1.0f,1.0f,1.0f);
}
bgTex->bind(0);
diff --git a/test.frag b/test.frag
index b16ae1a..3b11ebb 100644
--- a/test.frag
+++ b/test.frag
@@ -1,20 +1,23 @@
uniform sampler2D sampler;
-uniform vec2 lightLocation;
+uniform int numLight;
+uniform vec2 lightLocation[10];
uniform vec3 lightColor;
uniform float amb;
// uniform float lightStrength;
//uniform float screenHeight;
-void main() {
- float lightAdd = 1.0f;
-
- float dist = length(lightLocation - gl_FragCoord.xy);
- float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);
-
- //vec4 color = vec4(1.0f,1.0f,1.0f,1.0f);
- vec4 color = vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f);
- //color = color + vec4((vec3(lightColor.r + amb, lightColor.g + amb, lightColor.b + amb)*0.25f),1.0f);
+void main(){
+ vec4 color = vec4(0.0f,0.0f,0.0f,0.0f);
+ for(int i = 0; i < numLight; i++){
+ vec2 loc = lightLocation[i];
+ //if(loc.x == 0.0f) continue;
+ float dist = length(loc - gl_FragCoord.xy);
+ float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);
+ //vec4 color = vec4(1.0f,1.0f,1.0f,1.0f);
+ color += vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f);
+ //color = color + vec4((vec3(lightColor.r + amb, lightColor.g + amb, lightColor.b + amb)*0.25f),1.0f);
+ }
vec2 coords = gl_TexCoord[0].st;
vec4 tex = texture2D(sampler, coords);