Working directional light
This commit is contained in:
@@ -15,7 +15,9 @@ struct DirectionalLightJob : RenderJob
|
|||||||
DirectionalLightJob(ComponentWrapper transformComponent, ComponentWrapper directionalLightComponent, World* m_World)
|
DirectionalLightJob(ComponentWrapper transformComponent, ComponentWrapper directionalLightComponent, World* m_World)
|
||||||
: RenderJob()
|
: RenderJob()
|
||||||
{
|
{
|
||||||
Direction = glm::vec4((glm::vec3)directionalLightComponent["Direction"], 0.f);
|
|
||||||
|
Direction = glm::vec4(0,0,-1,0) * Transform::AbsoluteOrientation(m_World, transformComponent.EntityID);
|
||||||
|
//Direction = glm::vec4((glm::vec3)directionalLightComponent["Direction"], 0.f);
|
||||||
Color = (glm::vec4)directionalLightComponent["Color"];
|
Color = (glm::vec4)directionalLightComponent["Color"];
|
||||||
Intensity = (double)directionalLightComponent["Intensity"];
|
Intensity = (double)directionalLightComponent["Intensity"];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ private:
|
|||||||
int m_NumberOfTiles = 0;
|
int m_NumberOfTiles = 0;
|
||||||
|
|
||||||
struct Plane {
|
struct Plane {
|
||||||
glm::vec3 Normal;
|
glm::vec3 Normal = glm::vec3(0.f);
|
||||||
float d;
|
float d = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Frustum {
|
struct Frustum {
|
||||||
@@ -68,9 +68,9 @@ private:
|
|||||||
std::vector<LightSource> m_LightSources;
|
std::vector<LightSource> m_LightSources;
|
||||||
|
|
||||||
struct LightGrid {
|
struct LightGrid {
|
||||||
float Start;
|
float Start = 0;
|
||||||
float Amount;
|
float Amount = 0;
|
||||||
glm::vec2 Padding;
|
glm::vec2 Padding = glm::vec2(1.f, 2.f);
|
||||||
};
|
};
|
||||||
|
|
||||||
LightGrid* m_LightGrid;
|
LightGrid* m_LightGrid;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<c:DirectionalLight>
|
<c:DirectionalLight>
|
||||||
<Direction X="5" Y="5" Z="5"/>
|
|
||||||
<Color R="1" G="1" B="1" A="1"/>
|
<Color R="1" G="1" B="1" A="1"/>
|
||||||
<Intensity>0.8</Intensity>
|
<Intensity>0.8</Intensity>
|
||||||
<Visible>true</Visible>
|
<Visible>true</Visible>
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
</xs:annotation>
|
</xs:annotation>
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:all>
|
<xs:all>
|
||||||
<xs:element name="Direction" type="t:Vector" minOccurs="0"/>
|
|
||||||
<xs:element name="Color" type="t:Color" minOccurs="0"/>
|
<xs:element name="Color" type="t:Color" minOccurs="0"/>
|
||||||
<xs:element name="Intensity" type="t:double" minOccurs="0"/>
|
<xs:element name="Intensity" type="t:double" minOccurs="0"/>
|
||||||
<xs:element name="Visible" type="t:bool" minOccurs="0"/>
|
<xs:element name="Visible" type="t:bool" minOccurs="0"/>
|
||||||
|
|||||||
@@ -86,9 +86,9 @@ LightResult CalcPointLightSource(vec4 lightPos, float lightRadius, vec4 lightCol
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensity, vec4 viewVec, vec4 vertPosition, vec4 vertNormal)
|
LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensity, vec4 viewVec, vec4 vertNormal)
|
||||||
{
|
{
|
||||||
vec4 L = normalize( vec4(direction.xyz, 1) );
|
vec4 L = normalize( -direction );
|
||||||
|
|
||||||
LightResult result;
|
LightResult result;
|
||||||
result.Diffuse = CalcDiffuse(color, L, vertNormal) * intensity;
|
result.Diffuse = CalcDiffuse(color, L, vertNormal) * intensity;
|
||||||
@@ -105,8 +105,8 @@ void main()
|
|||||||
vec4 viewVec = normalize(-position);
|
vec4 viewVec = normalize(-position);
|
||||||
|
|
||||||
vec2 tilePos;
|
vec2 tilePos;
|
||||||
tilePos.x = int(gl_FragCoord.x/16);
|
tilePos.x = int(gl_FragCoord.x/TILE_SIZE);
|
||||||
tilePos.y = int(gl_FragCoord.y/16);
|
tilePos.y = int(gl_FragCoord.y/TILE_SIZE);
|
||||||
|
|
||||||
LightResult totalLighting;
|
LightResult totalLighting;
|
||||||
totalLighting.Diffuse = scene_ambient;
|
totalLighting.Diffuse = scene_ambient;
|
||||||
@@ -117,12 +117,13 @@ void main()
|
|||||||
//for(int i = 0; i < 3; i++)
|
//for(int i = 0; i < 3; i++)
|
||||||
for(int i = start; i < start + amount; i++) {
|
for(int i = start; i < start + amount; i++) {
|
||||||
int l = int(LightIndex[i]);
|
int l = int(LightIndex[i]);
|
||||||
|
LightSource light = LightSources.List[l];
|
||||||
LightResult result;
|
LightResult result;
|
||||||
|
|
||||||
if(LightSources.List[i].Type == 1) { // point
|
if(light.Type == 1) { // point
|
||||||
result = CalcPointLightSource(V * LightSources.List[l].Position, LightSources.List[l].Radius, LightSources.List[l].Color, LightSources.List[l].Intensity, viewVec, position, normal, LightSources.List[i].Falloff);
|
result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
|
||||||
} else if (LightSources.List[i].Type == 2) { //Directional
|
} else if (light.Type == 2) { //Directional
|
||||||
result = CalcDirectionalLightSource(V * LightSources.List[l].Direction, LightSources.List[i].Color, LightSources.List[i].Intensity, viewVec, position, normal);
|
result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
|
||||||
}
|
}
|
||||||
totalLighting.Diffuse += result.Diffuse;
|
totalLighting.Diffuse += result.Diffuse;
|
||||||
totalLighting.Specular += result.Specular;
|
totalLighting.Specular += result.Specular;
|
||||||
@@ -132,8 +133,9 @@ void main()
|
|||||||
//fragmentColor += Input.DiffuseColor;
|
//fragmentColor += Input.DiffuseColor;
|
||||||
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 += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color;
|
||||||
//fragmentColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Start/.0, 0, 1);
|
//fragmentColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Amount/3, 0, 1);
|
||||||
//fragmentColor = texel * Input.DiffuseColor * Color;
|
//fragmentColor = texel * Input.DiffuseColor * Color;
|
||||||
|
//fragmentColor += vec4(currentTile/3600.f, 0, 0, 1);
|
||||||
if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 ) {
|
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 {
|
} else {
|
||||||
|
|||||||
@@ -40,15 +40,14 @@ void LightCullingPass::OnResolutionChange()
|
|||||||
|
|
||||||
void LightCullingPass::SetSSBOSizes()
|
void LightCullingPass::SetSSBOSizes()
|
||||||
{
|
{
|
||||||
m_NumberOfTiles = (int)(m_Renderer->Resolution().Width*m_Renderer->Resolution().Height)/TILE_SIZE;
|
m_NumberOfTiles = (int)(m_Renderer->Resolution().Width/TILE_SIZE) * (int)(m_Renderer->Resolution().Height/TILE_SIZE);
|
||||||
|
|
||||||
//m_Frustums = new Frustum[s];
|
|
||||||
//m_LightGrid = new LightGrid[s];
|
|
||||||
//m_LightIndex = new float[s*200];
|
|
||||||
|
|
||||||
m_Frustums = new Frustum[m_NumberOfTiles];
|
m_Frustums = new Frustum[m_NumberOfTiles];
|
||||||
m_LightGrid = new LightGrid[m_NumberOfTiles];
|
m_LightGrid = new LightGrid[m_NumberOfTiles];
|
||||||
m_LightIndex = new float[m_NumberOfTiles*MAX_LIGHTS_PER_TILE];
|
m_LightIndex = new float[m_NumberOfTiles*MAX_LIGHTS_PER_TILE];
|
||||||
|
for (int i = 0; i < m_NumberOfTiles*MAX_LIGHTS_PER_TILE; i++) {
|
||||||
|
m_LightIndex[i] = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightCullingPass::CullLights(RenderScene& scene)
|
void LightCullingPass::CullLights(RenderScene& scene)
|
||||||
@@ -75,7 +74,7 @@ void LightCullingPass::CullLights(RenderScene& scene)
|
|||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO);
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO);
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO);
|
||||||
glDispatchCompute(m_Renderer->Resolution().Width / TILE_SIZE, m_Renderer->Resolution().Height / TILE_SIZE, 1);
|
glDispatchCompute(glm::ceil(m_Renderer->Resolution().Width / TILE_SIZE), glm::ceil(m_Renderer->Resolution().Height / TILE_SIZE), 1);
|
||||||
|
|
||||||
GLERROR("CullLights Error: End");
|
GLERROR("CullLights Error: End");
|
||||||
}
|
}
|
||||||
@@ -117,25 +116,22 @@ void LightCullingPass::InitializeSSBOs()
|
|||||||
{
|
{
|
||||||
glGenBuffers(1, &m_FrustumSSBO);
|
glGenBuffers(1, &m_FrustumSSBO);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_FrustumSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_FrustumSSBO);
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(Frustum)*m_NumberOfTiles, m_Frustums, GL_DYNAMIC_COPY);
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(Frustum)*m_NumberOfTiles, nullptr, GL_DYNAMIC_COPY);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||||
GLERROR("m_FrustumSSBO");
|
GLERROR("m_FrustumSSBO");
|
||||||
|
|
||||||
glGenBuffers(1, &m_LightSSBO);
|
glGenBuffers(1, &m_LightSSBO);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
|
||||||
if(m_LightSources.size() > 0) {
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightSource) * 200, nullptr, GL_DYNAMIC_COPY);
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightSource) * m_LightSources.size(), &(m_LightSources[0]), GL_DYNAMIC_COPY);
|
|
||||||
}
|
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||||
GLERROR("m_LightSSBO");
|
GLERROR("m_LightSSBO");
|
||||||
|
|
||||||
glGenBuffers(1, &m_LightGridSSBO);
|
glGenBuffers(1, &m_LightGridSSBO);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightGridSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightGridSSBO);
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightGrid)*m_NumberOfTiles, m_LightGrid, GL_DYNAMIC_COPY);
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightGrid)*m_NumberOfTiles, nullptr, GL_DYNAMIC_COPY);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||||
GLERROR("m_LightGridSSBO");
|
GLERROR("m_LightGridSSBO");
|
||||||
|
|
||||||
|
|
||||||
glGenBuffers(1, &m_LightOffsetSSBO);
|
glGenBuffers(1, &m_LightOffsetSSBO);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
||||||
|
|||||||
Reference in New Issue
Block a user