Browse Source

Improved Area Lighting

dragonCASTjosh 8 years ago
parent
commit
e741c50b11
2 changed files with 16 additions and 41 deletions
  1. 11 36
      bin/CoreData/Shaders/HLSL/PBR.hlsl
  2. 5 5
      bin/Data/Scenes/PBRExample.xml

+ 11 - 36
bin/CoreData/Shaders/HLSL/PBR.hlsl

@@ -10,30 +10,6 @@
 
 
     float3 SphereLight(float3 worldPos, float3 lightVec, float3 normal, float3 toCamera, float roughness, float3 specColor, float3 diffColor, out float ndl)
     float3 SphereLight(float3 worldPos, float3 lightVec, float3 normal, float3 toCamera, float roughness, float3 specColor, float3 diffColor, out float ndl)
     {
     {
-        // float3 pos   = (cLightPosPS.xyz - worldPos);
-        // float radius = cLightRad;
-
-        // float3 reflectVec   = reflect(-toCamera, normal);
-        // float3 centreToRay  = dot(pos, reflectVec) * reflectVec - pos;
-        // float3 closestPoint = pos + centreToRay * saturate(radius / length(centreToRay));
-
-        // float3 l = normalize(closestPoint);
-        // float3 h = normalize(toCamera + l);
-
-        // ndl       = saturate(dot(normal, l));
-        // float hdn = saturate(dot(h, normal));
-        // float hdv = dot(h, toCamera);
-        // float ndv = saturate(dot(normal, toCamera));
-
-        // float distL      = length(pos);
-        // float alpha      = roughness * roughness;
-        // float alphaPrime = saturate(radius / (distL * 2.0) + alpha);
-
-        // const float3 fresnelTerm = Fresnel(specColor, hdv) ;
-        // const float distTerm     = Distribution(hdn, alphaPrime);
-        // const float visTerm      = Visibility(ndl, ndv, roughness);
-
-        // return distTerm * visTerm * fresnelTerm ;
         float specEnergy = 1.0f;
         float specEnergy = 1.0f;
 
 
         float radius = cLightRad / 100;
         float radius = cLightRad / 100;
@@ -83,10 +59,10 @@
 
 
     }
     }
 
 
-    float3 TubeLight(float3 worldPos, float3 lightVec, float3 normal, float3 toCamera, float roughness, float3 specColor, out float ndl)
+    float3 TubeLight(float3 worldPos, float3 lightVec, float3 normal, float3 toCamera, float roughness, float3 specColor, float3 diffColor, out float ndl)
     {
     {
-         float radius      = cLightRad;
-         float len         = cLightLength; 
+        float radius      = cLightRad / 100;
+        float len         = cLightLength / 10; 
         float3 pos         = (cLightPosPS.xyz - worldPos);
         float3 pos         = (cLightPosPS.xyz - worldPos);
         float3 reflectVec  = reflect(-toCamera, normal);
         float3 reflectVec  = reflect(-toCamera, normal);
         
         
@@ -123,11 +99,12 @@
         float alpha      = roughness * roughness;
         float alpha      = roughness * roughness;
         float alphaPrime = saturate(radius / (distL * 2.0) + alpha);
         float alphaPrime = saturate(radius / (distL * 2.0) + alpha);
 
 
-        const float3 fresnelTerm = Fresnel(specColor, hdv) ;
-        const float distTerm     = Distribution(hdn, alphaPrime);
-        const float visTerm      = Visibility(ndl, ndv, roughness);
-
-        return distTerm * visTerm * fresnelTerm ;
+       const float3 diffuseFactor = Diffuse(diffColor, roughness, ndv, ndl, hdv)  * ndl;
+       const float3 fresnelTerm = Fresnel(specColor, hdv) ;
+       const float distTerm = Distribution(hdn, roughness);
+       const float visTerm = Visibility(ndl, ndv, roughness);
+       float3 specularFactor = distTerm * visTerm * fresnelTerm * ndl/ M_PI;
+       return diffuseFactor + specularFactor;
     }
     }
 
 
 	//Return the PBR BRDF value
 	//Return the PBR BRDF value
@@ -155,14 +132,12 @@
             {
             {
                 if(cLightLength > 0.0)
                 if(cLightLength > 0.0)
                 {
                 {
-                    return TubeLight(worldPos, lightVec, normal, toCamera, roughness, specColor, ndl);
+                    return TubeLight(worldPos, lightVec, normal, toCamera, roughness, specColor, diffColor, ndl);
                     
                     
                 }
                 }
                 else
                 else
                 {
                 {
-                    specularFactor = SphereLight(worldPos, lightVec, normal, toCamera, roughness, specColor, diffColor, ndl);
-                    specularFactor *= ndl;
-                    return diffuseFactor + specularFactor;
+                    return SphereLight(worldPos, lightVec, normal, toCamera, roughness, specColor, diffColor, ndl);
                 }
                 }
             }
             }
             else
             else

+ 5 - 5
bin/Data/Scenes/PBRExample.xml

@@ -7,8 +7,8 @@
 	<attribute name="Elapsed Time" value="152.788" />
 	<attribute name="Elapsed Time" value="152.788" />
 	<attribute name="Next Replicated Node ID" value="408" />
 	<attribute name="Next Replicated Node ID" value="408" />
 	<attribute name="Next Replicated Component ID" value="428" />
 	<attribute name="Next Replicated Component ID" value="428" />
-	<attribute name="Next Local Node ID" value="16777275" />
-	<attribute name="Next Local Component ID" value="16777901" />
+	<attribute name="Next Local Node ID" value="16777276" />
+	<attribute name="Next Local Component ID" value="16777913" />
 	<attribute name="Variables" />
 	<attribute name="Variables" />
 	<attribute name="Variable Names" value="" />
 	<attribute name="Variable Names" value="" />
 	<component type="Octree" id="1" />
 	<component type="Octree" id="1" />
@@ -1835,8 +1835,8 @@
 		<component type="Light" id="251">
 		<component type="Light" id="251">
 			<attribute name="Brightness Multiplier" value="1700" />
 			<attribute name="Brightness Multiplier" value="1700" />
 			<attribute name="Use Physical Values" value="true" />
 			<attribute name="Use Physical Values" value="true" />
-			<attribute name="Radius" value="0.11" />
-			<attribute name="Length" value="6.53" />
+			<attribute name="Radius" value="22.79" />
+			<attribute name="Length" value="55.25" />
 			<attribute name="Range" value="7.61" />
 			<attribute name="Range" value="7.61" />
 			<attribute name="Spot FOV" value="62.08" />
 			<attribute name="Spot FOV" value="62.08" />
 			<attribute name="Light Shape Texture" value="TextureCube;" />
 			<attribute name="Light Shape Texture" value="TextureCube;" />
@@ -3995,7 +3995,7 @@
 		<attribute name="Is Enabled" value="true" />
 		<attribute name="Is Enabled" value="true" />
 		<attribute name="Name" value="" />
 		<attribute name="Name" value="" />
 		<attribute name="Tags" />
 		<attribute name="Tags" />
-		<attribute name="Position" value="6.54564 5.37075 -0.065205" />
+		<attribute name="Position" value="6.15174 5.37075 -0.609303" />
 		<attribute name="Rotation" value="1 0 0 0" />
 		<attribute name="Rotation" value="1 0 0 0" />
 		<attribute name="Scale" value="0.648644 0.648644 0.648644" />
 		<attribute name="Scale" value="0.648644 0.648644 0.648644" />
 		<attribute name="Variables" />
 		<attribute name="Variables" />