Corrected probe init'ing so they don't fight for the cubemap idx order

Also correct deleting behavior so it updates indicies when a probe is removed
Updated forward lighting to utilize the same math as deferred
This commit is contained in:
Areloch 2019-06-30 23:04:16 -05:00
parent 37461b4768
commit a1ecc98c87
21 changed files with 440 additions and 389 deletions

View file

@ -28,12 +28,12 @@
// These are the uniforms used by most lighting shaders.
uniform float4 inLightPos[3];
uniform float4 inLightInvRadiusSq;
uniform float4 inLightPos[4];
uniform float4 inLightConfigData[4];
uniform float4 inLightColor[4];
#ifndef TORQUE_BL_NOSPOTLIGHT
uniform float4 inLightSpotDir[3];
uniform float4 inLightSpotDir[4];
uniform float4 inLightSpotAngle;
uniform float4 inLightSpotFalloff;
#endif
@ -48,6 +48,8 @@ uniform float4 albedo;
#define MAX_PROBES 50
#define MAX_FORWARD_PROBES 4
#define MAX_FORWARD_LIGHT 4
inline float3 getDistanceVectorToPlane( float3 origin, float3 direction, float4 plane )
{
float denum = dot( plane.xyz, direction.xyz );
@ -65,146 +67,6 @@ inline float3 getDistanceVectorToPlane( float negFarPlaneDotEye, float3 directio
return direction.xyz * t;
}
//TODO fix compute 4 lights
void compute4Lights( float3 wsView,
float3 wsPosition,
float3 wsNormal,
float4 shadowMask,
#ifdef TORQUE_SHADERGEN
float4 inLightPos[3],
float4 inLightInvRadiusSq,
float4 inLightColor[4],
float4 inLightSpotDir[3],
float4 inLightSpotAngle,
float4 inLightSpotFalloff,
float smoothness,
float metalness,
float4 albedo,
#endif // TORQUE_SHADERGEN
out float4 outDiffuse,
out float4 outSpecular )
{
// NOTE: The light positions and spotlight directions
// are stored in SoA order, so inLightPos[0] is the
// x coord for all 4 lights... inLightPos[1] is y... etc.
//
// This is the key to fully utilizing the vector units and
// saving a huge amount of instructions.
//
// For example this change saved more than 10 instructions
// over a simple for loop for each light.
int i;
float4 lightVectors[3];
for ( i = 0; i < 3; i++ )
lightVectors[i] = wsPosition[i] - inLightPos[i];
float4 squareDists = 0;
for ( i = 0; i < 3; i++ )
squareDists += lightVectors[i] * lightVectors[i];
// Accumulate the dot product between the light
// vector and the normal.
//
// The normal is negated because it faces away from
// the surface and the light faces towards the
// surface... this keeps us from needing to flip
// the light vector direction which complicates
// the spot light calculations.
//
// We normalize the result a little later.
//
float4 nDotL = 0;
for ( i = 0; i < 3; i++ )
nDotL += lightVectors[i] * -wsNormal[i];
float4 rDotL = 0;
#ifndef TORQUE_BL_NOSPECULAR
// We're using the Phong specular reflection model
// here where traditionally Torque has used Blinn-Phong
// which has proven to be more accurate to real materials.
//
// We do so because its cheaper as do not need to
// calculate the half angle for all 4 lights.
//
// Advanced Lighting still uses Blinn-Phong, but the
// specular reconstruction it does looks fairly similar
// to this.
//
float3 R = reflect( wsView, -wsNormal );
for ( i = 0; i < 3; i++ )
rDotL += lightVectors[i] * R[i];
#endif
// Normalize the dots.
//
// Notice we're using the half type here to get a
// much faster sqrt via the rsq_pp instruction at
// the loss of some precision.
//
// Unless we have some extremely large point lights
// i don't believe the precision loss will matter.
//
half4 correction = (half4)rsqrt( squareDists );
nDotL = saturate( nDotL * correction );
rDotL = clamp( rDotL * correction, 0.00001, 1.0 );
// First calculate a simple point light linear
// attenuation factor.
//
// If this is a directional light the inverse
// radius should be greater than the distance
// causing the attenuation to have no affect.
//
float4 atten = saturate( 1.0 - ( squareDists * inLightInvRadiusSq ) );
#ifndef TORQUE_BL_NOSPOTLIGHT
// The spotlight attenuation factor. This is really
// fast for what it does... 6 instructions for 4 spots.
float4 spotAtten = 0;
for ( i = 0; i < 3; i++ )
spotAtten += lightVectors[i] * inLightSpotDir[i];
float4 cosAngle = ( spotAtten * correction ) - inLightSpotAngle;
atten *= saturate( cosAngle * inLightSpotFalloff );
#endif
// Finally apply the shadow masking on the attenuation.
atten *= shadowMask;
// Get the final light intensity.
float4 intensity = nDotL * atten;
// Combine the light colors for output.
outDiffuse = 0;
for ( i = 0; i < 4; i++ )
outDiffuse += intensity[i] * inLightColor[i];
// Output the specular power.
float4 specularIntensity = pow( rDotL, float4(1,1,1,1) ) * atten;
// Apply the per-light specular attenuation.
float4 specular = float4(0,0,0,1);
for ( i = 0; i < 4; i++ )
specular += float4( inLightColor[i].rgb * inLightColor[i].a * specularIntensity[i], 1 );
// Add the final specular intensity values together
// using a single dot product operation then get the
// final specular lighting color.
outSpecular = float4(1,1,1,1) * specular;
}
struct Surface
{
float3 P; // world space position
@ -372,6 +234,57 @@ inline float3 getPunctualLight(in Surface surface, in SurfaceToLight surfaceToLi
return final;
}
float4 compute4Lights( Surface surface,
float4 shadowMask,
float4 inLightPos[4],
float4 inLightConfigData[4],
float4 inLightColor[4],
float4 inLightSpotDir[4],
float4 lightSpotParams[4] )
{
float3 finalLighting = 0.0.xxx;
int i;
for(i = 0; i < MAX_FORWARD_LIGHT; i++)
{
float3 L = inLightPos[i].xyz - surface.P;
float dist = length(L);
float lightRange = inLightConfigData[i].z;
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
float shadowed = 1.0;
float3 lightCol = inLightColor[i].rgb;
float lightBrightness = inLightConfigData[i].y;
float lightInvSqrRange= inLightConfigData[i].a;
float3 lighting = 0.0.xxx;
[branch]
if(dist < lightRange)
{
[branch]
if(inLightConfigData[i].x == 0) //point
{
//get punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
}
else //spot
{
//get Punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
//get spot angle attenuation
lighting *= getSpotAngleAtt(-surfaceToLight.L, inLightSpotDir[i].xyz, lightSpotParams[i].xy );
}
}
finalLighting += lighting;
}
return float4(finalLighting,1);
}
//Probe IBL stuff
float defineSphereSpaceInfluence(float3 wsPosition, float3 wsProbePosition, float radius)
{

View file

@ -32,7 +32,7 @@ uniform float4 probeConfigData[MAX_PROBES]; //r,g,b/mode,radius,atten
uniform float4 probeContribColors[MAX_PROBES];
#endif
uniform float skylightCubemapIdx;
uniform int skylightCubemapIdx;
float4 main(PFXVertToPix IN) : SV_TARGET
{
@ -140,7 +140,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
//Skylight coloration for anything not covered by probes above
if(skylightCubemapIdx != -1)
finalContribColor += float3(0.3, 0.3, 0.3) * contribAlpha;
finalContribColor += float3(0, 1, 0) * contribAlpha;
return float4(finalContribColor, 1);
#endif

View file

@ -7,8 +7,8 @@ singleton Material(Grid_512_Orange)
specular[0] = "0.8 0.8 0.8 1";
specularPower[0] = "0.25";
specularStrength[0] = "25";
translucentBlendOp = "Add";
smoothness[0] = "0.941176";
translucentBlendOp = "LerpAlpha";
smoothness[0] = "1";
metalness[0] = "1";
DiffuseMapAsset0 = "StaticShapeTest:Grid_512_orange_ALBEDO";
specularStrength0 = "25";

View file

@ -101,19 +101,6 @@ new Scene(PbrMatTestLevel) {
persistentId = "658580df-7bda-11e9-9951-fcefa3e1cde4";
reflectionPath = "data/pbr/levels/PbrMatTest/probes/";
};
new BoxEnvironmentProbe() {
Enabled = "1";
refOffset = "0 0 0";
refScale = "10 10 10";
ReflectionMode = "Baked Cubemap";
position = "-0.0289133 -0.122873 1.6924";
rotation = "1 0 0 0";
scale = "10 10 10";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "079c3eaf-874e-11e9-8bbc-bdd5fc1d7642";
attenuation = "1";
};
new TSStatic() {
shapeName = "data/pbr/shapes/material_ball.dae";
playAmbient = "1";
@ -284,6 +271,19 @@ new Scene(PbrMatTestLevel) {
surface = "0.5 0.5 -0.5 0.5 -0.412576 0 -1.53859e-07 0 0 0 1 1 0 1 1";
surface = "0.5 -0.5 0.5 0.5 0.412576 0 -1.53859e-07 0 0 0 1 1 0 1 1";
};
new BoxEnvironmentProbe() {
Enabled = "1";
refOffset = "0 0 0";
refScale = "10 10 10";
ReflectionMode = "Baked Cubemap";
position = "-0.0463406 0.0380459 2.23039";
rotation = "1 0 0 0";
scale = "10 10 10";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "29579d61-9b0f-11e9-b718-be72e303d0f8";
attenuation = "1";
};
new PointLight() {
radius = "5";
isEnabled = "1";
@ -310,7 +310,7 @@ new Scene(PbrMatTestLevel) {
representedInLightmap = "0";
shadowDarkenColor = "0 0 0 -1";
includeLightmappedGeometryInShadow = "0";
position = "-0.0881653 -2.35794 1.41582";
position = "0.110554 -2.2668 1.41582";
rotation = "1 0 0 0";
canSave = "1";
canSaveDynamicFields = "1";

View file

@ -1,59 +1,5 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<EditorSettings>
<Group name="Theme">
<Setting name="tooltipDividerColor">72 70 68 255</Setting>
<Setting name="headerTextColor">236 234 232 255</Setting>
<Setting name="tabsSELColor">59 58 57 255</Setting>
<Setting name="fieldBGHLColor">72 70 68 255</Setting>
<Setting name="tooltipTextColor">255 255 255 255</Setting>
<Setting name="fieldTextColor">178 175 172 255</Setting>
<Setting name="windowBackgroundColor">32 31 30 255</Setting>
<Setting name="headerColor">50 49 48 255</Setting>
<Setting name="dividerDarkColor">17 16 15 255</Setting>
<Setting name="fieldBGColor">59 58 57 255</Setting>
<Setting name="tooltipBGColor">43 43 43 255</Setting>
<Setting name="fieldTextSELColor">240 240 240 255</Setting>
<Setting name="fieldBGSELColor">100 98 96 255</Setting>
<Setting name="tabsColor">37 36 35 255</Setting>
<Setting name="dividerLightColor">96 94 92 255</Setting>
<Setting name="fieldTextHLColor">234 232 230 255</Setting>
<Setting name="tabsHLColor">50 49 48 255</Setting>
<Setting name="dividerMidColor">50 49 48 255</Setting>
</Group>
<Group name="GuiEditor">
<Setting name="previewResolution">1024 768</Setting>
<Setting name="lastPath">tools/gui</Setting>
<Group name="EngineDevelopment">
<Setting name="showEditorProfiles">0</Setting>
<Setting name="toggleIntoEditor">0</Setting>
<Setting name="showEditorGuis">0</Setting>
</Group>
<Group name="Help">
<Setting name="documentationLocal">../../../Documentation/Official Documentation.html</Setting>
<Setting name="documentationURL">http://www.garagegames.com/products/torque-3d/documentation/user</Setting>
<Setting name="documentationReference">../../../Documentation/Torque 3D - Script Manual.chm</Setting>
</Group>
<Group name="Selection">
<Setting name="fullBox">0</Setting>
</Group>
<Group name="Snapping">
<Setting name="snap2Grid">0</Setting>
<Setting name="snapToCanvas">1</Setting>
<Setting name="snapToGuides">1</Setting>
<Setting name="sensitivity">2</Setting>
<Setting name="snapToEdges">1</Setting>
<Setting name="snapToCenters">1</Setting>
<Setting name="snapToControls">1</Setting>
<Setting name="snap2GridSize">8</Setting>
</Group>
<Group name="Rendering">
<Setting name="drawBorderLines">1</Setting>
<Setting name="drawGuides">1</Setting>
</Group>
<Group name="Library">
<Setting name="viewType">Categorized</Setting>
</Group>
</Group>
<Group name="AxisGizmo">
<Setting name="rotationSnap">15</Setting>
<Setting name="mouseRotateScalar">0.8</Setting>
@ -63,95 +9,149 @@
<Setting name="mouseScaleScalar">0.8</Setting>
<Setting name="renderInfoText">1</Setting>
<Group name="Grid">
<Setting name="renderPlane">0</Setting>
<Setting name="gridColor">255 255 255 20</Setting>
<Setting name="gridSize">10 10 10</Setting>
<Setting name="planeDim">500</Setting>
<Setting name="gridColor">255 255 255 20</Setting>
<Setting name="renderPlaneHashes">0</Setting>
<Setting name="renderPlane">0</Setting>
<Setting name="snapToGrid">0</Setting>
<Setting name="renderPlaneHashes">0</Setting>
</Group>
</Group>
<Group name="Theme">
<Setting name="tooltipDividerColor">72 70 68 255</Setting>
<Setting name="fieldTextColor">178 175 172 255</Setting>
<Setting name="fieldBGHLColor">72 70 68 255</Setting>
<Setting name="fieldTextSELColor">240 240 240 255</Setting>
<Setting name="dividerMidColor">50 49 48 255</Setting>
<Setting name="windowBackgroundColor">32 31 30 255</Setting>
<Setting name="dividerLightColor">96 94 92 255</Setting>
<Setting name="dividerDarkColor">17 16 15 255</Setting>
<Setting name="fieldBGColor">59 58 57 255</Setting>
<Setting name="tooltipBGColor">43 43 43 255</Setting>
<Setting name="tabsColor">37 36 35 255</Setting>
<Setting name="tabsHLColor">50 49 48 255</Setting>
<Setting name="headerTextColor">236 234 232 255</Setting>
<Setting name="headerColor">50 49 48 255</Setting>
<Setting name="fieldBGSELColor">100 98 96 255</Setting>
<Setting name="tabsSELColor">59 58 57 255</Setting>
<Setting name="fieldTextHLColor">234 232 230 255</Setting>
<Setting name="tooltipTextColor">255 255 255 255</Setting>
</Group>
<Group name="WorldEditor">
<Setting name="orthoFOV">50</Setting>
<Setting name="displayType">6</Setting>
<Setting name="forceLoadDAE">0</Setting>
<Setting name="dropType">screenCenter</Setting>
<Setting name="undoLimit">40</Setting>
<Setting name="currentEditor">WorldEditorInspectorPlugin</Setting>
<Setting name="forceLoadDAE">0</Setting>
<Setting name="torsionPath">AssetWork_Debug.exe</Setting>
<Setting name="orthoShowGrid">1</Setting>
<Group name="Tools">
<Setting name="objectsUseBoxCenter">1</Setting>
<Setting name="dropAtScreenCenterScalar">1</Setting>
<Setting name="snapGround">0</Setting>
<Setting name="snapSoft">0</Setting>
<Setting name="dropAtScreenCenterMax">100</Setting>
<Setting name="boundingBoxCollision">0</Setting>
<Setting name="snapSoftSize">2</Setting>
</Group>
<Group name="Color">
<Setting name="objMouseOverColor">0 255 0 255</Setting>
<Setting name="selectionBoxColor">255 255 0 255</Setting>
<Setting name="objectTextColor">255 255 255 255</Setting>
<Setting name="objSelectColor">255 0 0 255</Setting>
<Setting name="popupBackgroundColor">100 100 100 255</Setting>
<Setting name="objMouseOverSelectColor">0 0 255 255</Setting>
<Setting name="dragRectColor">255 255 0 255</Setting>
<Setting name="displayType">6</Setting>
<Setting name="orthoFOV">50</Setting>
<Setting name="dropType">screenCenter</Setting>
<Group name="ObjectIcons">
<Setting name="fadeIconsEndAlpha">0</Setting>
<Setting name="fadeIcons">1</Setting>
<Setting name="fadeIconsStartDist">8</Setting>
<Setting name="fadeIconsEndDist">20</Setting>
<Setting name="fadeIconsStartAlpha">255</Setting>
</Group>
<Group name="Grid">
<Setting name="gridSnap">0</Setting>
<Setting name="gridMinorColor">51 51 51 100</Setting>
<Setting name="gridColor">102 102 102 100</Setting>
<Setting name="gridSize">1</Setting>
<Setting name="gridMinorColor">51 51 51 100</Setting>
<Setting name="gridOriginColor">255 255 255 100</Setting>
<Setting name="gridColor">102 102 102 100</Setting>
<Setting name="gridSnap">0</Setting>
</Group>
<Group name="Images">
<Setting name="selectHandle">tools/worldEditor/images/SelectHandle</Setting>
<Setting name="defaultHandle">tools/worldEditor/images/DefaultHandle</Setting>
<Setting name="lockedHandle">tools/worldEditor/images/LockedHandle</Setting>
</Group>
<Group name="Render">
<Setting name="renderPopupBackground">1</Setting>
<Setting name="renderObjHandle">1</Setting>
<Setting name="showMousePopupInfo">1</Setting>
<Setting name="renderObjText">1</Setting>
<Setting name="renderSelectionBox">1</Setting>
</Group>
<Group name="Tools">
<Setting name="snapSoft">0</Setting>
<Setting name="snapSoftSize">2</Setting>
<Setting name="dropAtScreenCenterScalar">1</Setting>
<Setting name="objectsUseBoxCenter">1</Setting>
<Setting name="snapGround">0</Setting>
<Setting name="boundingBoxCollision">0</Setting>
<Setting name="dropAtScreenCenterMax">100</Setting>
</Group>
<Group name="Color">
<Setting name="popupBackgroundColor">100 100 100 255</Setting>
<Setting name="objMouseOverSelectColor">0 0 255 255</Setting>
<Setting name="objMouseOverColor">Lime</Setting>
<Setting name="selectionBoxColor">255 255 0 255</Setting>
<Setting name="objectTextColor">255 255 255 255</Setting>
<Setting name="dragRectColor">255 255 0 255</Setting>
<Setting name="objSelectColor">255 0 0 255</Setting>
</Group>
<Group name="Theme">
<Setting name="windowTitleBGHLColor">48 48 48 255</Setting>
<Setting name="windowTitleBGNAColor">180 180 180 255</Setting>
<Setting name="windowTitleBGColor">50 50 50 255</Setting>
<Setting name="windowTitleFontColor">215 215 215 255</Setting>
<Setting name="windowTitleFontHLColor">255 255 255 255</Setting>
</Group>
<Group name="Docs">
<Setting name="documentationURL">http://www.garagegames.com/products/torque-3d/documentation/user</Setting>
<Setting name="documentationLocal">../../../Documentation/Official Documentation.html</Setting>
<Setting name="forumURL">http://www.garagegames.com/products/torque-3d/forums</Setting>
<Setting name="documentationReference">../../../Documentation/Torque 3D - Script Manual.chm</Setting>
<Setting name="forumURL">http://www.garagegames.com/products/torque-3d/forums</Setting>
<Setting name="documentationLocal">../../../Documentation/Official Documentation.html</Setting>
</Group>
<Group name="ObjectIcons">
<Setting name="fadeIconsEndAlpha">0</Setting>
<Setting name="fadeIconsStartAlpha">255</Setting>
<Setting name="fadeIconsEndDist">20</Setting>
<Setting name="fadeIconsStartDist">8</Setting>
<Setting name="fadeIcons">1</Setting>
</Group>
<Group name="GuiEditor">
<Setting name="previewResolution">1024 768</Setting>
<Setting name="lastPath">tools/gui</Setting>
<Group name="Rendering">
<Setting name="drawGuides">1</Setting>
<Setting name="drawBorderLines">1</Setting>
</Group>
<Group name="Render">
<Setting name="renderObjHandle">1</Setting>
<Setting name="renderObjText">1</Setting>
<Setting name="showMousePopupInfo">1</Setting>
<Setting name="renderSelectionBox">1</Setting>
<Setting name="renderPopupBackground">1</Setting>
<Group name="EngineDevelopment">
<Setting name="showEditorProfiles">0</Setting>
<Setting name="showEditorGuis">0</Setting>
<Setting name="toggleIntoEditor">0</Setting>
</Group>
<Group name="Theme">
<Setting name="windowTitleFontHLColor">255 255 255 255</Setting>
<Setting name="windowTitleBGHLColor">48 48 48 255</Setting>
<Setting name="windowTitleBGColor">50 50 50 255</Setting>
<Setting name="windowTitleBGNAColor">180 180 180 255</Setting>
<Setting name="windowTitleFontColor">215 215 215 255</Setting>
<Group name="Snapping">
<Setting name="snapToGuides">1</Setting>
<Setting name="snap2GridSize">8</Setting>
<Setting name="snapToEdges">1</Setting>
<Setting name="snapToCanvas">1</Setting>
<Setting name="snapToControls">1</Setting>
<Setting name="sensitivity">2</Setting>
<Setting name="snapToCenters">1</Setting>
<Setting name="snap2Grid">0</Setting>
</Group>
<Group name="Images">
<Setting name="defaultHandle">tools/worldEditor/images/DefaultHandle</Setting>
<Setting name="selectHandle">tools/worldEditor/images/SelectHandle</Setting>
<Setting name="lockedHandle">tools/worldEditor/images/LockedHandle</Setting>
<Group name="Help">
<Setting name="documentationLocal">../../../Documentation/Official Documentation.html</Setting>
<Setting name="documentationReference">../../../Documentation/Torque 3D - Script Manual.chm</Setting>
<Setting name="documentationURL">http://www.garagegames.com/products/torque-3d/documentation/user</Setting>
</Group>
<Group name="Library">
<Setting name="viewType">Categorized</Setting>
</Group>
<Group name="Selection">
<Setting name="fullBox">0</Setting>
</Group>
</Group>
<Group name="LevelInformation">
<Setting name="levelsDirectory">data/FPSGameplay/levels</Setting>
<Group name="levels">
<Group name="BlankRoom.mis">
<Setting name="cameraSpeed">25</Setting>
</Group>
<Group name="PbrMatTest.mis">
<Setting name="cameraSpeed">5</Setting>
</Group>
</Group>
</Group>
<Group name="NavEditor">
<Setting name="SpawnClass">AIPlayer</Setting>
</Group>
<Group name="LevelInformation">
<Setting name="levelsDirectory">data/FPSGameplay/levels</Setting>
<Group name="levels">
<Group name="PbrMatTest.mis">
<Setting name="cameraSpeed">5</Setting>
</Group>
<Group name="BlankRoom.mis">
<Setting name="cameraSpeed">25</Setting>
</Group>
</Group>
</Group>
<Group name="ConvexEditor">
<Setting name="materialName">Grid_512_Orange</Setting>
</Group>