New Lightstruct working.
This commit is contained in:
+1
-1
Submodule assets updated: 6cbf2365d4...2fca918162
@@ -56,15 +56,16 @@ private:
|
||||
Frustum* m_Frustums;
|
||||
|
||||
//This should be a component
|
||||
struct PointLight {
|
||||
struct LightSource {
|
||||
glm::vec4 Position = glm::vec4(0.f);
|
||||
glm::vec4 Direction = glm::vec4(0.f);
|
||||
glm::vec4 Color = glm::vec4(1.f);
|
||||
float Radius = 5.f;
|
||||
float Intensity = 0.8f;
|
||||
float Falloff = 0.3f;
|
||||
float Padding = 1337;
|
||||
enum Type_t { Point, Directional, Spot } Type;
|
||||
};
|
||||
std::vector<PointLight> m_PointLights;
|
||||
std::vector<LightSource> m_LightSources;
|
||||
|
||||
struct LightGrid {
|
||||
float Start;
|
||||
|
||||
@@ -27,19 +27,20 @@ layout (std430, binding = 0) buffer FrustumBuffer
|
||||
Frustum Data[];
|
||||
} Frustums;
|
||||
|
||||
struct PointLight {
|
||||
struct LightSource {
|
||||
vec4 Position;
|
||||
vec4 Direction;
|
||||
vec4 Color;
|
||||
float Radius;
|
||||
float Intensity;
|
||||
float Falloff;
|
||||
float Padding;
|
||||
int Type;
|
||||
};
|
||||
|
||||
layout (std430, binding = 1) buffer LightBuffer
|
||||
{
|
||||
PointLight List[];
|
||||
} PointLights;
|
||||
LightSource List[];
|
||||
} LightSources;
|
||||
|
||||
struct LightGrid {
|
||||
float Start;
|
||||
@@ -106,8 +107,7 @@ layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
void main ()
|
||||
{
|
||||
GroupIndex = int(gl_WorkGroupID.x + (gl_WorkGroupID.y * int(ScreenDimensions.x/TILE_SIZE)));
|
||||
if(gl_LocalInvocationIndex == 0)
|
||||
{
|
||||
if(gl_LocalInvocationIndex == 0) {
|
||||
GroupLightCount = 0;
|
||||
GroupFrustum = Frustums.Data[GroupIndex];
|
||||
}
|
||||
@@ -115,22 +115,25 @@ void main ()
|
||||
barrier();
|
||||
memoryBarrierShared();
|
||||
|
||||
for(int i = int(gl_LocalInvocationIndex); i < PointLights.List.length(); i += TILE_SIZE*TILE_SIZE)
|
||||
{
|
||||
PointLight light = PointLights.List[i];
|
||||
for(int i = int(gl_LocalInvocationIndex); i < LightSources.List.length(); i += TILE_SIZE*TILE_SIZE) {
|
||||
LightSource light = LightSources.List[i];
|
||||
|
||||
//if pointlight
|
||||
//Pos i view antagligen
|
||||
if(SphereInsideFrustrum( vec3(V * light.Position), light.Radius, GroupFrustum))
|
||||
{
|
||||
//TODO: Fix transparent and opaque list, and depth test.
|
||||
AppendLight( i );
|
||||
if(light.Type == 0) {
|
||||
if(SphereInsideFrustrum( vec3(V * light.Position), light.Radius, GroupFrustum)) {
|
||||
//TODO: Fix transparent and opaque list, and depth test.
|
||||
AppendLight( i );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if conelight
|
||||
|
||||
//if directional
|
||||
if(light.Type == 1) {
|
||||
AppendLight( i );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,19 +9,20 @@ uniform sampler2D texture0;
|
||||
|
||||
#define TILE_SIZE 16
|
||||
|
||||
struct PointLight {
|
||||
struct LightSource {
|
||||
vec4 Position;
|
||||
vec4 Direction;
|
||||
vec4 Color;
|
||||
float Radius;
|
||||
float Intensity;
|
||||
float Falloff;
|
||||
float Padding;
|
||||
int Type;
|
||||
};
|
||||
|
||||
layout (std430, binding = 1) buffer LightBuffer
|
||||
{
|
||||
PointLight List[];
|
||||
} PointLights;
|
||||
LightSource List[];
|
||||
} LightSources;
|
||||
|
||||
struct LightGrid {
|
||||
float Start;
|
||||
@@ -71,7 +72,7 @@ vec4 CalcDiffuse(vec4 lightColor, vec4 lightVec, vec4 normal) {
|
||||
return lightColor * power;
|
||||
}
|
||||
|
||||
LightResult CalcPointLight(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff)
|
||||
LightResult CalcLightSource(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff)
|
||||
{
|
||||
vec4 L = lightPos - position;
|
||||
float dist = length(L);
|
||||
@@ -108,15 +109,15 @@ void main()
|
||||
{
|
||||
int l = int(LightIndex[i]);
|
||||
|
||||
LightResult result = CalcPointLight(V * PointLights.List[l].Position, PointLights.List[l].Radius, PointLights.List[l].Color, PointLights.List[l].Intensity, viewVec, position, normal, PointLights.List[i].Falloff);
|
||||
LightResult result = CalcLightSource(V * LightSources.List[l].Position, LightSources.List[l].Radius, LightSources.List[l].Color, LightSources.List[l].Intensity, viewVec, position, normal, LightSources.List[i].Falloff);
|
||||
|
||||
totalLighting.Diffuse += result.Diffuse;
|
||||
totalLighting.Specular += result.Specular;
|
||||
}
|
||||
|
||||
fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
|
||||
//fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
|
||||
//fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color;
|
||||
//fragmentColor += vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1);
|
||||
fragmentColor += Input.DiffuseColor + 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 )
|
||||
{
|
||||
|
||||
@@ -59,8 +59,8 @@ void LightCullingPass::CullLights(RenderScene& scene)
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
|
||||
if (m_PointLights.size() > 0) {
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(PointLight) * m_PointLights.size(), &(m_PointLights[0]), GL_DYNAMIC_COPY);
|
||||
if (m_LightSources.size() > 0) {
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightSource) * m_LightSources.size(), &(m_LightSources[0]), GL_DYNAMIC_COPY);
|
||||
} else {
|
||||
GLfloat zero = 0.f;
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(GLfloat), &zero , GL_DYNAMIC_COPY);
|
||||
@@ -82,19 +82,20 @@ void LightCullingPass::CullLights(RenderScene& scene)
|
||||
|
||||
void LightCullingPass::FillLightList(RenderScene& scene)
|
||||
{
|
||||
m_PointLights.clear();
|
||||
m_LightSources.clear();
|
||||
|
||||
for(auto &job : scene.PointLightJobs) {
|
||||
auto pointLightjob = std::dynamic_pointer_cast<PointLightJob>(job);
|
||||
if (pointLightjob) {
|
||||
PointLight p;
|
||||
LightSource p;
|
||||
p.Color = pointLightjob->Color;
|
||||
p.Falloff = pointLightjob->Falloff;
|
||||
p.Intensity = pointLightjob->Intensity;
|
||||
p.Position = glm::vec4(glm::vec3(pointLightjob->Position), 1.f);
|
||||
p.Radius = pointLightjob->Radius;
|
||||
p.Padding = 123.f;
|
||||
m_PointLights.push_back(p);
|
||||
//p.Padding = 123.f;
|
||||
p.Type = LightSource::Point;
|
||||
m_LightSources.push_back(p);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -110,8 +111,8 @@ void LightCullingPass::InitializeSSBOs()
|
||||
|
||||
glGenBuffers(1, &m_LightSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
|
||||
if(m_PointLights.size() > 0) {
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(PointLight) * m_PointLights.size(), &(m_PointLights[0]), GL_DYNAMIC_COPY);
|
||||
if(m_LightSources.size() > 0) {
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightSource) * m_LightSources.size(), &(m_LightSources[0]), GL_DYNAMIC_COPY);
|
||||
}
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
GLERROR("m_LightSSBO");
|
||||
|
||||
Reference in New Issue
Block a user