Skip to content

Commit

Permalink
updated readme and CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
nilspettersson committed Nov 28, 2020
1 parent 942b465 commit 1063596
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 2.1.0
#### features
* added glosy function to ray marcher.
* ray marched objects can now cast shadows on rasterized objects.


### 2.0.0
#### changed
* changed the game loop.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# lwjgl_3D_library
Current version: **2.0.0**
# lwjgl_3D_framework
Current version: **2.1.0**

## Screenshots
| Ray marching| Rasterization and ray marching|
Expand Down
Binary file modified images/img2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 23 additions & 7 deletions shaders/lib/rayMarching.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Ray getRay(){
return Ray(dir, 0, 0, false);
}


//gets the distance to the closest object in the sdf function.
Ray rayMarch(Ray ray){
vec3 rayOrigin = cameraPosition;
Expand All @@ -69,7 +70,8 @@ Ray rayMarch(Ray ray){
//if ray hits rasterized object
if(DistOrigin * cosA > depth){
ray.hitRasterized = true;
DistOrigin *= cosA;
//gets the real depth value.
DistOrigin = depth / cosA;
break;
}

Expand All @@ -79,14 +81,14 @@ Ray rayMarch(Ray ray){
return Ray(ray.dir, DistOrigin, steps, ray.hitRasterized);
}


Ray rayMarchShadow(Ray ray, vec3 origin){

float cosA = ray.dir.w;
float DistOrigin = 0;
int steps = 0;
for(int i = 0; i < 200; i++){
vec3 point = origin + ray.dir.xyz * DistOrigin;

float dist = sdf(point);

DistOrigin += dist;
Expand Down Expand Up @@ -218,13 +220,19 @@ vec4 rayMarchShadows(Ray ray, vec3 color){
rayOrigin.z *= -1;
vec3 point = rayOrigin + ray.dir.xyz * ray.length;


vec3 allLight = vec3(0, 0, 0);
int shadowCount = 0;
for(int i = 0; i < lightCount; i++){
vec3 pos = lightPositions[i];
pos.z *= -1;
vec3 toLight = pos - point;
float disToLight = length(toLight);
float disToLight = length(toLight) / 8;


float brightness = 1;
brightness = max(brightness, 0);
float attenuation = lightIntensity[i] / (4.0 + 1 * disToLight + 1 * disToLight * disToLight);
brightness *= attenuation;


//if pixel is in shadow dont add current light.
Expand All @@ -234,10 +242,18 @@ vec4 rayMarchShadows(Ray ray, vec3 color){
if(toLightRay.length != -1){
shadowCount++;
}

else{
vec3 light = lightColors[i] * brightness;
allLight += light;
}
}

if(shadowCount > 0){
color *= allLight / lightCount;
}

vec4 diffuse = vec4(color, 1);
diffuse.xyz /= shadowCount + 1;
//diffuse.xyz /= shadowCount + 1;
return diffuse;
}
}

5 changes: 1 addition & 4 deletions shaders/postShader2.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@ float sdf(vec3 point){
transform1 = vec3(4, -8, 2);
float box2 = sdBox(point - transform1, vec3(2, 0.2, 2));

return (box);
return min(box, box2);
}

fragment{
Ray ray = getRay();
ray = rayMarch(ray);
//vec4 diffuse = rayMarchDiffuse(rayDir, vec3(1, 0.5, 0.5));


vec4 output = texture;
if(ray.length == -1){
return vec4(output);
}
else if(ray.hitRasterized == true){
ray.length = depth / ray.dir.w;
return rayMarchShadows(ray, vec3(texture.xyz));
}
else{
Expand Down
4 changes: 2 additions & 2 deletions src/niles/examples/Example2.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public void onload() {
addEntityToScene(e2);


addLight(new Vector3f(-3,-4 ,-4), new Vector3f(1), 6);
addLight(new Vector3f(8,-4 ,-4), new Vector3f(1), 6);
addLight(new Vector3f(-3,-4 ,-4), new Vector3f(1, 0.6f, 0.6f), 6);
addLight(new Vector3f(8,-4 ,-4), new Vector3f(0.6f, 0.6f, 1), 6);
}

@Override
Expand Down

0 comments on commit 1063596

Please sign in to comment.