Finished current cleanup/reorg.

Temporarily disabled logic for forward render of probes to avoid data mangle. TODO: fix up forward once deferred math is locked in
Split probe modes out into distinct environmental probe objects
Removed the probes from tracking their own baked cubemap file paths and instead have a pref store it
Removed old probe shaders and materials that aren't used now.
Fixed mLastConst memory leak by removing nono line.
This commit is contained in:
Areloch 2019-02-14 00:35:22 -06:00
parent 9ec7eb999d
commit b52799bbce
18 changed files with 1024 additions and 1282 deletions

View file

@ -277,94 +277,7 @@ new CustomMaterial( AL_ParticlePointLightMaterial )
pixVersion = 3.0;
};
//Reflection probe Specular
new ShaderData( ReflectionProbeShader )
{
/*DXVertexShaderFile = "shaders/common/lighting/advanced/convexGeometryV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/reflectionProbeP.hlsl";
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/convexGeometryV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/reflectionProbeP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$colorBuffer";
samplerNames[2] = "$matInfoBuffer";
samplerNames[3] = "$cubeMap";
samplerNames[4] = "$irradianceCubemap";
samplerNames[5] = "$BRDFTexture";*/
DXVertexShaderFile = "shaders/common/lighting/advanced/farFrustumQuadV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl";
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/farFrustumQuadV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/reflectionProbeArrayP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$colorBuffer";
samplerNames[2] = "$matInfoBuffer";
samplerNames[3] = "$BRDFTexture";
samplerNames[4] = "$cubeMap";
samplerNames[5] = "$irradianceCubemap";
pixVersion = 3.0;
};
// Convex-geometry light states
new GFXStateBlockData( AL_ProbeState )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendSrcAlpha; //TODO change this to GFXBlendOne once probes are done in one pass!
blendDest = GFXBlendOne;
blendOp = GFXBlendOpAdd;
colorWriteDefined = true;
colorWriteRed = true;
colorWriteBlue = true;
colorWriteGreen = true;
colorWriteAlpha = true;
zDefined = true;
zEnable = true;
zWriteEnable = false;
zFunc = GFXCmpGreaterEqual;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint; // G-buffer
mSamplerNames[0] = "deferredBuffer";
samplerStates[1] = SamplerClampLinear;
mSamplerNames[1] = "colorBuffer";
samplerStates[2] = SamplerClampLinear;
mSamplerNames[2] = "matInfoBuffer";
mSamplerNames[3] = "BRDFTexture";
mSamplerNames[4] = "cubeMap";
mSamplerNames[5] = "irradianceCubemap";
cullDefined = true;
cullMode = GFXCullCW;
stencilDefined = true;
stencilEnable = true;
stencilFailOp = GFXStencilOpKeep;
stencilZFailOp = GFXStencilOpKeep;
stencilPassOp = GFXStencilOpKeep;
stencilFunc = GFXCmpLess;
stencilRef = 0;
};
new CustomMaterial( ReflectionProbeMaterial )
{
shader = ReflectionProbeShader;
stateBlock = AL_ProbeState;
sampler["deferredBuffer"] = "#deferred";
sampler["matInfoBuffer"] = "#matinfo";
pixVersion = 3.0;
};
//Skylight
//Probe Processing
new ShaderData( IrradianceShader )
{
DXVertexShaderFile = "shaders/common/lighting/advanced/cubemapV.hlsl";
@ -391,68 +304,6 @@ new ShaderData( PrefiterCubemapShader )
pixVersion = 3.0;
};
new ShaderData( SkyLightShader )
{
DXVertexShaderFile = "shaders/common/lighting/advanced/convexGeometryV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/skylightP.hlsl";
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/convexGeometryV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/skylightP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$matInfoBuffer";
samplerNames[2] = "$colorBuffer";
samplerNames[3] = "$cubeMap";
samplerNames[4] = "$irradianceCubemap";
samplerNames[5] = "$BRDFTexture";
pixVersion = 3.0;
};
new CustomMaterial( SkyLightMaterial )
{
shader = SkyLightShader;
stateBlock = AL_ProbeState;
sampler["deferredBuffer"] = "#deferred";
sampler["matInfoBuffer"] = "#matinfo";
sampler["colorBuffer"] = "#color";
pixVersion = 3.0;
};
new ShaderData( ReflectionProbeArrayShader )
{
DXVertexShaderFile = "shaders/common/lighting/advanced/reflectionProbeArrayV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl";
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/reflectionProbeArrayV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/reflectionProbeArrayP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$colorBuffer";
samplerNames[2] = "$matInfoBuffer";
samplerNames[3] = "$BRDFTexture";
samplerNames[4] = "$cubeMap";
samplerNames[5] = "$irradianceCubemap";
pixVersion = 3.0;
};
new CustomMaterial( ReflectionProbeArrayMaterial )
{
shader = ReflectionProbeArrayShader;
stateBlock = AL_ProbeState;
sampler["deferredBuffer"] = "#deferred";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
sampler["BRDFTexture"] = "core/art/pbr/brdfTexture.dds";
pixVersion = 3.0;
};
//
//
singleton ShaderData( PFX_ReflectionProbeArray )
{
@ -461,8 +312,6 @@ singleton ShaderData( PFX_ReflectionProbeArray )
//OGLVertexShaderFile = "shaders/common/postFx/gl//postFxV.glsl";
//OGLPixelShaderFile = "shaders/common/postFx/gl/passthruP.glsl";
//samplerNames[0] = "$inputTex";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$colorBuffer";
@ -476,10 +325,6 @@ singleton ShaderData( PFX_ReflectionProbeArray )
singleton GFXStateBlockData( PFX_ReflectionProbeArrayStateBlock )
{
//zDefined = true;
//zEnable = false;
//zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
};
@ -497,15 +342,11 @@ singleton PostEffect( reflectionProbeArrayPostFX )
shader = PFX_ReflectionProbeArray;
stateBlock = PFX_ReflectionProbeArrayStateBlock;
//texture[0] = "#highlight";
//texture[1] = "$backBuffer";
texture[0] = "#deferred";
texture[1] = "#color";
texture[2] = "#matinfo";
texture[3] = "core/art/pbr/brdfTexture.dds";
//texture[4] = "$cubeMap";
//texture[5] = "$irradianceCubemap";
target = "AL_FormatToken";
};

View file

@ -89,6 +89,7 @@ function clientCmdMissionStartPhase3(%seq,%missionName)
echo ("*** Phase 3: Mission Lighting");
$MSeq = %seq;
$Client::MissionFile = %missionName;
$pref::ReflectionProbes::CurrentLevelPath = filePath($Client::MissionFile) @ "/" @ fileBase($Client::MissionFile) @ "/probes/";
// Need to light the mission before we are ready.
// The sceneLightingComplete function will complete the handshake

View file

@ -39,11 +39,9 @@ new SimGroup(MissionGroup) {
};
new Skylight() {
enabled = "0";
ProbeShape = "Box";
radius = "10";
posOffset = "0 0 0";
ReflectionMode = "Static Cubemap";
reflectionPath = "levels/AProbeTest/probes/";
StaticCubemap = "sky_day_hdr_cubemap";
Bake = "0";
position = "0 0 0";
@ -52,6 +50,8 @@ new SimGroup(MissionGroup) {
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "e4c73467-4089-11e8-b478-cd227cd60b8b";
ProbeShape = "Box";
reflectionPath = "levels/AProbeTest/probes/";
};
new SimGroup(PlayerDropPoints) {
canSave = "1";
@ -126,15 +126,13 @@ new SimGroup(MissionGroup) {
canSaveDynamicFields = "1";
direction = "1 1 -1";
};
new ReflectionProbe() {
new BoxEnvironmentProbe() {
enabled = "1";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "0 0.280415 4.80432";
position = "0 0 4";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
@ -144,6 +142,65 @@ new SimGroup(MissionGroup) {
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
ProbeShape = "Box";
reflectionPath = "levels/probeTest/probes/";
SkyColor = "0.5 0.5 1 1";
};
new BoxEnvironmentProbe() {
enabled = "1";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
Bake = "0";
position = "-10 8 4";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "f281a5ff-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
reflectionPath = "levels/probeTest/probes/";
SkyColor = "0.5 0.5 1 1";
};
new BoxEnvironmentProbe() {
enabled = "1";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
Bake = "0";
position = "-10 0 4";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "e9c2eed2-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
reflectionPath = "levels/probeTest/probes/";
SkyColor = "0.5 0.5 1 1";
};
new BoxEnvironmentProbe() {
enabled = "1";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
Bake = "0";
position = "-10 -8 4";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "f4db4dde-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
reflectionPath = "levels/probeTest/probes/";
SkyColor = "0.5 0.5 1 1";
};
new ConvexShape() {
@ -313,65 +370,5 @@ new SimGroup(MissionGroup) {
canSave = "1";
canSaveDynamicFields = "1";
};
new ReflectionProbe() {
enabled = "1";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "-9.34007 0.48281 2.5031";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "e9c2eed2-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
SkyColor = "0.5 0.5 1 1";
};
new ReflectionProbe() {
enabled = "1";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "-10.1924 8.78742 2.18272";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "f281a5ff-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
SkyColor = "0.5 0.5 1 1";
};
new ReflectionProbe() {
enabled = "0";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "8.24487 -3.37372 2.18272";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "f4db4dde-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
SkyColor = "0.5 0.5 1 1";
};
};
//--- OBJECT WRITE END ---

View file

@ -1,52 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../hlslStructs.hlsl"
#include "../../shaderModel.hlsl"
#include "../../torque.hlsl"
struct GFXVertexPT
{
float3 pos : POSITION;
float4 uv : TEXCOORD1;
};
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 uv0 : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
uniform float4 rtParams0;
uniform float4x4 worldViewOnly;
ConnectData main( GFXVertexPT IN )
{
ConnectData OUT;
OUT.hpos = float4(IN.pos,1.0);
OUT.uv0 = float4(viewportCoordToRenderTarget( IN.uv, rtParams0 ),0,0);
OUT.vsEyeDir = mul(worldViewOnly, float4(IN.pos, 1.0));
return OUT;
}

View file

@ -1,171 +0,0 @@
#include "../../shaderModelAutoGen.hlsl"
#include "farFrustumQuad.hlsl"
#include "../../lighting.hlsl"
#include "../../torque.hlsl"
struct ConvexConnectP
{
float4 pos : TORQUE_POSITION;
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0);
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 1);
TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 2);
TORQUE_UNIFORM_SAMPLERCUBE(cubeMap, 3);
TORQUE_UNIFORM_SAMPLERCUBE(irradianceCubemap, 4);
TORQUE_UNIFORM_SAMPLER2D(BRDFTexture, 5);
uniform float cubeMips;
uniform float4 rtParams0;
uniform float3 probeWSPos;
uniform float3 probeLSPos;
uniform float4 vsFarPlane;
uniform float radius;
uniform float2 attenuation;
uniform float4x4 worldToObj;
uniform float4x4 cameraToWorld;
uniform float3 eyePosWorld;
uniform float3 bbMin;
uniform float3 bbMax;
uniform float useSphereMode;
#define MAX_PROBES 50
uniform float numProbes;
uniform float3 inProbePosArray[MAX_PROBES];
// Box Projected IBL Lighting
// Based on: http://www.gamedev.net/topic/568829-box-projected-cubemap-environment-mapping/
// and https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
float3 boxProject(float3 wsPosition, float3 reflectDir, float3 boxWSPos, float3 boxMin, float3 boxMax)
{
float3 nrdir = reflectDir;
float3 offset = wsPosition;
float3 plane1vec = (boxMax - offset) / nrdir;
float3 plane2vec = (boxMin - offset) / nrdir;
float3 furthestPlane = max(plane1vec, plane2vec);
float dist = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
float3 posonbox = offset + nrdir * dist;
return posonbox - boxWSPos;
}
float3 iblBoxSpecular(float3 normal, float3 wsPos, float roughness, float3 surfToEye,
TORQUE_SAMPLER2D(brdfTexture),
TORQUE_SAMPLERCUBE(radianceCube),
float3 boxPos,
float3 boxMin,
float3 boxMax)
{
float ndotv = clamp(dot(normal, surfToEye), 0.0, 1.0);
// BRDF
float2 brdf = TORQUE_TEX2DLOD(brdfTexture, float4(roughness, ndotv,0.0,0.0)).xy;
// Radiance (Specular)
float maxmip = pow(cubeMips+1,2);
float lod = roughness*maxmip;
float3 r = reflect(surfToEye, normal);
float3 cubeR = normalize(r);
cubeR = boxProject(wsPos, cubeR, boxPos, boxMin, boxMax);
float3 radiance = TORQUE_TEXCUBELOD(radianceCube, float4(cubeR, lod)).xyz * (brdf.x + brdf.y);
return radiance;
}
float defineBoxSpaceInfluence(float3 surfPosWS, float3 probePos, float radius, float atten)
{
float3 surfPosLS = mul( worldToObj, float4(surfPosWS,1.0)).xyz;
float3 boxMinLS = probePos-(float3(1,1,1)*radius);
float3 boxMaxLS = probePos+(float3(1,1,1)*radius);
float boxOuterRange = length(boxMaxLS - boxMinLS);
float boxInnerRange = boxOuterRange / atten;
float3 localDir = float3(abs(surfPosLS.x), abs(surfPosLS.y), abs(surfPosLS.z));
localDir = (localDir - boxInnerRange) / (boxOuterRange - boxInnerRange);
return max(localDir.x, max(localDir.y, localDir.z)) * -1;
}
float4 main( ConvexConnectP IN ) : SV_TARGET
{
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
//eye ray WS/LS
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
//unpack normal and linear depth
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
//create surface
Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
float blendVal = 1.0;
/*if(useSphereMode)
{
float3 L = probeWSPos - surface.P;
blendVal = 1.0-length(L)/radius;
clip(blendVal);
}
else
{
float tempAttenVal = 3.5;
blendVal = defineBoxSpaceInfluence(surface.P, probeWSPos, radius, tempAttenVal);
clip(blendVal);
float compression = 0.05;
blendVal=(1.0-compression)+blendVal*compression;
}*/
float3 surfToEye = normalize(surface.P - eyePosWorld);
float3 irradiance = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).xyz;
float3 specular = iblBoxSpecular(surface.N, surface.P, surface.roughness, surfToEye, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture), TORQUE_SAMPLERCUBE_MAKEARG(cubeMap), probeWSPos, bbMin, bbMax);
int i;
irradiance = float3(0,0,0);
float blendSum = 0.00001;
for(i=0; i < numProbes; i++)
{
float3 probeWS = inProbePosArray[i];
float3 L = probeWS - surface.P;
blendVal = 1.0-length(L)/radius;
blendVal = max(0,blendVal);
irradiance += float3(blendVal,blendVal,blendVal);
specular = irradiance;
blendSum += blendVal;
}
//irradiance /= blendSum;
//specular /= blendSum;
blendSum /= numProbes;
//render into the bound space defined above
//
//float3 irradiance = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).xyz;
//float3 specular = iblBoxSpecular(surface.N, surface.P, surface.roughness, surfToEye, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture), TORQUE_SAMPLERCUBE_MAKEARG(cubeMap), probeWSPos, bbMin, bbMax);
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
specular *= F;
//energy conservation
float3 kD = 1.0.xxx - F;
kD *= 1.0 - surface.metalness;
//final diffuse color
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
return float4(diffuse + specular * surface.ao, blendSum);
}

View file

@ -1,62 +0,0 @@
#include "../../shaderModelAutoGen.hlsl"
#include "farFrustumQuad.hlsl"
#include "../../lighting.hlsl"
#include "../../torque.hlsl"
struct ConvexConnectP
{
float4 pos : TORQUE_POSITION;
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0);
TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 1);
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 2);
TORQUE_UNIFORM_SAMPLERCUBE(cubeMap, 3);
TORQUE_UNIFORM_SAMPLERCUBE(irradianceCubemap, 4);
TORQUE_UNIFORM_SAMPLER2D(BRDFTexture, 5);
uniform float4 rtParams0;
uniform float4 vsFarPlane;
uniform float4x4 cameraToWorld;
uniform float3 eyePosWorld;
float3 iblSpecular(in Surface surface, float3 F)
{
const float MAX_REFLECTION_LOD = 4.0;
float3 prefilteredColor = TORQUE_TEXCUBELOD(cubeMap, float4(surface.R, surface.roughness * MAX_REFLECTION_LOD)).rgb;
float2 envBRDF = TORQUE_TEX2D(BRDFTexture, float2(surface.NdotV, surface.roughness)).rg;
return prefilteredColor * (F * envBRDF.x + envBRDF.y);
}
float4 main( ConvexConnectP IN ) : SV_TARGET
{
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
//eye ray WS/LS
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
//unpack normal and linear depth
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
//create surface
Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
float3 irradiance = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).rgb;
float3 specular = iblSpecular(surface, F);
//energy conservation
float3 kD = 1.0.xxx - F;
kD *= 1.0 - surface.metalness;
//final diffuse color
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
return float4(diffuse + specular * surface.ao, 0);
}

View file

@ -56,7 +56,8 @@ function EWCreatorWindow::init( %this )
%this.registerMissionObject( "PointLight", "Point Light" );
%this.registerMissionObject( "SpotLight", "Spot Light" );
%this.registerMissionObject( "ReflectionProbe", "Reflection Probe" );
%this.registerMissionObject( "BoxEnvironmentProbe", "Box Environment Probe" );
%this.registerMissionObject( "SphereEnvironmentProbe", "Sphere Environment Probe" );
%this.registerMissionObject( "Skylight", "Skylight" );
%this.registerMissionObject( "GroundCover", "Ground Cover" );

View file

@ -64,18 +64,5 @@ function EditorLightingMenu::onMenuSelect( %this )
function updateReflectionProbes()
{
/*%probeIds = parseMissionGroupForIds("ReflectionProbe", "");
%probeCount = getWordCount(%probeIds);
for(%i=0; %i < %probeCount; %i++)
{
%probe = getWord(%probeIds, %i);
%path = filePath($Server::MissionFile) @ "/" @ fileBase($Server::MissionFile) @ "/probes/";
%probe.bake(%path, 64);
}
EWorldEditor.isDirty = true;*/
Canvas.pushDialog(ProbeBakeDlg);
Canvas.pushDialog(ProbeBakeDlg);
}

View file

@ -16,14 +16,16 @@ function ProbeBakeDlg::onWake(%this)
function ProbeBakeDlg_RunBake::onClick(%this)
{
%probeIds = parseMissionGroupForIds("ReflectionProbe", "");
%boxProbeIds = parseMissionGroupForIds("BoxEnvironmentProbe", "");
%sphereProbeIds = parseMissionGroupForIds("SphereEnvironmentProbe", "");
%skylightIds = parseMissionGroupForIds("Skylight", "");
%probeIds = rtrim(ltrim(%boxProbeIds SPC %sphereProbeIds));
%probeIds = rtrim(ltrim(%probeIds SPC %skylightIds));
%probeCount = getWordCount(%probeIds);
%numIter = ProbeBakeDlg_NumIterTxt.getText();
%resolution = ProbeBakeDlg_ProbeResList.getText();
$pref::ReflectionProbes::BakeResolution = ProbeBakeDlg_ProbeResList.getText();
%progressStep = 100 / (%numIter * %probeCount);
%currentProgressValue = 0;
@ -32,17 +34,17 @@ function ProbeBakeDlg_RunBake::onClick(%this)
for(%iter=0; %iter < %numIter; %iter++)
{
%renderWithProbes = false;
$pref::ReflectionProbes::RenderWithProbes = false;
if(%iter != 0)
%renderWithProbes = true;
$pref::ReflectionProbes::RenderWithProbes = true;
for(%i=0; %i < %probeCount; %i++)
{
%probe = getWord(%probeIds, %i);
%path = filePath($Server::MissionFile) @ "/" @ fileBase($Server::MissionFile) @ "/probes/";
%probe.bake(%path, %resolution, %renderWithProbes);
$pref::ReflectionProbes::CurrentLevelPath = filePath($Server::MissionFile) @ "/" @ fileBase($Server::MissionFile) @ "/probes/";
ProbeBin.bakeProbe(%probe);
%currentProgressValue += %progressStep;
ProbeBakeDlg_Progress.setValue(%currentProgressValue);