Forward+ semi working

This commit is contained in:
viktorljung
2015-12-17 17:55:44 +01:00
parent 6a3c14540d
commit 4a817613e3
5 changed files with 30 additions and 24 deletions
+3 -3
View File
@@ -49,7 +49,7 @@ in VertexData{
out vec4 fragmentColor;
vec4 scene_ambient = vec4(0.0,0.0,0.0,1);
vec4 scene_ambient = vec4(0.3,0.3,0.3,1);
struct LightResult {
vec4 Diffuse;
@@ -115,11 +115,11 @@ void main()
}
fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
fragmentColor += vec4(LightGrids.Data[currentTile].Amount/3.0, 0, 0, 1);
fragmentColor += vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1);
//fragmentColor = texel * Input.DiffuseColor * Color;
if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 )
{
//fragmentColor = vec4(0.5, 0, 0, 0);
fragmentColor += vec4(0.5, 0, 0, 0);
} else {
//fragmentColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/3.0, 0, 0, 1);
+6 -6
View File
@@ -24,7 +24,7 @@ vec4 ConvertToView(vec4 ScreenCoords)
vec2 normalizedScreenCoords = ScreenCoords.xy / ScreenDimensions;
vec4 clipSpace = vec4( vec2(normalizedScreenCoords.x, normalizedScreenCoords.y) * 2.0 - 1.0, ScreenCoords.z, ScreenCoords.w);
vec4 view = inverse(P) * clipSpace;
view = view / view.w;
//view = view / view.w;
return view;
}
@@ -46,7 +46,7 @@ void main ()
//Top-Left = 0 | Top-Right = 1
//Bottom-Left = 2 | Bottom-Right = 3
vec4 ScreenCoords[4];
ScreenCoords[0] = vec4(gl_GlobalInvocationID.x * TILE_SIZE, (gl_GlobalInvocationID.y + 1 ) * TILE_SIZE, -1.0, 1.0);
ScreenCoords[0] = vec4(gl_GlobalInvocationID.x * TILE_SIZE, (gl_GlobalInvocationID.y + 1) * TILE_SIZE, -1.0, 1.0);
ScreenCoords[1] = vec4((gl_GlobalInvocationID.x + 1) * TILE_SIZE, (gl_GlobalInvocationID.y + 1) * TILE_SIZE, -1.0, 1.0);
ScreenCoords[2] = vec4(gl_GlobalInvocationID.x * TILE_SIZE, (gl_GlobalInvocationID.y) * TILE_SIZE, -1.0, 1.0);
ScreenCoords[3] = vec4((gl_GlobalInvocationID.x + 1) * TILE_SIZE, (gl_GlobalInvocationID.y) * TILE_SIZE, -1.0, 1.0);
@@ -59,10 +59,10 @@ void main ()
vec3 EyePos = vec3(0,0,0);
Frustum f;
f.Planes[0] = ComputePlane(EyePos, ViewVectors[2], ViewVectors[0]);
f.Planes[1] = ComputePlane(EyePos, ViewVectors[1], ViewVectors[3]);
f.Planes[2] = ComputePlane(EyePos, ViewVectors[0], ViewVectors[1]);
f.Planes[3] = ComputePlane(EyePos, ViewVectors[3], ViewVectors[2]);
f.Planes[0] = ComputePlane(EyePos, ViewVectors[2], ViewVectors[0]); // left plane
f.Planes[1] = ComputePlane(EyePos, ViewVectors[1], ViewVectors[3]); // right plane
f.Planes[2] = ComputePlane(EyePos, ViewVectors[0], ViewVectors[1]); // top plane
f.Planes[3] = ComputePlane(EyePos, ViewVectors[3], ViewVectors[2]); // bottom plane
+9 -7
View File
@@ -8,7 +8,7 @@
#define NUM_LIGHTS 3
#define NUM_LIGHTS 25
#define MAX_LIGHTS_PER_TILE 1024
#define NUM_TILES 3600
#define TILE_SIZE 16
@@ -71,12 +71,11 @@ int GroupIndex;
bool SphereInsidePlane(vec3 center, float radius, Plane plane)
{
return dot(plane.Normal, center) - plane.d < -radius;
return dot(plane.Normal, center) + plane.d > -radius;
}
bool SphereInsideFrustrum(vec3 center, float radius, Frustum frustum/*, float zNear, float zFar*/)
{
bool result = true;
//Check depth here
//if ( sphere.c.z - sphere.r > zNear || sphere.c.z + sphere.r < zFar )
@@ -84,14 +83,14 @@ bool SphereInsideFrustrum(vec3 center, float radius, Frustum frustum/*, float zN
// result = false;
//}
for (int i =0; i < 4 && result; i++)
for (int i =0; i < 4; i++)
{
if(SphereInsidePlane(center, radius, frustum.Planes[i]))
if(! SphereInsidePlane(center, radius, frustum.Planes[i]))
{
result = false;
return false;
}
}
return result;
return true;
}
void AppendLight(int li)
@@ -115,6 +114,7 @@ void main ()
}
barrier();
memoryBarrierShared();
for(int i = int(gl_LocalInvocationIndex); i < PointLights.List.length(); i += TILE_SIZE*TILE_SIZE)
{
@@ -136,6 +136,7 @@ void main ()
}
barrier();
memoryBarrierShared();
if(gl_LocalInvocationIndex == 0)
{
@@ -145,6 +146,7 @@ void main ()
}
barrier();
for (uint i = gl_LocalInvocationIndex; i < GroupLightCount; i += TILE_SIZE * TILE_SIZE )
{