This commit is contained in:
Tleety
2016-01-18 16:50:41 +01:00
parent 01a164847c
commit 601ce85c05
4 changed files with 33 additions and 11 deletions
@@ -23,7 +23,6 @@ struct DirectionalLightJob : RenderJob
glm::vec4 Direction;
glm::vec4 Color;
float Intensity;
glm::vec3 padding = glm::vec3(1.f, 2.f, 3.f);
void CalculateHash() override
{
+1 -1
View File
@@ -58,7 +58,7 @@ private:
//This should be a component
struct LightSource {
glm::vec4 Position = glm::vec4(0.f);
glm::vec4 Direction = glm::vec4(0.f);
glm::vec4 Direction = glm::vec4(10.f);
glm::vec4 Color = glm::vec4(1.f);
float Radius = 5.f;
float Intensity = 0.8f;
@@ -1,5 +1,5 @@
<c:DirectionalLight>
<Direction X="0" Y="0" Z="0"/>
<Direction X="5" Y="5" Z="5"/>
<Color R="1" G="1" B="1" A="1"/>
<Intensity>0.8</Intensity>
<Visible>true</Visible>
+31 -8
View File
@@ -72,7 +72,7 @@ vec4 CalcDiffuse(vec4 lightColor, vec4 lightVec, vec4 normal) {
return lightColor * power;
}
LightResult CalcLightSource(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff)
LightResult CalcPointLightSource(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff)
{
vec4 L = lightPos - position;
float dist = length(L);
@@ -86,6 +86,16 @@ LightResult CalcLightSource(vec4 lightPos, float lightRadius, vec4 lightColor, f
return result;
}
LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensity, vec4 viewVec, vec4 vertPosition, vec4 vertNormal)
{
vec4 L = normalize( -direction );
LightResult result;
result.Diffuse = CalcDiffuse(color, L, vertNormal) * intensity;
result.Specular = CalcSpecular(color, viewVec, L, vertNormal) * intensity;
return result;
}
void main()
{
@@ -105,22 +115,35 @@ void main()
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++)
{
for(int i = start; i < start + amount; i++) {
int l = int(LightIndex[i]);
LightResult result;
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);
if(LightSources.List[i].Type == 0) { // 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);
} else if (LightSources.List[i].Type == 1) { //Directional
result = CalcDirectionalLightSource(V * LightSources.List[l].Direction, LightSources.List[i].Color, LightSources.List[i].Intensity, viewVec, position, normal);
}
totalLighting.Diffuse += result.Diffuse;
totalLighting.Specular += result.Specular;
}
fragmentColor += Input.DiffuseColor;
//fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
//fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color;
fragmentColor += Input.DiffuseColor + 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);
if(LightSources.List[0].Type == 0) {
fragmentColor += vec4(1,0,0,1);
}
if(LightSources.List[0].Type == 1) {
fragmentColor += vec4(0,1,0,1);
}
if(LightSources.List[0].Type == 2) {
fragmentColor += vec4(0,0,1,1);
}
//fragmentColor = texel * Input.DiffuseColor * Color;
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);
} else {
//fragmentColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/3.0, 0, 0, 1);