fixes
This commit is contained in:
@@ -7,6 +7,7 @@ uniform vec4 Color;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
|
||||
#define TILE_SIZE 16
|
||||
|
||||
struct PointLight {
|
||||
vec4 Position;
|
||||
@@ -48,7 +49,7 @@ in VertexData{
|
||||
|
||||
out vec4 fragmentColor;
|
||||
|
||||
vec4 scene_ambient = vec4(0.6,0.6,0.6,1);
|
||||
vec4 scene_ambient = vec4(0.0,0.0,0.0,1);
|
||||
|
||||
struct LightResult {
|
||||
vec4 Diffuse;
|
||||
@@ -98,10 +99,10 @@ void main()
|
||||
|
||||
LightResult totalLighting;
|
||||
totalLighting.Diffuse = scene_ambient;
|
||||
int currentTile = int(floor(gl_FragCoord.x/TILE_SIZE) + (floor(gl_FragCoord.y/TILE_SIZE) * 80));
|
||||
|
||||
|
||||
int start = int(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Start);
|
||||
int amount = int(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount);
|
||||
int start = int(LightGrids.Data[currentTile].Start);
|
||||
int amount = int(LightGrids.Data[currentTile].Amount);
|
||||
//for(int i = 0; i < 3; i++)
|
||||
for(int i = start; i < start + amount; i++)
|
||||
{
|
||||
@@ -114,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 = 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);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ struct Frustum {
|
||||
|
||||
layout (std430, binding = 0) buffer FrustumBuffer
|
||||
{
|
||||
Frustum Data[3600];
|
||||
Frustum Data[];
|
||||
} Frustums;
|
||||
|
||||
vec4 ConvertToView(vec4 ScreenCoords)
|
||||
@@ -43,36 +43,32 @@ Plane ComputePlane( vec3 p0, vec3 p1, vec3 p2 )
|
||||
layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
void main ()
|
||||
{
|
||||
if(gl_GlobalInvocationID.x * TILE_SIZE < ScreenDimensions.x && gl_GlobalInvocationID.y * TILE_SIZE < ScreenDimensions.y) {
|
||||
//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); // Z-axis might need to be 1
|
||||
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);
|
||||
//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[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);
|
||||
|
||||
vec3 ViewVectors[4];
|
||||
for(int i = 0; i < 4; i++) {
|
||||
ViewVectors[i] = vec3(ConvertToView(ScreenCoords[i]));
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
|
||||
|
||||
|
||||
if ( gl_GlobalInvocationID.x < ScreenDimensions.x / TILE_SIZE && gl_GlobalInvocationID.y < ScreenDimensions.y / TILE_SIZE ) { // innanför skärmen?
|
||||
Frustums.Data[gl_GlobalInvocationID.x + gl_GlobalInvocationID.y*80] = f;
|
||||
|
||||
}
|
||||
|
||||
|
||||
vec3 ViewVectors[4];
|
||||
for(int i = 0; i < 4; i++) {
|
||||
ViewVectors[i] = vec3(ConvertToView(ScreenCoords[i]));
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
|
||||
|
||||
|
||||
if ( gl_GlobalInvocationID.x < ScreenDimensions.x / TILE_SIZE && gl_GlobalInvocationID.y < ScreenDimensions.y / TILE_SIZE ) { // inside the screen
|
||||
Frustums.Data[gl_GlobalInvocationID.x + gl_GlobalInvocationID.y*80] = f;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ struct Frustum {
|
||||
|
||||
layout (std430, binding = 0) buffer FrustumBuffer
|
||||
{
|
||||
Frustum Data[3600];
|
||||
Frustum Data[];
|
||||
} Frustums;
|
||||
|
||||
struct PointLight {
|
||||
@@ -111,11 +111,9 @@ void main ()
|
||||
if(gl_LocalInvocationIndex == 0)
|
||||
{
|
||||
GroupLightCount = 0;
|
||||
|
||||
GroupFrustum = Frustums.Data[GroupIndex];
|
||||
}
|
||||
|
||||
memoryBarrierShared();
|
||||
barrier();
|
||||
|
||||
for(int i = int(gl_LocalInvocationIndex); i < PointLights.List.length(); i += TILE_SIZE*TILE_SIZE)
|
||||
@@ -124,7 +122,7 @@ void main ()
|
||||
|
||||
//if pointlight
|
||||
//Pos i view antagligen
|
||||
if(SphereInsideFrustrum(vec3(V * light.Position), light.Radius, GroupFrustum))
|
||||
if(SphereInsideFrustrum( vec3(V * light.Position), light.Radius, GroupFrustum))
|
||||
{
|
||||
//TODO: Fix transparent and opaque list, and depth test.
|
||||
AppendLight( i );
|
||||
@@ -137,20 +135,15 @@ void main ()
|
||||
|
||||
}
|
||||
|
||||
memoryBarrierShared();
|
||||
barrier();
|
||||
|
||||
if(gl_LocalInvocationIndex == 0)
|
||||
{
|
||||
GroupLightIndexStartOffset = atomicAdd(LightOffset[0], GroupLightCount);
|
||||
LightGrid g;
|
||||
g.Start = GroupLightIndexStartOffset;
|
||||
g.Amount = GroupLightCount;
|
||||
g.Padding = vec2(1111, 1111);
|
||||
LightGrids.Data[GroupIndex] = g;
|
||||
LightGrids.Data[GroupIndex].Start = GroupLightIndexStartOffset;
|
||||
LightGrids.Data[GroupIndex].Amount = GroupLightCount;
|
||||
}
|
||||
|
||||
memoryBarrierShared();
|
||||
barrier();
|
||||
|
||||
for (uint i = gl_LocalInvocationIndex; i < GroupLightCount; i += TILE_SIZE * TILE_SIZE )
|
||||
|
||||
Reference in New Issue
Block a user