Initial implementation of the new Base Game Template and some starting modules.

This makes some tweaks to the engine to support this, specifically, it tweaks the hardcoded shaderpaths to defer to a pref variable, so none of the shader paths are hardcoded.

Also tweaks how post effects read in texture files, removing a bizzare filepath interpretation choice, where if the file path didn't start with "/" it forcefully appended the script's file path. This made it impossible to have images not in the same dir as the script file defining the post effect.

This was changed and the existing template's post effects tweaked for now to just add "./" to those few paths impacted, as well as the perf vars to support the non-hardcoded shader paths in the engine.
This commit is contained in:
Areloch 2017-02-24 02:40:56 -06:00
parent 5c8a82180b
commit 1ed8b05169
1572 changed files with 146699 additions and 85 deletions

View file

@ -0,0 +1,112 @@
// The general flow of a gane - server's creation, loading and hosting clients, and then destruction is as follows:
// First, a client will always create a server in the event that they want to host a single player
// game. Torque3D treats even single player connections as a soft multiplayer game, with some stuff
// in the networking short-circuited to sidestep around lag and packet transmission times.
// initServer() is called, loading the default server scripts.
// After that, if this is a dedicated server session, initDedicated() is called, otherwise initClient is called
// to prep a playable client session.
// When a local game is started - a listen server - via calling StartGame() a server is created and then the client is
// connected to it via createAndConnectToLocalServer().
function ClientServer::create( %this )
{
echo("\n--------- Initializing Directory: scripts ---------");
exec( "./scripts/client/client.cs" );
exec( "./scripts/server/server.cs" );
$Game::MissionGroup = "MissionGroup";
initServer();
%dbList = new ArrayObject(DatablockFilesList);
// Start up in either client, or dedicated server mode
if ($Server::Dedicated)
{
initDedicated();
}
else
{
initClient();
}
}
function ClientServer::destroy( %this )
{
// Ensure that we are disconnected and/or the server is destroyed.
// This prevents crashes due to the SceneGraph being deleted before
// the objects it contains.
if ($Server::Dedicated)
destroyServer();
else
disconnect();
// Destroy the physics plugin.
physicsDestroy();
sfxShutdown();
echo("Exporting client prefs");
%prefPath = getPrefpath();
export("$pref::*", %prefPath @ "/clientPrefs.cs", false);
echo("Exporting server prefs");
export("$Pref::Server::*", %prefPath @ "/serverPrefs.cs", false);
BanList::Export(%prefPath @ "/banlist.cs");
}
//-----------------------------------------------------------------------------
function StartGame( %mission, %hostingType )
{
if( %mission $= "" )
{
%id = CL_levelList.getSelectedId();
%mission = getField(CL_levelList.getRowTextById(%id), 1);
//error("Cannot start a level with no level selected!");
}
if (%hostingType !$= "")
{
%serverType = %hostingType;
}
else
{
if ($pref::HostMultiPlayer)
%serverType = "MultiPlayer";
else
%serverType = "SinglePlayer";
}
// Show the loading screen immediately.
if ( isObject( LoadingGui ) )
{
Canvas.setContent("LoadingGui");
LoadingProgress.setValue(1);
LoadingProgressTxt.setValue("LOADING MISSION FILE");
Canvas.repaint();
}
createAndConnectToLocalServer( %serverType, %mission );
}
function JoinGame( %serverIndex )
{
// The server info index is stored in the row along with the
// rest of displayed info.
if( setServerInfo( %serverIndex ) )
{
Canvas.setContent("LoadingGui");
LoadingProgress.setValue(1);
LoadingProgressTxt.setValue("WAITING FOR SERVER");
Canvas.repaint();
%conn = new GameConnection(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);
%conn.connect($ServerInfo::Address);
}
}

View file

@ -0,0 +1,9 @@
<ModuleDefinition
ModuleId="ClientServer"
VersionId="1"
Description="Default module for the game."
ScriptFile="ClientServer.cs"
CreateFunction="create"
DestroyFunction="destroy"
Group="Game">
</ModuleDefinition>

View file

@ -0,0 +1,29 @@
function initClient()
{
echo("\n--------- Initializing " @ $appName @ ": Client Scripts ---------");
// Make sure this variable reflects the correct state.
$Server::Dedicated = false;
// Game information used to query the master server
$Client::GameTypeQuery = $appName;
$Client::MissionTypeQuery = "Any";
exec( "data/clientServer/scripts/client/message.cs" );
exec( "data/clientServer/scripts/client/connectionToServer.cs" );
exec( "data/clientServer/scripts/client/levelDownload.cs" );
exec( "data/clientServer/scripts/client/levelLoad.cs" );
//load prefs
%prefPath = getPrefpath();
if ( isFile( %prefPath @ "/clientPrefs.cs" ) )
exec( %prefPath @ "/clientPrefs.cs" );
else
exec( "data/defaults.cs" );
loadMaterials();
// Copy saved script prefs into C++ code.
setDefaultFov( $pref::Player::defaultFov );
setZoomSpeed( $pref::Player::zoomSpeed );
}

View file

@ -0,0 +1,130 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Functions dealing with connecting to a server
//----------------------------------------------------------------------------
// GameConnection client callbacks
//----------------------------------------------------------------------------
// Called on the new connection object after connect() succeeds.
function GameConnection::onConnectionAccepted(%this)
{
// Startup the physX world on the client before any
// datablocks and objects are ghosted over.
physicsInitWorld( "client" );
}
function GameConnection::initialControlSet(%this)
{
echo ("*** Initial Control Object");
// The first control object has been set by the server
// and we are now ready to go.
// first check if the editor is active
if (!isToolBuild() || !isMethod("Editor", "checkActiveLoadDone") || !Editor::checkActiveLoadDone())
{
if (Canvas.getContent() != PlayGui.getId())
Canvas.setContent(PlayGui);
}
}
function GameConnection::onControlObjectChange(%this)
{
echo ("*** Control Object Changed");
// Reset the current FOV to match the new object
// and turn off any current zoom.
resetCurrentFOV();
turnOffZoom();
}
function GameConnection::onConnectionError(%this, %msg)
{
// General connection error, usually raised by ghosted objects
// initialization problems, such as missing files. We'll display
// the server's connection error message.
disconnectedCleanup();
MessageBoxOK( "DISCONNECT", $ServerConnectionErrorMessage @ " (" @ %msg @ ")" );
}
//-----------------------------------------------------------------------------
// Server connection error
//-----------------------------------------------------------------------------
addMessageCallback( 'MsgConnectionError', handleConnectionErrorMessage );
function handleConnectionErrorMessage(%msgType, %msgString, %msgError)
{
// On connect the server transmits a message to display if there
// are any problems with the connection. Most connection errors
// are game version differences, so hopefully the server message
// will tell us where to get the latest version of the game.
$ServerConnectionErrorMessage = %msgError;
}
//-----------------------------------------------------------------------------
// Disconnect
//-----------------------------------------------------------------------------
function disconnect()
{
// We need to stop the client side simulation
// else physics resources will not cleanup properly.
physicsStopSimulation( "client" );
// Delete the connection if it's still there.
if (isObject(ServerConnection))
ServerConnection.delete();
disconnectedCleanup();
// Call destroyServer in case we're hosting
destroyServer();
}
function disconnectedCleanup()
{
// End mission, if it's running.
if( $Client::missionRunning )
clientEndMission();
// Disable mission lighting if it's going, this is here
// in case we're disconnected while the mission is loading.
$lightingMission = false;
$sceneLighting::terminateLighting = true;
// Back to the launch screen
if (isObject( MainMenuGui ))
Canvas.setContent( MainMenuGui );
// Before we destroy the client physics world
// make sure all ServerConnection objects are deleted.
if(isObject(ServerConnection))
{
ServerConnection.deleteAllObjects();
}
// We can now delete the client physics simulation.
physicsDestroyWorld( "client" );
}

View file

@ -0,0 +1,185 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Mission Loading
// The client portion of the client/server mission loading process
//-----------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Loading Phases:
// Phase 1: Transmit Datablocks
// Transmit targets
// Phase 2: Transmit Ghost Objects
// Phase 3: Start Game
//
// The server invokes the client MissionStartPhase[1-3] function to request
// permission to start each phase. When a client is ready for a phase,
// it responds with MissionStartPhase[1-3]Ack.
//----------------------------------------------------------------------------
// Phase 1
//----------------------------------------------------------------------------
function clientCmdMissionStartPhase1(%seq, %missionName)
{
// These need to come after the cls.
echo ("*** New Mission: " @ %missionName);
echo ("*** Phase 1: Download Datablocks & Targets");
//Prep the postFX stuff
// Load the post effect presets for this mission.
%path = filePath( %missionName ) @ "/" @ fileBase( %missionName ) @ $PostFXManager::fileExtension;
if ( isScriptFile( %path ) )
{
postFXManager::loadPresetHandler( %path );
}
else
{
PostFXManager::settingsApplyDefaultPreset();
}
onMissionDownloadPhase("LOADING DATABLOCKS");
commandToServer('MissionStartPhase1Ack', %seq);
}
function onDataBlockObjectReceived(%index, %total)
{
onMissionDownloadProgress(%index / %total);
}
//----------------------------------------------------------------------------
// Phase 2
//----------------------------------------------------------------------------
function clientCmdMissionStartPhase2(%seq,%missionName)
{
onPhaseComplete();
echo ("*** Phase 2: Download Ghost Objects");
onMissionDownloadPhase("LOADING OBJECTS");
commandToServer('MissionStartPhase2Ack', %seq);
}
function onGhostAlwaysStarted(%ghostCount)
{
$ghostCount = %ghostCount;
$ghostsRecvd = 0;
}
function onGhostAlwaysObjectReceived()
{
$ghostsRecvd++;
onMissionDownloadProgress($ghostsRecvd / $ghostCount);
}
//----------------------------------------------------------------------------
// Phase 3
//----------------------------------------------------------------------------
function clientCmdMissionStartPhase3(%seq,%missionName)
{
onPhaseComplete();
StartClientReplication();
StartFoliageReplication();
// Load the static mission decals.
if(isFile(%missionName @ ".decals"))
decalManagerLoad( %missionName @ ".decals" );
echo ("*** Phase 3: Mission Lighting");
$MSeq = %seq;
$Client::MissionFile = %missionName;
// Need to light the mission before we are ready.
// The sceneLightingComplete function will complete the handshake
// once the scene lighting is done.
if (lightScene("sceneLightingComplete", ""))
{
echo("Lighting mission....");
schedule(1, 0, "updateLightingProgress");
onMissionDownloadPhase("LIGHTING MISSION");
$lightingMission = true;
}
}
function updateLightingProgress()
{
onMissionDownloadProgress($SceneLighting::lightingProgress);
if ($lightingMission)
$lightingProgressThread = schedule(1, 0, "updateLightingProgress");
}
function sceneLightingComplete()
{
echo("Mission lighting done");
$lightingMission = false;
onPhaseComplete("STARTING MISSION");
// The is also the end of the mission load cycle.
commandToServer('MissionStartPhase3Ack', $MSeq);
}
//----------------------------------------------------------------------------
// Helper functions
//----------------------------------------------------------------------------
function connect(%server)
{
%conn = new GameConnection(ServerConnection);
RootGroup.add(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);
%conn.connect(%server);
}
function onMissionDownloadPhase(%phase)
{
if ( !isObject( LoadingProgress ) )
return;
LoadingProgress.setValue(0);
LoadingProgressTxt.setValue(%phase);
Canvas.repaint();
}
function onMissionDownloadProgress(%progress)
{
if ( !isObject( LoadingProgress ) )
return;
LoadingProgress.setValue(%progress);
Canvas.repaint(33);
}
function onPhaseComplete(%text)
{
if ( !isObject( LoadingProgress ) )
return;
if(%text !$= "")
LoadingProgressTxt.setValue(%text);
LoadingProgress.setValue( 1 );
Canvas.repaint();
}

View file

@ -0,0 +1,92 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Whether the local client is currently running a mission.
$Client::missionRunning = false;
// Sequence number for currently running mission.
$Client::missionSeq = -1;
// Called when mission is started.
function clientStartMission()
{
// The client recieves a mission start right before
// being dropped into the game.
physicsStartSimulation( "client" );
// Start game audio effects channels.
AudioChannelEffects.play();
// Create client mission cleanup group.
new SimGroup( ClientMissionCleanup );
// Done.
$Client::missionRunning = true;
}
// Called when mission is ended (either through disconnect or
// mission end client command).
function clientEndMission()
{
// Stop physics simulation on client.
physicsStopSimulation( "client" );
// Stop game audio effects channels.
AudioChannelEffects.stop();
// Delete all the decals.
decalManagerClear();
// Delete client mission cleanup group.
if( isObject( ClientMissionCleanup ) )
ClientMissionCleanup.delete();
clearClientPaths();
// Done.
$Client::missionRunning = false;
}
//----------------------------------------------------------------------------
// Mission start / end events sent from the server
//----------------------------------------------------------------------------
function clientCmdMissionStart(%seq)
{
clientStartMission();
$Client::missionSeq = %seq;
}
function clientCmdMissionEnd( %seq )
{
if( $Client::missionRunning && $Client::missionSeq == %seq )
{
clientEndMission();
$Client::missionSeq = -1;
}
}

View file

@ -0,0 +1,94 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Functions that process commands sent from the server.
// Game event descriptions, which may or may not include text messages, can be
// sent using the message* functions in core/scripts/server/message.cs. Those
// functions do commandToClient with the tag ServerMessage, which invokes the
// function below.
// For ServerMessage messages, the client can install callbacks that will be
// run, according to the "type" of the message.
function clientCmdServerMessage(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
{
// Get the message type; terminates at any whitespace.
%tag = getWord(%msgType, 0);
// First see if there is a callback installed that doesn't have a type;
// if so, that callback is always executed when a message arrives.
for (%i = 0; (%func = $MSGCB["", %i]) !$= ""; %i++) {
call(%func, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
}
// Next look for a callback for this particular type of ServerMessage.
if (%tag !$= "") {
for (%i = 0; (%func = $MSGCB[%tag, %i]) !$= ""; %i++) {
call(%func, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
}
}
}
// Called by the client to install a callback for a particular type of
// ServerMessage.
function addMessageCallback(%msgType, %func)
{
for (%i = 0; (%afunc = $MSGCB[%msgType, %i]) !$= ""; %i++) {
// If it already exists as a callback for this type,
// nothing to do.
if (%afunc $= %func) {
return;
}
}
// Set it up.
$MSGCB[%msgType, %i] = %func;
}
// The following is the callback that will be executed for every ServerMessage,
// because we're going to install it without a specified type. Any type-
// specific callbacks will be executed afterward.
// This just invokes onServerMessage, which can be overridden by the game
function onServerMessage(%a, %b, %c, %d, %e, %f, %g, %h, %i)
{
echo("onServerMessage: ");
if(%a !$= "") echo(" +- a: " @ %a);
if(%b !$= "") echo(" +- b: " @ %b);
if(%c !$= "") echo(" +- c: " @ %c);
if(%d !$= "") echo(" +- d: " @ %d);
if(%e !$= "") echo(" +- e: " @ %e);
if(%f !$= "") echo(" +- f: " @ %f);
if(%g !$= "") echo(" +- g: " @ %g);
if(%h !$= "") echo(" +- h: " @ %h);
if(%i !$= "") echo(" +- i: " @ %i);
}
function defaultMessageCallback(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
{
onServerMessage(detag(%msgString));
}
// Register that default message handler now.
addMessageCallback("", defaultMessageCallback);

View file

@ -0,0 +1,40 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ServerPlay2D(%profile)
{
// Play the given sound profile on every client.
// The sounds will be transmitted as an event, not attached to any object.
for(%idx = 0; %idx < ClientGroup.getCount(); %idx++)
ClientGroup.getObject(%idx).play2D(%profile);
}
function ServerPlay3D(%profile,%transform)
{
// Play the given sound profile at the given position on every client
// The sound will be transmitted as an event, not attached to any object.
for(%idx = 0; %idx < ClientGroup.getCount(); %idx++)
ClientGroup.getObject(%idx).play3D(%profile,%transform);
}

View file

@ -0,0 +1,35 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Misc. server commands avialable to clients
//-----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Debug commands
//----------------------------------------------------------------------------
function serverCmdNetSimulateLag( %client, %msDelay, %packetLossPercent )
{
if ( %client.isAdmin )
%client.setSimulatedNetParams( %packetLossPercent / 100.0, %msDelay );
}

View file

@ -0,0 +1,161 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// This script function is called before a client connection
// is accepted. Returning "" will accept the connection,
// anything else will be sent back as an error to the client.
// All the connect args are passed also to onConnectRequest
//
function GameConnection::onConnectRequest( %client, %netAddress, %name )
{
echo("Connect request from: " @ %netAddress);
if($Server::PlayerCount >= $pref::Server::MaxPlayers)
return "CR_SERVERFULL";
return "";
}
//-----------------------------------------------------------------------------
// This script function is the first called on a client accept
function GameConnection::onConnect( %this, %clientData )
{
// Send down the connection error info, the client is responsible for
// displaying this message if a connection error occurs.
messageClient(%this, 'MsgConnectionError', "", $Pref::Server::ConnectionError);
// Send mission information to the client
sendLoadInfoToClient(%this);
// Simulated client lag for testing...
// %client.setSimulatedNetParams(0.1, 30);
// Get the client's unique id:
// %authInfo = %client.getAuthInfo();
// %client.guid = getField(%authInfo, 3);
%this.guid = 0;
addToServerGuidList(%this.guid);
// Set admin status
if (%this.getAddress() $= "local")
{
%this.isAdmin = true;
%this.isSuperAdmin = true;
}
else
{
%this.isAdmin = false;
%this.isSuperAdmin = false;
}
echo("CADD: "@ %this @" "@ %this.getAddress());
// If the mission is running, go ahead download it to the client
if ($missionRunning)
{
%this.loadMission();
}
else if ($Server::LoadFailMsg !$= "")
{
messageClient(%this, 'MsgLoadFailed', $Server::LoadFailMsg);
}
%this.connectData = %clientData;
$Server::PlayerCount++;
}
//-----------------------------------------------------------------------------
// A player's name could be obtained from the auth server, but for
// now we use the one passed from the client.
// %realName = getField( %authInfo, 0 );
//
function GameConnection::setPlayerName(%client,%name)
{
%client.sendGuid = 0;
// Minimum length requirements
%name = trim( strToPlayerName( %name ) );
if ( strlen( %name ) < 3 )
%name = "Poser";
// Make sure the alias is unique, we'll hit something eventually
if (!isNameUnique(%name))
{
%isUnique = false;
for (%suffix = 1; !%isUnique; %suffix++) {
%nameTry = %name @ "." @ %suffix;
%isUnique = isNameUnique(%nameTry);
}
%name = %nameTry;
}
// Tag the name with the "smurf" color:
%client.nameBase = %name;
%client.playerName = addTaggedString("\cp\c8" @ %name @ "\co");
}
function isNameUnique(%name)
{
%count = ClientGroup.getCount();
for ( %i = 0; %i < %count; %i++ )
{
%test = ClientGroup.getObject( %i );
%rawName = stripChars( detag( getTaggedString( %test.playerName ) ), "\cp\co\c6\c7\c8\c9" );
if ( strcmp( %name, %rawName ) == 0 )
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// This function is called when a client drops for any reason
//
function GameConnection::onDrop(%client, %reason)
{
if($missionRunning)
theLevelInfo.onClientLeaveGame();
removeFromServerGuidList( %client.guid );
$Server::PlayerCount--;
}
//-----------------------------------------------------------------------------
function GameConnection::startMission(%this)
{
// Inform the client the mission starting
commandToClient(%this, 'MissionStart', $missionSequence);
}
function GameConnection::endMission(%this)
{
// Inform the client the mission is done. Note that if this is
// called as part of the server destruction routine, the client will
// actually never see this comment since the client connection will
// be destroyed before another round of command processing occurs.
// In this case, the client will only see the disconnect from the server
// and should manually trigger a mission cleanup.
commandToClient(%this, 'MissionEnd', $missionSequence);
}

View file

@ -0,0 +1,62 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//Firstly, set up our standard server prefs
// List of master servers to query, each one is tried in order
// until one responds
$Pref::Server::RegionMask = 2;
$pref::Master[0] = "2:master.garagegames.com:28002";
// Information about the server
$Pref::Server::Name = "Torque 3D Server";
$Pref::Server::Info = "This is a Torque 3D server.";
// The connection error message is transmitted to the client immediatly
// on connection, if any further error occures during the connection
// process, such as network traffic mismatch, or missing files, this error
// message is display. This message should be replaced with information
// usefull to the client, such as the url or ftp address of where the
// latest version of the game can be obtained.
$Pref::Server::ConnectionError =
"You do not have the correct version of "@$appName@" or "@
"the related art needed to play on this server, please contact "@
"the server administrator.";
// The network port is also defined by the client, this value
// overrides pref::net::port for dedicated servers
$Pref::Server::Port = 28000;
// If the password is set, clients must provide it in order
// to connect to the server
$Pref::Server::Password = "";
// Password for admin clients
$Pref::Server::AdminPassword = "";
// Misc server settings.
$Pref::Server::MaxPlayers = 64;
$Pref::Server::TimeLimit = 20; // In minutes
$Pref::Server::KickBanTime = 300; // specified in seconds
$Pref::Server::BanTime = 1800; // specified in seconds
$Pref::Server::FloodProtectionEnabled = 1;
$Pref::Server::MaxChatLen = 120;

View file

@ -0,0 +1,171 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Mission Loading
// The server portion of the client/server mission loading process
//-----------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Loading Phases:
// Phase 1: Transmit Datablocks
// Transmit targets
// Phase 2: Transmit Ghost Objects
// Phase 3: Start Game
//
// The server invokes the client MissionStartPhase[1-3] function to request
// permission to start each phase. When a client is ready for a phase,
// it responds with MissionStartPhase[1-3]Ack.
//----------------------------------------------------------------------------
// Phase 1
//----------------------------------------------------------------------------
function GameConnection::loadMission(%this)
{
// Send over the information that will display the server info
// when we learn it got there, we'll send the data blocks
%this.currentPhase = 0;
if (%this.isAIControlled())
{
// Cut to the chase...
theLevelInfo.onEnterGame(%this);
}
else
{
commandToClient(%this, 'MissionStartPhase1', $missionSequence, $Server::MissionFile);
echo("*** Sending mission load to client: " @ $Server::MissionFile);
}
}
function serverCmdMissionStartPhase1Ack(%client, %seq)
{
// Make sure to ignore calls from a previous mission load
if (%seq != $missionSequence || !$MissionRunning || %client.currentPhase != 0)
return;
%client.currentPhase = 1;
// Start with the CRC
%client.setMissionCRC( $missionCRC );
// Send over the datablocks...
// OnDataBlocksDone will get called when have confirmation
// that they've all been received.
%client.transmitDataBlocks($missionSequence);
}
function GameConnection::onDataBlocksDone( %this, %missionSequence )
{
// Make sure to ignore calls from a previous mission load
if (%missionSequence != $missionSequence || %this.currentPhase != 1)
return;
%this.currentPhase = 1.5;
// On to the next phase
commandToClient(%this, 'MissionStartPhase2', $missionSequence, $Server::MissionFile);
}
//----------------------------------------------------------------------------
// Phase 2
//----------------------------------------------------------------------------
function serverCmdMissionStartPhase2Ack(%client, %seq)
{
// Make sure to ignore calls from a previous mission load
if (%seq != $missionSequence || !$MissionRunning || %client.currentPhase != 1.5)
return;
%client.currentPhase = 2;
// Update mod paths, this needs to get there before the objects.
%client.transmitPaths();
// Start ghosting objects to the client
%client.activateGhosting();
}
function GameConnection::clientWantsGhostAlwaysRetry(%client)
{
if($MissionRunning)
%client.activateGhosting();
}
function GameConnection::onGhostAlwaysFailed(%client)
{
}
function GameConnection::onGhostAlwaysObjectsReceived(%client)
{
// Ready for next phase.
commandToClient(%client, 'MissionStartPhase3', $missionSequence, $Server::MissionFile);
}
//----------------------------------------------------------------------------
// Phase 3
//----------------------------------------------------------------------------
function serverCmdMissionStartPhase3Ack(%client, %seq)
{
// Make sure to ignore calls from a previous mission load
if(%seq != $missionSequence || !$MissionRunning || %client.currentPhase != 2)
return;
%client.currentPhase = 3;
// Server is ready to drop into the game
//Have any special game-play handling here
if(theLevelInfo.isMethod("onClientEnterGame"))
{
theLevelInfo.onClientEnterGame(%client);
}
else
{
//No Game mode class for the level info, so just spawn a default camera
// Set the control object to the default camera
if (!isObject(%client.camera))
{
if(!isObject(Observer))
{
datablock CameraData(Observer)
{
mode = "Observer";
};
}
if (isDefined("$Game::DefaultCameraClass"))
%client.camera = spawnObject("Camera", Observer);
}
// If we have a camera then set up some properties
if (isObject(%client.camera))
{
MissionCleanup.add( %this.camera );
%client.camera.scopeToClient(%client);
%client.setControlObject(%client.camera);
%client.camera.setTransform("0 0 1 0 0 0 0");
}
}
%client.startMission();
}

View file

@ -0,0 +1,197 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Loading info is text displayed on the client side while the mission
// is being loaded. This information is extracted from the mission file
// and sent to each the client as it joins.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// clearLoadInfo
//
// Clears the mission info stored
//------------------------------------------------------------------------------
function clearLoadInfo()
{
if (isObject(theLevelInfo))
theLevelInfo.delete();
}
//------------------------------------------------------------------------------
// buildLoadInfo
//
// Extract the map description from the .mis file
//------------------------------------------------------------------------------
function buildLoadInfo( %mission )
{
clearLoadInfo();
%infoObject = "";
%file = new FileObject();
if ( %file.openForRead( %mission ) ) {
%inInfoBlock = false;
while ( !%file.isEOF() ) {
%line = %file.readLine();
%line = trim( %line );
if( %line $= "new ScriptObject(MissionInfo) {" )
%inInfoBlock = true;
else if( %line $= "new LevelInfo(theLevelInfo) {" )
%inInfoBlock = true;
else if( %inInfoBlock && %line $= "};" ) {
%inInfoBlock = false;
%infoObject = %infoObject @ %line;
break;
}
if( %inInfoBlock )
%infoObject = %infoObject @ %line @ " ";
}
%file.close();
}
else
error("Level file " @ %mission @ " not found.");
// Will create the object "MissionInfo"
eval( %infoObject );
%file.delete();
}
//------------------------------------------------------------------------------
// dumpLoadInfo
//
// Echo the mission information to the console
//------------------------------------------------------------------------------
function dumpLoadInfo()
{
echo( "Level Name: " @ theLevelInfo.name );
echo( "Level Description:" );
for( %i = 0; theLevelInfo.desc[%i] !$= ""; %i++ )
echo (" " @ theLevelInfo.desc[%i]);
}
//------------------------------------------------------------------------------
// sendLoadInfoToClient
//
// Sends mission description to the client
//------------------------------------------------------------------------------
function sendLoadInfoToClient( %client )
{
messageClient( %client, 'MsgLoadInfo', "", theLevelInfo.levelName );
// Send Mission Description a line at a time
for( %i = 0; theLevelInfo.desc[%i] !$= ""; %i++ )
messageClient( %client, 'MsgLoadDescripition', "", theLevelInfo.desc[%i] );
messageClient( %client, 'MsgLoadInfoDone' );
}
// A function used in order to easily parse the MissionGroup for classes . I'm pretty
// sure at this point the function can be easily modified to search the any group as well.
function parseMissionGroup( %className, %childGroup )
{
if( getWordCount( %childGroup ) == 0)
%currentGroup = "MissionGroup";
else
%currentGroup = %childGroup;
for(%i = 0; %i < (%currentGroup).getCount(); %i++)
{
if( (%currentGroup).getObject(%i).getClassName() $= %className )
return true;
if( (%currentGroup).getObject(%i).getClassName() $= "SimGroup" )
{
if( parseMissionGroup( %className, (%currentGroup).getObject(%i).getId() ) )
return true;
}
}
}
//
function parseMissionGroupForIds( %className, %childGroup )
{
if( getWordCount( %childGroup ) == 0)
%currentGroup = $Game::MissionGroup;
else
%currentGroup = %childGroup;
for(%i = 0; %i < (%currentGroup).getCount(); %i++)
{
if( (%currentGroup).getObject(%i).getClassName() $= %className )
%classIds = %classIds @ (%currentGroup).getObject(%i).getId() @ " ";
if( (%currentGroup).getObject(%i).getClassName() $= "SimGroup" )
%classIds = %classIds @ parseMissionGroupForIds( %className, (%currentGroup).getObject(%i).getId());
}
return %classIds;
}
function getLevelInfo( %missionFile )
{
clearLoadInfo();
%file = new FileObject();
%LevelInfoObject = "";
if ( %file.openForRead( %missionFile ) ) {
%inInfoBlock = false;
while ( !%file.isEOF() ) {
%line = %file.readLine();
%line = trim( %line );
if( %line $= "new ScriptObject(LevelInfo) {" )
%inInfoBlock = true;
else if( %line $= "new LevelInfo(theLevelInfo) {" )
%inInfoBlock = true;
else if( %inInfoBlock && %line $= "};" ) {
%inInfoBlock = false;
%LevelInfoObject = %LevelInfoObject @ %line;
break;
}
if( %inInfoBlock )
%LevelInfoObject = %LevelInfoObject @ %line @ " ";
}
%file.close();
}
%file.delete();
if( %LevelInfoObject !$= "" )
{
%LevelInfoObject = "%LevelInfoObject = " @ %LevelInfoObject;
eval( %LevelInfoObject );
return %LevelInfoObject;
}
// Didn't find our LevelInfo
return 0;
}

View file

@ -0,0 +1,181 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Mission Loading
// The server portion of the client/server mission loading process
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Server mission loading
//-----------------------------------------------------------------------------
// On every mission load except the first, there is a pause after
// the initial mission info is downloaded to the client.
$MissionLoadPause = 5000;
//-----------------------------------------------------------------------------
//This is the first call made by the server to kick the loading process off
function loadMission( %missionName, %isFirstMission )
{
endMission();
echo("*** LOADING MISSION: " @ %missionName);
echo("*** Stage 1 load");
// increment the mission sequence (used for ghost sequencing)
$missionSequence++;
$missionRunning = false;
$Server::MissionFile = %missionName;
$Server::LoadFailMsg = "";
// Extract mission info from the mission file,
// including the display name and stuff to send
// to the client.
buildLoadInfo( %missionName );
// Download mission info to the clients
%count = ClientGroup.getCount();
for( %cl = 0; %cl < %count; %cl++ )
{
%client = ClientGroup.getObject( %cl );
if (!%client.isAIControlled())
sendLoadInfoToClient(%client);
}
// Now that we've sent the LevelInfo to the clients
// clear it so that it won't conflict with the actual
// LevelInfo loaded in the level
clearLoadInfo();
// if this isn't the first mission, allow some time for the server
// to transmit information to the clients:
if( %isFirstMission || $Server::ServerType $= "SinglePlayer" )
loadMissionStage2();
else
schedule( $MissionLoadPause, ServerGroup, loadMissionStage2 );
}
//-----------------------------------------------------------------------------
function loadMissionStage2()
{
echo("*** Stage 2 load");
// Create the mission group off the ServerGroup
$instantGroup = ServerGroup;
// Make sure the mission exists
%file = $Server::MissionFile;
if( !isFile( %file ) )
{
$Server::LoadFailMsg = "Could not find mission \"" @ %file @ "\"";
}
else
{
// Calculate the mission CRC. The CRC is used by the clients
// to caching mission lighting.
$missionCRC = getFileCRC( %file );
// Exec the mission. The MissionGroup (loaded components) is added to the ServerGroup
exec(%file);
if( !isObject(MissionGroup) )
{
$Server::LoadFailMsg = "No 'MissionGroup' found in mission \"" @ %file @ "\".";
}
}
if( $Server::LoadFailMsg !$= "" )
{
// Inform clients that are already connected
for (%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
messageClient(ClientGroup.getObject(%clientIndex), 'MsgLoadFailed', $Server::LoadFailMsg);
return;
}
// Set mission name.
if( isObject( theLevelInfo ) )
$Server::MissionName = theLevelInfo.levelName;
// Mission cleanup group. This is where run time components will reside. The MissionCleanup
// group will be added to the ServerGroup.
new SimGroup( MissionCleanup );
// Make the MissionCleanup group the place where all new objects will automatically be added.
$instantGroup = MissionCleanup;
// Construct MOD paths
pathOnMissionLoadDone();
// Mission loading done...
echo("*** Mission loaded");
// Start all the clients in the mission
$missionRunning = true;
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ )
ClientGroup.getObject(%clientIndex).loadMission();
// Go ahead and launch the game
if(TheLevelInfo.isMethod("onMissionStart"))
TheLevelInfo.onMissionStart();
}
function endMission()
{
if (!isObject( MissionGroup ))
return;
echo("*** ENDING MISSION");
// Inform the game code we're done.
TheLevelInfo.onMissionEnded();
// Inform the clients
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
// clear ghosts and paths from all clients
%cl = ClientGroup.getObject( %clientIndex );
%cl.endMission();
%cl.resetGhosting();
%cl.clearPaths();
}
// Delete everything
MissionGroup.delete();
MissionCleanup.delete();
clearServerPaths();
}
function resetMission()
{
echo("*** MISSION RESET");
// Remove any temporary mission objects
MissionCleanup.delete();
$instantGroup = ServerGroup;
new SimGroup( MissionCleanup );
$instantGroup = MissionCleanup;
clearServerPaths();
//
TheLevelInfo.onMissionReset();
}

View file

@ -0,0 +1,50 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function messageClient(%client, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
{
commandToClient(%client, 'ServerMessage', %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
}
function messageAll(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
{
%count = ClientGroup.getCount();
for(%cl = 0; %cl < %count; %cl++)
{
%client = ClientGroup.getObject(%cl);
messageClient(%client, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
}
}
function messageAllExcept(%client, %team, %msgtype, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
{
//can exclude a client, a team or both. A -1 value in either field will ignore that exclusion, so
//messageAllExcept(-1, -1, $Mesblah, 'Blah!'); will message everyone (since there shouldn't be a client -1 or client on team -1).
%count = ClientGroup.getCount();
for(%cl= 0; %cl < %count; %cl++)
{
%recipient = ClientGroup.getObject(%cl);
if((%recipient != %client) && (%recipient.team != %team))
messageClient(%recipient, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
}
}

View file

@ -0,0 +1,291 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
function initServer()
{
echo("\n--------- Initializing " @ $appName @ ": Server Scripts ---------");
//load prefs
%prefPath = getPrefpath();
if ( isFile( %prefPath @ "/serverPrefs.cs" ) )
exec( %prefPath @ "/serverPrefs.cs" );
else
exec( "data/clientServer/scripts/server/defaults.cs" );
exec( "data/clientServer/scripts/server/audio.cs" );
exec( "data/clientServer/scripts/server/commands.cs" );
exec( "data/clientServer/scripts/server/message.cs" );
exec( "data/clientServer/scripts/server/levelDownload.cs" );
exec( "data/clientServer/scripts/server/levelLoad.cs" );
exec( "data/clientServer/scripts/server/levelInfo.cs" );
exec( "data/clientServer/scripts/server/connectionToClient.cs" );
// Server::Status is returned in the Game Info Query and represents the
// current status of the server. This string sould be very short.
$Server::Status = "Unknown";
// Turn on testing/debug script functions
$Server::TestCheats = false;
// Specify where the mission files are.
$Server::MissionFileSpec = "data/levels/*.mis";
}
//-----------------------------------------------------------------------------
function initDedicated()
{
enableWinConsole(true);
echo("\n--------- Starting Dedicated Server ---------");
// Make sure this variable reflects the correct state.
$Server::Dedicated = true;
// The server isn't started unless a mission has been specified.
if ($missionArg !$= "") {
createServer("MultiPlayer", $missionArg);
}
else
echo("No mission specified (use -mission filename)");
}
/// Attempt to find an open port to initialize the server with
function portInit(%port)
{
%failCount = 0;
while(%failCount < 10 && !setNetPort(%port))
{
echo("Port init failed on port " @ %port @ " trying next port.");
%port++; %failCount++;
}
}
/// Create a server of the given type, load the given level, and then
/// create a local client connection to the server.
//
/// @return true if successful.
function createAndConnectToLocalServer( %serverType, %level )
{
if( !createServer( %serverType, %level ) )
return false;
%conn = new GameConnection( ServerConnection );
RootGroup.add( ServerConnection );
%conn.setConnectArgs( $pref::Player::Name );
%conn.setJoinPassword( $Client::Password );
%result = %conn.connectLocal();
if( %result !$= "" )
{
%conn.delete();
destroyServer();
return false;
}
return true;
}
/// Create a server with either a "SinglePlayer" or "MultiPlayer" type
/// Specify the level to load on the server
function createServer(%serverType, %level)
{
// Increase the server session number. This is used to make sure we're
// working with the server session we think we are.
$Server::Session++;
if (%level $= "")
{
error("createServer(): level name unspecified");
return false;
}
// Make sure our level name is relative so that it can send
// across the network correctly
%level = makeRelativePath(%level, getWorkingDirectory());
destroyServer();
$missionSequence = 0;
$Server::PlayerCount = 0;
$Server::ServerType = %serverType;
$Server::LoadFailMsg = "";
$Physics::isSinglePlayer = true;
// Setup for multi-player, the network must have been
// initialized before now.
if (%serverType $= "MultiPlayer")
{
$Physics::isSinglePlayer = false;
echo("Starting multiplayer mode");
// Make sure the network port is set to the correct pref.
portInit($Pref::Server::Port);
allowConnections(true);
if ($pref::Net::DisplayOnMaster !$= "Never" )
schedule(0,0,startHeartbeat);
}
// Let the game initialize some things now that the
// the server has been created
onServerCreated();
loadMission(%level, true);
$Game::running = true;
return true;
}
function onServerCreated()
{
// Server::GameType is sent to the master server.
// This variable should uniquely identify your game and/or mod.
$Server::GameType = $appName;
// Server::MissionType sent to the master server. Clients can
// filter servers based on mission type.
// $Server::MissionType = "Deathmatch";
// GameStartTime is the sim time the game started. Used to calculated
// game elapsed time.
$Game::StartTime = 0;
// Create the server physics world.
physicsInitWorld( "server" );
physicsStartSimulation("server");
%cnt = DatablockFilesList.count();
loadDatablockFiles( DatablockFilesList, true );
%cnt = DatablockFilesList.count();
// Keep track of when the game started
$Game::StartTime = $Sim::Time;
}
/// Shut down the server
function destroyServer()
{
$Server::ServerType = "";
$Server::Running = false;
allowConnections(false);
stopHeartbeat();
$missionRunning = false;
// End any running levels and shut down the physics sim
onServerDestroyed();
physicsDestroy();
// Delete all the server objects
if (isObject(ServerGroup))
ServerGroup.delete();
// Delete all the connections:
while (ClientGroup.getCount())
{
%client = ClientGroup.getObject(0);
%client.delete();
}
$Server::GuidList = "";
// Delete all the data blocks...
deleteDataBlocks();
// Save any server settings
echo( "Exporting server prefs..." );
export( "$Pref::Server::*", "data/clientServer/scripts/server/prefs.cs", false );
// Increase the server session number. This is used to make sure we're
// working with the server session we think we are.
$Server::Session++;
}
function onServerDestroyed()
{
physicsStopSimulation("server");
if (!isObject( MissionGroup ))
return;
echo("*** ENDING MISSION");
// Inform the game code we're done.
if(TheLevelInfo.isMethod("onMissionEnded"))
TheLevelInfo.onMissionEnded();
// Inform the clients
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
// clear ghosts and paths from all clients
%cl = ClientGroup.getObject( %clientIndex );
%cl.endMission();
%cl.resetGhosting();
%cl.clearPaths();
}
// Delete everything
MissionGroup.delete();
MissionCleanup.delete();
clearServerPaths();
}
/// Guid list maintenance functions
function addToServerGuidList( %guid )
{
%count = getFieldCount( $Server::GuidList );
for ( %i = 0; %i < %count; %i++ )
{
if ( getField( $Server::GuidList, %i ) == %guid )
return;
}
$Server::GuidList = $Server::GuidList $= "" ? %guid : $Server::GuidList TAB %guid;
}
function removeFromServerGuidList( %guid )
{
%count = getFieldCount( $Server::GuidList );
for ( %i = 0; %i < %count; %i++ )
{
if ( getField( $Server::GuidList, %i ) == %guid )
{
$Server::GuidList = removeField( $Server::GuidList, %i );
return;
}
}
}
/// When the server is queried for information, the value of this function is
/// returned as the status field of the query packet. This information is
/// accessible as the ServerInfo::State variable.
function onServerInfoQuery()
{
return "Doing Ok";
}

View file

@ -0,0 +1,218 @@
$pref::Player::Name = "Visitor";
$pref::Player::defaultFov = 75;
$pref::Player::zoomSpeed = 0;
$pref::Net::LagThreshold = 400;
$pref::Net::Port = 28000;
$pref::HudMessageLogSize = 40;
$pref::ChatHudLength = 1;
$pref::Input::LinkMouseSensitivity = 1;
// DInput keyboard, mouse, and joystick prefs
$pref::Input::KeyboardEnabled = 1;
$pref::Input::MouseEnabled = 1;
$pref::Input::JoystickEnabled = 0;
$pref::Input::KeyboardTurnSpeed = 0.1;
$pref::Input::invertVerticalMouse = false;
$pref::Input::VertMouseSensitivity = 1;
$pref::Input::HorzMouseSensitivity = 1;
$pref::Input::RollMouseSensitivity = 1;
$pref::Input::ZoomVertMouseSensitivity = 0.3;
$pref::Input::ZoomHorzMouseSensitivity = 0.3;
$sceneLighting::cacheSize = 20000;
$sceneLighting::purgeMethod = "lastCreated";
$sceneLighting::cacheLighting = 1;
$pref::Video::displayDevice = "D3D9";
$pref::Video::disableVerticalSync = 1;
$pref::Video::Resolution = "1024 768";
$pref::Video::FullScreen = false;
$pref::Video::BitDepth = "32";
$pref::Video::RefreshRate = "60";
$pref::Video::AA = "4";
$pref::Video::defaultFenceCount = 0;
$pref::Video::screenShotSession = 0;
$pref::Video::screenShotFormat = "PNG";
/// This disables the hardware FSAA/MSAA so that
/// we depend completely on the FXAA post effect
/// which works on all cards and in deferred mode.
///
/// Note the new Intel Hybrid graphics on laptops
/// will fail to initialize when hardware AA is
/// enabled... so you've been warned.
///
$pref::Video::disableHardwareAA = true;
$pref::Video::disableNormalmapping = false;
$pref::Video::disablePixSpecular = false;
$pref::Video::disableCubemapping = false;
///
$pref::Video::disableParallaxMapping = false;
$pref::Video::Gamma = 2.2;
$pref::Video::Contrast = 1.0;
$pref::Video::Brightness = 0;
/// The perfered light manager to use at startup. If blank
/// or if the selected one doesn't work on this platfom it
/// will try the defaults below.
$pref::lightManager = "";
/// This is the default list of light managers ordered from
/// most to least desirable for initialization.
$lightManager::defaults = "Advanced Lighting";
/// A scale to apply to the camera view distance
/// typically used for tuning performance.
$pref::camera::distanceScale = 1.0;
/// Causes the system to do a one time autodetect
/// of an SFX provider and device at startup if the
/// provider is unset.
$pref::SFX::autoDetect = true;
/// The sound provider to select at startup. Typically
/// this is DirectSound, OpenAL, or XACT. There is also
/// a special Null provider which acts normally, but
/// plays no sound.
$pref::SFX::provider = "";
/// The sound device to select from the provider. Each
/// provider may have several different devices.
$pref::SFX::device = "OpenAL";
/// If true the device will try to use hardware buffers
/// and sound mixing. If not it will use software.
$pref::SFX::useHardware = false;
/// If you have a software device you have a
/// choice of how many software buffers to
/// allow at any one time. More buffers cost
/// more CPU time to process and mix.
$pref::SFX::maxSoftwareBuffers = 16;
/// This is the playback frequency for the primary
/// sound buffer used for mixing. Although most
/// providers will reformat on the fly, for best
/// quality and performance match your sound files
/// to this setting.
$pref::SFX::frequency = 44100;
/// This is the playback bitrate for the primary
/// sound buffer used for mixing. Although most
/// providers will reformat on the fly, for best
/// quality and performance match your sound files
/// to this setting.
$pref::SFX::bitrate = 32;
/// The overall system volume at startup. Note that
/// you can only scale volume down, volume does not
/// get louder than 1.
$pref::SFX::masterVolume = 0.8;
/// The startup sound channel volumes. These are
/// used to control the overall volume of different
/// classes of sounds.
$pref::SFX::channelVolume1 = 1;
$pref::SFX::channelVolume2 = 1;
$pref::SFX::channelVolume3 = 1;
$pref::SFX::channelVolume4 = 1;
$pref::SFX::channelVolume5 = 1;
$pref::SFX::channelVolume6 = 1;
$pref::SFX::channelVolume7 = 1;
$pref::SFX::channelVolume8 = 1;
$pref::SFX::channelVolume[1] = 1;
$pref::SFX::channelVolume[2] = 1;
$pref::SFX::channelVolume[3] = 1;
$pref::SFX::channelVolume[4] = 1;
$pref::PostEffect::PreferedHDRFormat = "GFXFormatR8G8B8A8";
/// This is an scalar which can be used to reduce the
/// reflection textures on all objects to save fillrate.
$pref::Reflect::refractTexScale = 1.0;
/// This is the total frame in milliseconds to budget for
/// reflection rendering. If your CPU bound and have alot
/// of smaller reflection surfaces try reducing this time.
$pref::Reflect::frameLimitMS = 10;
/// Set true to force all water objects to use static cubemap reflections.
$pref::Water::disableTrueReflections = false;
// A global LOD scalar which can reduce the overall density of placed GroundCover.
$pref::GroundCover::densityScale = 1.0;
/// An overall scaler on the lod switching between DTS models.
/// Smaller numbers makes the lod switch sooner.
$pref::TS::detailAdjust = 1.0;
///
$pref::Decals::enabled = true;
///
$pref::Decals::lifeTimeScale = "1";
/// The number of mipmap levels to drop on loaded textures
/// to reduce video memory usage.
///
/// It will skip any textures that have been defined as not
/// allowing down scaling.
///
$pref::Video::textureReductionLevel = 0;
///
$pref::Shadows::textureScalar = 1.0;
///
$pref::Shadows::disable = false;
/// Sets the shadow filtering mode.
///
/// None - Disables filtering.
///
/// SoftShadow - Does a simple soft shadow
///
/// SoftShadowHighQuality
///
$pref::Shadows::filterMode = "SoftShadow";
///
$pref::Video::defaultAnisotropy = 1;
/// Radius in meters around the camera that ForestItems are affected by wind.
/// Note that a very large number with a large number of items is not cheap.
$pref::windEffectRadius = 25;
/// AutoDetect graphics quality levels the next startup.
$pref::Video::autoDetect = 1;
$PostFXManager::Settings::EnableDOF = "0";
$PostFXManager::Settings::DOF::BlurCurveFar = "";
$PostFXManager::Settings::DOF::BlurCurveNear = "";
$PostFXManager::Settings::DOF::BlurMax = "";
$PostFXManager::Settings::DOF::BlurMin = "";
$PostFXManager::Settings::DOF::EnableAutoFocus = "";
$PostFXManager::Settings::DOF::EnableDOF = "";
$PostFXManager::Settings::DOF::FocusRangeMax = "";
$PostFXManager::Settings::DOF::FocusRangeMin = "";
$PostFXManager::Settings::EnableLightRays = "0";
$PostFXManager::Settings::LightRays::brightScalar = "0.75";
$PostFXManager::Settings::LightRays::decay = "1.0";
$PostFXManager::Settings::LightRays::density = "0.94";
$PostFXManager::Settings::LightRays::numSamples = "40";
$PostFXManager::Settings::LightRays::weight = "5.65";
$PostFXManager::Settings::EnableDOF = 1;
$pref::PostFX::EnableVignette = 1;
$pref::PostFX::EnableLightRays = 1;
$pref::PostFX::EnableHDR = 1;
$pref::PostFX::EnableSSAO = 1;

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

@ -0,0 +1,45 @@
// The general flow of a gane - server's creation, loading and hosting clients, and then destruction is as follows:
// First, a client will always create a server in the event that they want to host a single player
// game. Torque3D treats even single player connections as a soft multiplayer game, with some stuff
// in the networking short-circuited to sidestep around lag and packet transmission times.
// initServer() is called, loading the default server scripts.
// After that, if this is a dedicated server session, initDedicated() is called, otherwise initClient is called
// to prep a playable client session.
// When a local game is started - a listen server - via calling StartGame() a server is created and then the client is
// connected to it via createAndConnectToLocalServer().
function PostFX::create( %this )
{
echo("\n--------- Initializing PostFX Directory: scripts ---------");
// Start up in either client, or dedicated server mode
if (!$Server::Dedicated)
{
//postFX stuffs
exec("./scripts/gui/postFxManager.gui");
//init the postFX
%pattern = "./scripts/client/*.cs";
%file = findFirstFile( %pattern );
if ( %file $= "" )
{
// Try for DSOs next.
%pattern = "./scripts/client/*.cs.dso";
%file = findFirstFile( %pattern );
}
while( %file !$= "" )
{
exec( %file );
%file = findNextFile( %pattern );
}
}
}
function PostFX::destroy( %this )
{
}

View file

@ -0,0 +1,9 @@
<ModuleDefinition
ModuleId="PostFX"
VersionId="1"
Description="Default PostFX elements"
ScriptFile="postFX.cs"
CreateFunction="create"
DestroyFunction="destroy"
Group="Game">
</ModuleDefinition>

View file

@ -0,0 +1,74 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
singleton ShaderData( GammaShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gammaP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gl/gammaP.glsl";
samplerNames[0] = "$backBuffer";
samplerNames[1] = "$colorCorrectionTex";
pixVersion = 2.0;
};
singleton GFXStateBlockData( GammaStateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
samplerStates[1] = SamplerClampLinear;
};
singleton PostEffect( GammaPostFX )
{
isEnabled = true;
allowReflectPass = true;
renderTime = "PFXBeforeBin";
renderBin = "EditorBin";
renderPriority = 9999;
shader = GammaShader;
stateBlock = GammaStateBlock;
texture[0] = "$backBuffer";
texture[1] = $HDRPostFX::colorCorrectionRamp;
targetFormat = getBestHDRFormat();
};
function GammaPostFX::preProcess( %this )
{
if ( %this.texture[1] !$= $HDRPostFX::colorCorrectionRamp )
%this.setTexture( 1, $HDRPostFX::colorCorrectionRamp );
}
function GammaPostFX::setShaderConsts( %this )
{
%clampedGamma = mClamp( $pref::Video::Gamma, 2.0, 2.5);
%this.setShaderConst( "$OneOverGamma", 1 / %clampedGamma );
%this.setShaderConst( "$Brightness", $pref::Video::Brightness );
%this.setShaderConst( "$Contrast", $pref::Video::Contrast );
}

View file

@ -0,0 +1,186 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
// NOTE: This is currently disabled in favor of FXAA. See
// core\scripts\client\canvas.cs if you want to re-enable it.
singleton GFXStateBlockData( MLAA_EdgeDetectStateBlock : PFX_DefaultStateBlock )
{
// Mark the edge pixels in stencil.
stencilDefined = true;
stencilEnable = true;
stencilPassOp = GFXStencilOpReplace;
stencilFunc = GFXCmpAlways;
stencilRef = 1;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
};
singleton ShaderData( MLAA_EdgeDetectionShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/mlaa/offsetV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/mlaa/edgeDetectionP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/mlaa/gl/offsetV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/mlaa/gl/edgeDetectionP.glsl";
samplerNames[0] = "$colorMapG";
samplerNames[1] = "$prepassMap";
pixVersion = 3.0;
};
singleton GFXStateBlockData( MLAA_BlendWeightCalculationStateBlock : PFX_DefaultStateBlock )
{
// Here we want to process only marked pixels.
stencilDefined = true;
stencilEnable = true;
stencilPassOp = GFXStencilOpKeep;
stencilFunc = GFXCmpEqual;
stencilRef = 1;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint;
samplerStates[1] = SamplerClampLinear;
samplerStates[2] = SamplerClampPoint;
};
singleton ShaderData( MLAA_BlendWeightCalculationShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/mlaa/passthruV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/mlaa/blendWeightCalculationP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/mlaa/gl/passthruV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/mlaa/gl/blendWeightCalculationP.glsl";
samplerNames[0] = "$edgesMap";
samplerNames[1] = "$edgesMapL";
samplerNames[2] = "$areaMap";
pixVersion = 3.0;
};
singleton GFXStateBlockData( MLAA_NeighborhoodBlendingStateBlock : PFX_DefaultStateBlock )
{
// Here we want to process only marked pixels too.
stencilDefined = true;
stencilEnable = true;
stencilPassOp = GFXStencilOpKeep;
stencilFunc = GFXCmpEqual;
stencilRef = 1;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint;
samplerStates[1] = SamplerClampLinear;
samplerStates[2] = SamplerClampPoint;
};
singleton ShaderData( MLAA_NeighborhoodBlendingShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFx/mlaa/offsetV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/postFx/mlaa/neighborhoodBlendingP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFx/mlaa/gl/offsetV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/postFx/mlaa/gl/neighborhoodBlendingP.glsl";
samplerNames[0] = "$blendMap";
samplerNames[1] = "$colorMapL";
samplerNames[2] = "$colorMap";
pixVersion = 3.0;
};
singleton PostEffect( MLAAFx )
{
isEnabled = false;
allowReflectPass = false;
renderTime = "PFXAfterDiffuse";
texture[0] = "$backBuffer"; //colorMapG
texture[1] = "#prepass"; // Used for depth detection
target = "$outTex";
targetClear = PFXTargetClear_OnDraw;
targetClearColor = "0 0 0 0";
stateBlock = MLAA_EdgeDetectStateBlock;
shader = MLAA_EdgeDetectionShader;
// The luma calculation weights which can be user adjustable
// per-scene if nessasary. The default value of...
//
// 0.2126 0.7152 0.0722
//
// ... is the HDTV ITU-R Recommendation BT. 709.
lumaCoefficients = "0.2126 0.7152 0.0722";
// The tweakable color threshold used to select
// the range of edge pixels to blend.
threshold = 0.1;
// The depth delta threshold used to select
// the range of edge pixels to blend.
depthThreshold = 0.01;
new PostEffect()
{
internalName = "blendingWeightsCalculation";
target = "$outTex";
targetClear = PFXTargetClear_OnDraw;
shader = MLAA_BlendWeightCalculationShader;
stateBlock = MLAA_BlendWeightCalculationStateBlock;
texture[0] = "$inTex"; // Edges mask
texture[1] = "$inTex"; // Edges mask
texture[2] = "data/postFX/art/AreaMap33.dds";
};
new PostEffect()
{
internalName = "neighborhoodBlending";
shader = MLAA_NeighborhoodBlendingShader;
stateBlock = MLAA_NeighborhoodBlendingStateBlock;
texture[0] = "$inTex"; // Blend weights
texture[1] = "$backBuffer";
texture[2] = "$backBuffer";
};
};
function MLAAFx::setShaderConsts(%this)
{
%this.setShaderConst("$lumaCoefficients", %this.lumaCoefficients);
%this.setShaderConst("$threshold", %this.threshold);
%this.setShaderConst("$depthThreshold", %this.depthThreshold);
}

View file

@ -0,0 +1,53 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
singleton ShaderData( PFX_MotionBlurShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl"; //we use the bare-bones postFxV.hlsl
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/motionBlurP.hlsl"; //new pixel shader
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gl/motionBlurP.glsl";
samplerNames[0] = "$backBuffer";
samplerNames[1] = "$prepassTex";
pixVersion = 3.0;
};
singleton PostEffect(MotionBlurFX)
{
isEnabled = false;
renderTime = "PFXAfterDiffuse";
shader = PFX_MotionBlurShader;
stateBlock = PFX_DefaultStateBlock;
texture[0] = "$backbuffer";
texture[1] = "#prepass";
target = "$backBuffer";
};
function MotionBlurFX::setShaderConsts(%this)
{
%this.setShaderConst( "$velocityMultiplier", 3000 );
}

View file

@ -0,0 +1,64 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
singleton GFXStateBlockData( PFX_CausticsStateBlock : PFX_DefaultStateBlock )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendOne;
blendDest = GFXBlendOne;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
samplerStates[1] = SamplerWrapLinear;
samplerStates[2] = SamplerWrapLinear;
};
singleton ShaderData( PFX_CausticsShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/caustics/causticsP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/caustics/gl/causticsP.glsl";
samplerNames[0] = "$prepassTex";
samplerNames[1] = "$causticsTex0";
samplerNames[2] = "$causticsTex1";
pixVersion = 3.0;
};
singleton PostEffect( CausticsPFX )
{
isEnabled = false;
renderTime = "PFXAfterDiffuse";
renderBin = "ObjTranslucentBin";
//renderPriority = 0.1;
shader = PFX_CausticsShader;
stateBlock = PFX_CausticsStateBlock;
texture[0] = "#prepass";
texture[1] = "data/postFX/art/caustics_1";
texture[2] = "data/postFX/art/caustics_2";
target = "$backBuffer";
};

View file

@ -0,0 +1,77 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
///
$CAPostFx::enabled = false;
/// The lens distortion coefficient.
$CAPostFx::distCoeffecient = -0.05;
/// The cubic distortion value.
$CAPostFx::cubeDistortionFactor = -0.1;
/// The amount and direction of the maxium shift for
/// the red, green, and blue channels.
$CAPostFx::colorDistortionFactor = "0.005 -0.005 0.01";
singleton GFXStateBlockData( PFX_DefaultChromaticLensStateBlock )
{
zDefined = true;
zEnable = false;
zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint;
};
singleton ShaderData( PFX_ChromaticLensShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/chromaticLens.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gl/chromaticLens.glsl";
samplerNames[0] = "$backBuffer";
pixVersion = 3.0;
};
singleton PostEffect( ChromaticLensPostFX )
{
renderTime = "PFXAfterDiffuse";
renderPriority = 0.2;
isEnabled = false;
allowReflectPass = false;
shader = PFX_ChromaticLensShader;
stateBlock = PFX_DefaultChromaticLensStateBlock;
texture[0] = "$backBuffer";
target = "$backBuffer";
};
function ChromaticLensPostFX::setShaderConsts( %this )
{
%this.setShaderConst( "$distCoeff", $CAPostFx::distCoeffecient );
%this.setShaderConst( "$cubeDistort", $CAPostFx::cubeDistortionFactor );
%this.setShaderConst( "$colorDistort", $CAPostFx::colorDistortionFactor );
}

View file

@ -0,0 +1,72 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
$PostFXManager::Settings::EnableVignette = "1";
$PostFXManager::Settings::EnableDOF = "1";
$PostFXManager::Settings::EnabledSSAO = "1";
$PostFXManager::Settings::EnableHDR = "1";
$PostFXManager::Settings::EnableLightRays = "1";
$PostFXManager::Settings::EnablePostFX = "1";
$PostFXManager::Settings::Vignette::VMax = "0.6";
$PostFXManager::Settings::DOF::BlurCurveFar = "";
$PostFXManager::Settings::DOF::BlurCurveNear = "";
$PostFXManager::Settings::DOF::BlurMax = "";
$PostFXManager::Settings::DOF::BlurMin = "";
$PostFXManager::Settings::DOF::EnableAutoFocus = "";
$PostFXManager::Settings::DOF::EnableDOF = "";
$PostFXManager::Settings::DOF::FocusRangeMax = "";
$PostFXManager::Settings::DOF::FocusRangeMin = "";
$PostFXManager::Settings::HDR::adaptRate = "2";
$PostFXManager::Settings::HDR::blueShiftColor = "1.05 0.97 1.27";
$PostFXManager::Settings::HDR::brightPassThreshold = "1";
$PostFXManager::Settings::HDR::enableBloom = "1";
$PostFXManager::Settings::HDR::enableBlueShift = "0";
$PostFXManager::Settings::HDR::enableToneMapping = "0.5";
$PostFXManager::Settings::HDR::gaussMean = "0";
$PostFXManager::Settings::HDR::gaussMultiplier = "0.3";
$PostFXManager::Settings::HDR::gaussStdDev = "0.8";
$PostFXManager::Settings::HDR::keyValue = "0.18";
$PostFXManager::Settings::HDR::minLuminace = "0.001";
$PostFXManager::Settings::HDR::whiteCutoff = "1";
$PostFXManager::Settings::LightRays::brightScalar = "0.75";
$PostFXManager::Settings::LightRays::decay = "1.0";
$PostFXManager::Settings::LightRays::density = "0.94";
$PostFXManager::Settings::LightRays::numSamples = "40";
$PostFXManager::Settings::LightRays::weight = "5.65";
$PostFXManager::Settings::SSAO::blurDepthTol = "0.001";
$PostFXManager::Settings::SSAO::blurNormalTol = "0.95";
$PostFXManager::Settings::SSAO::lDepthMax = "2";
$PostFXManager::Settings::SSAO::lDepthMin = "0.2";
$PostFXManager::Settings::SSAO::lDepthPow = "0.2";
$PostFXManager::Settings::SSAO::lNormalPow = "2";
$PostFXManager::Settings::SSAO::lNormalTol = "-0.5";
$PostFXManager::Settings::SSAO::lRadius = "1";
$PostFXManager::Settings::SSAO::lStrength = "10";
$PostFXManager::Settings::SSAO::overallStrength = "2";
$PostFXManager::Settings::SSAO::quality = "0";
$PostFXManager::Settings::SSAO::sDepthMax = "1";
$PostFXManager::Settings::SSAO::sDepthMin = "0.1";
$PostFXManager::Settings::SSAO::sDepthPow = "1";
$PostFXManager::Settings::SSAO::sNormalPow = "1";
$PostFXManager::Settings::SSAO::sNormalTol = "0";
$PostFXManager::Settings::SSAO::sRadius = "0.1";
$PostFXManager::Settings::SSAO::sStrength = "6";
$PostFXManager::Settings::ColorCorrectionRamp = "data/postFX/art/null_color_ramp.png";

View file

@ -0,0 +1,599 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
/*
================================================================================
The DOFPostEffect API
================================================================================
DOFPostEffect::setFocalDist( %dist )
@summary
This method is for manually controlling the focus distance. It will have no
effect if auto focus is currently enabled. Makes use of the parameters set by
setFocusParams.
@param dist
float distance in meters
--------------------------------------------------------------------------------
DOFPostEffect::setAutoFocus( %enabled )
@summary
This method sets auto focus enabled or disabled. Makes use of the parameters set
by setFocusParams. When auto focus is enabled it determines the focal depth
by performing a raycast at the screen-center.
@param enabled
bool
--------------------------------------------------------------------------------
DOFPostEffect::setFocusParams( %nearBlurMax, %farBlurMax, %minRange, %maxRange, %nearSlope, %farSlope )
Set the parameters that control how the near and far equations are calculated
from the focal distance. If you are not using auto focus you will need to call
setFocusParams PRIOR to calling setFocalDist.
@param nearBlurMax
float between 0.0 and 1.0
The max allowed value of near blur.
@param farBlurMax
float between 0.0 and 1.0
The max allowed value of far blur.
@param minRange/maxRange
float in meters
The distance range around the focal distance that remains in focus is a lerp
between the min/maxRange using the normalized focal distance as the parameter.
The point is to allow the focal range to expand as you focus farther away since this is
visually appealing.
Note: since min/maxRange are lerped by the "normalized" focal distance it is
dependant on the visible distance set in your level.
@param nearSlope
float less than zero
The slope of the near equation. A small number causes bluriness to increase gradually
at distances closer than the focal distance. A large number causes bluriness to
increase quickly.
@param farSlope
float greater than zero
The slope of the far equation. A small number causes bluriness to increase gradually
at distances farther than the focal distance. A large number causes bluriness to
increase quickly.
Note: To rephrase, the min/maxRange parameters control how much area around the
focal distance is completely in focus where the near/farSlope parameters control
how quickly or slowly bluriness increases at distances outside of that range.
================================================================================
Examples
================================================================================
Example1: Turn on DOF while zoomed in with a weapon.
NOTE: These are not real callbacks! Hook these up to your code where appropriate!
function onSniperZoom()
{
// Parameterize how you want DOF to look.
DOFPostEffect.setFocusParams( 0.3, 0.3, 50, 500, -5, 5 );
// Turn on auto focus
DOFPostEffect.setAutoFocus( true );
// Turn on the PostEffect
DOFPostEffect.enable();
}
function onSniperUnzoom()
{
// Turn off the PostEffect
DOFPostEffect.disable();
}
Example2: Manually control DOF with the mouse wheel.
// Somewhere on startup...
// Parameterize how you want DOF to look.
DOFPostEffect.setFocusParams( 0.3, 0.3, 50, 500, -5, 5 );
// Turn off auto focus
DOFPostEffect.setAutoFocus( false );
// Turn on the PostEffect
DOFPostEffect.enable();
NOTE: These are not real callbacks! Hook these up to your code where appropriate!
function onMouseWheelUp()
{
// Since setFocalDist is really just a wrapper to assign to the focalDist
// dynamic field we can shortcut and increment it directly.
DOFPostEffect.focalDist += 8;
}
function onMouseWheelDown()
{
DOFPostEffect.focalDist -= 8;
}
*/
/// This method is for manually controlling the focal distance. It will have no
/// effect if auto focus is currently enabled. Makes use of the parameters set by
/// setFocusParams.
function DOFPostEffect::setFocalDist( %this, %dist )
{
%this.focalDist = %dist;
}
/// This method sets auto focus enabled or disabled. Makes use of the parameters set
/// by setFocusParams. When auto focus is enabled it determine the focal depth
/// by performing a raycast at the screen-center.
function DOFPostEffect::setAutoFocus( %this, %enabled )
{
%this.autoFocusEnabled = %enabled;
}
/// Set the parameters that control how the near and far equations are calculated
/// from the focal distance. If you are not using auto focus you will need to call
/// setFocusParams PRIOR to calling setFocalDist.
function DOFPostEffect::setFocusParams( %this, %nearBlurMax, %farBlurMax, %minRange, %maxRange, %nearSlope, %farSlope )
{
%this.nearBlurMax = %nearBlurMax;
%this.farBlurMax = %farBlurMax;
%this.minRange = %minRange;
%this.maxRange = %maxRange;
%this.nearSlope = %nearSlope;
%this.farSlope = %farSlope;
}
/*
More information...
This DOF technique is based on this paper:
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch28.html
================================================================================
1. Overview of how we represent "Depth of Field"
================================================================================
DOF is expressed as an amount of bluriness per pixel according to its depth.
We represented this by a piecewise linear curve depicted below.
Note: we also refer to "bluriness" as CoC ( circle of confusion ) which is the term
used in the basis paper and in photography.
X-axis (depth)
x = 0.0----------------------------------------------x = 1.0
Y-axis (bluriness)
y = 1.0
|
| ____(x1,y1) (x4,y4)____
| (ns,nb)\ <--Line1 line2---> /(fe,fb)
| \ /
| \(x2,y2) (x3,y3)/
| (ne,0)------(fs,0)
y = 0.0
I have labeled the "corners" of this graph with (Xn,Yn) to illustrate that
this is in fact a collection of line segments where the x/y of each point
corresponds to the key below.
key:
ns - (n)ear blur (s)tart distance
nb - (n)ear (b)lur amount (max value)
ne - (n)ear blur (e)nd distance
fs - (f)ar blur (s)tart distance
fe - (f)ar blur (e)nd distance
fb - (f)ar (b)lur amount (max value)
Of greatest importance in this graph is Line1 and Line2. Where...
L1 { (x1,y1), (x2,y2) }
L2 { (x3,y3), (x4,y4) }
Line one represents the amount of "near" blur given a pixels depth and line two
represents the amount of "far" blur at that depth.
Both these equations are evaluated for each pixel and then the larger of the two
is kept. Also the output blur (for each equation) is clamped between 0 and its
maximum allowable value.
Therefore, to specify a DOF "qualify" you need to specify the near-blur-line,
far-blur-line, and maximum near and far blur value.
================================================================================
2. Abstracting a "focal depth"
================================================================================
Although the shader(s) work in terms of a near and far equation it is more
useful to express DOF as an adjustable focal depth and derive the other parameters
"under the hood".
Given a maximum near/far blur amount and a near/far slope we can calculate the
near/far equations for any focal depth. We extend this to also support a range
of depth around the focal depth that is also in focus and for that range to
shrink or grow as the focal depth moves closer or farther.
Keep in mind this is only one implementation and depending on the effect you
desire you may which to express the relationship between focal depth and
the shader paramaters different.
*/
//-----------------------------------------------------------------------------
// GFXStateBlockData / ShaderData
//-----------------------------------------------------------------------------
singleton GFXStateBlockData( PFX_DefaultDOFStateBlock )
{
zDefined = true;
zEnable = false;
zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint;
samplerStates[1] = SamplerClampPoint;
};
singleton GFXStateBlockData( PFX_DOFCalcCoCStateBlock )
{
zDefined = true;
zEnable = false;
zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
samplerStates[1] = SamplerClampLinear;
};
singleton GFXStateBlockData( PFX_DOFDownSampleStateBlock )
{
zDefined = true;
zEnable = false;
zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
samplerStates[1] = SamplerClampPoint;
};
singleton GFXStateBlockData( PFX_DOFBlurStateBlock )
{
zDefined = true;
zEnable = false;
zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
};
singleton GFXStateBlockData( PFX_DOFFinalStateBlock )
{
zDefined = true;
zEnable = false;
zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
samplerStates[1] = SamplerClampLinear;
samplerStates[2] = SamplerClampLinear;
samplerStates[3] = SamplerClampPoint;
blendDefined = true;
blendEnable = true;
blendDest = GFXBlendInvSrcAlpha;
blendSrc = GFXBlendOne;
};
singleton ShaderData( PFX_DOFDownSampleShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/dof/DOF_DownSample_V.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/dof/DOF_DownSample_P.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/dof/gl/DOF_DownSample_V.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/dof/gl/DOF_DownSample_P.glsl";
samplerNames[0] = "$colorSampler";
samplerNames[1] = "$depthSampler";
pixVersion = 3.0;
};
singleton ShaderData( PFX_DOFBlurYShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/dof/DOF_Gausian_V.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/dof/DOF_Gausian_P.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/dof/gl/DOF_Gausian_V.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/dof/gl/DOF_Gausian_P.glsl";
samplerNames[0] = "$diffuseMap";
pixVersion = 2.0;
defines = "BLUR_DIR=float2(0.0,1.0)";
};
singleton ShaderData( PFX_DOFBlurXShader : PFX_DOFBlurYShader )
{
defines = "BLUR_DIR=float2(1.0,0.0)";
};
singleton ShaderData( PFX_DOFCalcCoCShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/dof/DOF_CalcCoC_V.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/dof/DOF_CalcCoC_P.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/dof/gl/DOF_CalcCoC_V.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/dof/gl/DOF_CalcCoC_P.glsl";
samplerNames[0] = "$shrunkSampler";
samplerNames[1] = "$blurredSampler";
pixVersion = 3.0;
};
singleton ShaderData( PFX_DOFSmallBlurShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/dof/DOF_SmallBlur_V.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/dof/DOF_SmallBlur_P.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/dof/gl/DOF_SmallBlur_V.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/dof/gl/DOF_SmallBlur_P.glsl";
samplerNames[0] = "$colorSampler";
pixVersion = 3.0;
};
singleton ShaderData( PFX_DOFFinalShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/dof/DOF_Final_V.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/dof/DOF_Final_P.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/dof/gl/DOF_Final_V.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/dof/gl/DOF_Final_P.glsl";
samplerNames[0] = "$colorSampler";
samplerNames[1] = "$smallBlurSampler";
samplerNames[2] = "$largeBlurSampler";
samplerNames[3] = "$depthSampler";
pixVersion = 3.0;
};
//-----------------------------------------------------------------------------
// PostEffects
//-----------------------------------------------------------------------------
function DOFPostEffect::onAdd( %this )
{
// The weighted distribution of CoC value to the three blur textures
// in the order small, medium, large. Most likely you will not need to
// change this value.
%this.setLerpDist( 0.2, 0.3, 0.5 );
// Fill out some default values but DOF really should not be turned on
// without actually specifying your own parameters!
%this.autoFocusEnabled = false;
%this.focalDist = 0.0;
%this.nearBlurMax = 0.5;
%this.farBlurMax = 0.5;
%this.minRange = 50;
%this.maxRange = 500;
%this.nearSlope = -5.0;
%this.farSlope = 5.0;
}
function DOFPostEffect::setLerpDist( %this, %d0, %d1, %d2 )
{
%this.lerpScale = -1.0 / %d0 SPC -1.0 / %d1 SPC -1.0 / %d2 SPC 1.0 / %d2;
%this.lerpBias = 1.0 SPC ( 1.0 - %d2 ) / %d1 SPC 1.0 / %d2 SPC ( %d2 - 1.0 ) / %d2;
}
singleton PostEffect( DOFPostEffect )
{
renderTime = "PFXAfterBin";
renderBin = "GlowBin";
renderPriority = 0.1;
shader = PFX_DOFDownSampleShader;
stateBlock = PFX_DOFDownSampleStateBlock;
texture[0] = "$backBuffer";
texture[1] = "#prepass";
target = "#shrunk";
targetScale = "0.25 0.25";
isEnabled = false;
};
singleton PostEffect( DOFBlurY )
{
shader = PFX_DOFBlurYShader;
stateBlock = PFX_DOFBlurStateBlock;
texture[0] = "#shrunk";
target = "$outTex";
};
DOFPostEffect.add( DOFBlurY );
singleton PostEffect( DOFBlurX )
{
shader = PFX_DOFBlurXShader;
stateBlock = PFX_DOFBlurStateBlock;
texture[0] = "$inTex";
target = "#largeBlur";
};
DOFPostEffect.add( DOFBlurX );
singleton PostEffect( DOFCalcCoC )
{
shader = PFX_DOFCalcCoCShader;
stateBlock = PFX_DOFCalcCoCStateBlock;
texture[0] = "#shrunk";
texture[1] = "#largeBlur";
target = "$outTex";
};
DOFPostEffect.add( DOFCalcCoc );
singleton PostEffect( DOFSmallBlur )
{
shader = PFX_DOFSmallBlurShader;
stateBlock = PFX_DefaultDOFStateBlock;
texture[0] = "$inTex";
target = "$outTex";
};
DOFPostEffect.add( DOFSmallBlur );
singleton PostEffect( DOFFinalPFX )
{
shader = PFX_DOFFinalShader;
stateBlock = PFX_DOFFinalStateBlock;
texture[0] = "$backBuffer";
texture[1] = "$inTex";
texture[2] = "#largeBlur";
texture[3] = "#prepass";
target = "$backBuffer";
};
DOFPostEffect.add( DOFFinalPFX );
//-----------------------------------------------------------------------------
// Scripts
//-----------------------------------------------------------------------------
function DOFPostEffect::setShaderConsts( %this )
{
if ( %this.autoFocusEnabled )
%this.autoFocus();
%fd = %this.focalDist / $Param::FarDist;
%range = mLerp( %this.minRange, %this.maxRange, %fd ) / $Param::FarDist * 0.5;
// We work in "depth" space rather than real-world units for the
// rest of this method...
// Given the focal distance and the range around it we want in focus
// we can determine the near-end-distance and far-start-distance
%ned = getMax( %fd - %range, 0.0 );
%fsd = getMin( %fd + %range, 1.0 );
// near slope
%nsl = %this.nearSlope;
// Given slope of near blur equation and the near end dist and amount (x2,y2)
// solve for the y-intercept
// y = mx + b
// so...
// y - mx = b
%b = 0.0 - %nsl * %ned;
%eqNear = %nsl SPC %b SPC 0.0;
// Do the same for the far blur equation...
%fsl = %this.farSlope;
%b = 0.0 - %fsl * %fsd;
%eqFar = %fsl SPC %b SPC 1.0;
%this.setShaderConst( "$dofEqWorld", %eqNear );
DOFFinalPFX.setShaderConst( "$dofEqFar", %eqFar );
%this.setShaderConst( "$maxWorldCoC", %this.nearBlurMax );
DOFFinalPFX.setShaderConst( "$maxFarCoC", %this.farBlurMax );
DOFFinalPFX.setShaderConst( "$dofLerpScale", %this.lerpScale );
DOFFinalPFX.setShaderConst( "$dofLerpBias", %this.lerpBias );
}
function DOFPostEffect::autoFocus( %this )
{
if ( !isObject( ServerConnection ) ||
!isObject( ServerConnection.getCameraObject() ) )
{
return;
}
%mask = $TypeMasks::StaticObjectType | $TypeMasks::TerrainObjectType;
%control = ServerConnection.getCameraObject();
%fvec = %control.getEyeVector();
%start = %control.getEyePoint();
%end = VectorAdd( %start, VectorScale( %fvec, $Param::FarDist ) );
// Use the client container for this ray cast.
%result = containerRayCast( %start, %end, %mask, %control, true );
%hitPos = getWords( %result, 1, 3 );
if ( %hitPos $= "" )
%focDist = $Param::FarDist;
else
%focDist = VectorDist( %hitPos, %start );
// For debuging
//$DOF::debug_dist = %focDist;
//$DOF::debug_depth = %focDist / $Param::FarDist;
//echo( "F: " @ %focDist SPC "D: " @ %delta );
%this.focalDist = %focDist;
}
// For debugging
/*
function reloadDOF()
{
exec( "./dof.cs" );
DOFPostEffect.reload();
DOFPostEffect.disable();
DOFPostEffect.enable();
}
function dofMetricsCallback()
{
return " | DOF |" @
" Dist: " @ $DOF::debug_dist @
" Depth: " @ $DOF::debug_depth;
}
*/

View file

@ -0,0 +1,113 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
singleton GFXStateBlockData( PFX_DefaultEdgeAAStateBlock )
{
zDefined = true;
zEnable = false;
zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint;
//samplerStates[1] = SamplerWrapPoint;
};
singleton ShaderData( PFX_EdgeAADetectShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/edgeaa/edgeDetectP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/edgeaa/gl/edgeDetectP.glsl";
samplerNames[0] = "$prepassBuffer";
pixVersion = 3.0;
};
singleton ShaderData( PFX_EdgeAAShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/edgeaa/edgeAAV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/edgeaa/edgeAAP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/edgeaa/gl/edgeAAV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/edgeaa/gl/edgeAAP.glsl";
samplerNames[0] = "$edgeBuffer";
samplerNames[1] = "$backBuffer";
pixVersion = 3.0;
};
singleton ShaderData( PFX_EdgeAADebugShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/edgeaa/dbgEdgeDisplayP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/edgeaa/gl/dbgEdgeDisplayP.glsl";
samplerNames[0] = "$edgeBuffer";
pixVersion = 3.0;
};
singleton PostEffect( EdgeDetectPostEffect )
{
renderTime = "PFXBeforeBin";
renderBin = "ObjTranslucentBin";
//renderPriority = 0.1;
targetScale = "0.5 0.5";
shader = PFX_EdgeAADetectShader;
stateBlock = PFX_DefaultEdgeAAStateBlock;
texture[0] = "#prepass";
target = "#edge";
isEnabled = true;
};
singleton PostEffect( EdgeAAPostEffect )
{
renderTime = "PFXAfterDiffuse";
//renderBin = "ObjTranslucentBin";
//renderPriority = 0.1;
shader = PFX_EdgeAAShader;
stateBlock = PFX_DefaultEdgeAAStateBlock;
texture[0] = "#edge";
texture[1] = "$backBuffer";
target = "$backBuffer";
};
singleton PostEffect( Debug_EdgeAAPostEffect )
{
renderTime = "PFXAfterDiffuse";
//renderBin = "ObjTranslucentBin";
//renderPriority = 0.1;
shader = PFX_EdgeAADebugShader;
stateBlock = PFX_DefaultEdgeAAStateBlock;
texture[0] = "#edge";
target = "$backBuffer";
};

View file

@ -0,0 +1,63 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
singleton ShaderData( PFX_FlashShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/flashP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gl/flashP.glsl";
samplerNames[0] = "$backBuffer";
defines = "WHITE_COLOR=float4(1.0,1.0,1.0,0.0);MUL_COLOR=float4(1.0,0.25,0.25,0.0)";
pixVersion = 2.0;
};
singleton PostEffect( FlashFx )
{
isEnabled = false;
allowReflectPass = false;
renderTime = "PFXAfterDiffuse";
shader = PFX_FlashShader;
texture[0] = "$backBuffer";
renderPriority = 10;
stateBlock = PFX_DefaultStateBlock;
};
function FlashFx::setShaderConsts( %this )
{
if ( isObject( ServerConnection ) )
{
%this.setShaderConst( "$damageFlash", ServerConnection.getDamageFlash() );
%this.setShaderConst( "$whiteOut", ServerConnection.getWhiteOut() );
}
else
{
%this.setShaderConst( "$damageFlash", 0 );
%this.setShaderConst( "$whiteOut", 0 );
}
}

View file

@ -0,0 +1,135 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Fog
//------------------------------------------------------------------------------
singleton ShaderData( FogPassShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/fogP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gl/fogP.glsl";
samplerNames[0] = "$prepassTex";
pixVersion = 2.0;
};
singleton GFXStateBlockData( FogPassStateBlock : PFX_DefaultStateBlock )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendSrcAlpha;
blendDest = GFXBlendInvSrcAlpha;
};
singleton PostEffect( FogPostFx )
{
// We forward render the reflection pass
// so it does its own fogging.
allowReflectPass = false;
renderTime = "PFXBeforeBin";
renderBin = "ObjTranslucentBin";
shader = FogPassShader;
stateBlock = FogPassStateBlock;
texture[0] = "#prepass";
renderPriority = 5;
targetFormat = getBestHDRFormat();
isEnabled = true;
};
//------------------------------------------------------------------------------
// UnderwaterFog
//------------------------------------------------------------------------------
singleton ShaderData( UnderwaterFogPassShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/underwaterFogP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gl/underwaterFogP.glsl";
samplerNames[0] = "$prepassTex";
samplerNames[1] = "$backbuffer";
samplerNames[2] = "$waterDepthGradMap";
pixVersion = 2.0;
};
singleton GFXStateBlockData( UnderwaterFogPassStateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampPoint;
samplerStates[1] = SamplerClampPoint;
samplerStates[2] = SamplerClampLinear;
};
singleton PostEffect( UnderwaterFogPostFx )
{
oneFrameOnly = true;
onThisFrame = false;
// Let the fog effect render during the
// reflection pass.
allowReflectPass = true;
renderTime = "PFXBeforeBin";
renderBin = "ObjTranslucentBin";
shader = UnderwaterFogPassShader;
stateBlock = UnderwaterFogPassStateBlock;
texture[0] = "#prepass";
texture[1] = "$backBuffer";
texture[2] = "#waterDepthGradMap";
// Needs to happen after the FogPostFx
renderPriority = 4;
isEnabled = true;
};
function UnderwaterFogPostFx::onEnabled( %this )
{
TurbulenceFx.enable();
CausticsPFX.enable();
return true;
}
function UnderwaterFogPostFx::onDisabled( %this )
{
TurbulenceFx.disable();
CausticsPFX.disable();
return false;
}

View file

@ -0,0 +1,64 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "NVIDIA FXAA 3.11" by TIMOTHY LOTTES
//
// http://timothylottes.blogspot.com/
//
// The shader is tuned for the defaul quality and good performance.
// See shaders\common\postFx\fxaa\fxaaP.hlsl to tweak the internal
// quality and performance settings.
singleton GFXStateBlockData( FXAA_StateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
};
singleton ShaderData( FXAA_ShaderData )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/fxaa/fxaaV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/fxaa/fxaaP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/fxaa/gl/fxaaV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/fxaa/gl/fxaaP.glsl";
samplerNames[0] = "$colorTex";
pixVersion = 3.0;
};
singleton PostEffect( FXAA_PostEffect )
{
isEnabled = false;
allowReflectPass = false;
renderTime = "PFXAfterDiffuse";
texture[0] = "$backBuffer";
target = "$backBuffer";
stateBlock = FXAA_StateBlock;
shader = FXAA_ShaderData;
};

View file

@ -0,0 +1,184 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
singleton ShaderData( PFX_GlowBlurVertShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/glowBlurV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/glowBlurP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/gl/glowBlurV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gl/glowBlurP.glsl";
defines = "BLUR_DIR=float2(0.0,1.0)";
samplerNames[0] = "$diffuseMap";
pixVersion = 2.0;
};
singleton ShaderData( PFX_GlowBlurHorzShader : PFX_GlowBlurVertShader )
{
defines = "BLUR_DIR=float2(1.0,0.0)";
};
singleton GFXStateBlockData( PFX_GlowCombineStateBlock : PFX_DefaultStateBlock )
{
// Use alpha test to save some fillrate
// on the non-glowing areas of the scene.
alphaDefined = true;
alphaTestEnable = true;
alphaTestRef = 1;
alphaTestFunc = GFXCmpGreaterEqual;
// Do a one to one blend.
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendOne;
blendDest = GFXBlendOne;
};
singleton PostEffect( GlowPostFx )
{
// Do not allow the glow effect to work in reflection
// passes by default so we don't do the extra drawing.
allowReflectPass = false;
renderTime = "PFXAfterBin";
renderBin = "GlowBin";
renderPriority = 1;
// First we down sample the glow buffer.
shader = PFX_PassthruShader;
stateBlock = PFX_DefaultStateBlock;
texture[0] = "#glowbuffer";
target = "$outTex";
targetScale = "0.5 0.5";
isEnabled = true;
// Blur vertically
new PostEffect()
{
shader = PFX_GlowBlurVertShader;
stateBlock = PFX_DefaultStateBlock;
texture[0] = "$inTex";
target = "$outTex";
};
// Blur horizontally
new PostEffect()
{
shader = PFX_GlowBlurHorzShader;
stateBlock = PFX_DefaultStateBlock;
texture[0] = "$inTex";
target = "$outTex";
};
// Upsample and combine with the back buffer.
new PostEffect()
{
shader = PFX_PassthruShader;
stateBlock = PFX_GlowCombineStateBlock;
texture[0] = "$inTex";
target = "$backBuffer";
};
};
singleton ShaderData( PFX_VolFogGlowBlurVertShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/glowBlurV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/VolFogGlowP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/gl/glowBlurV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gl/VolFogGlowP.glsl";
defines = "BLUR_DIR=float2(0.0,1.0)";
samplerNames[0] = "$diffuseMap";
pixVersion = 2.0;
};
singleton ShaderData( PFX_VolFogGlowBlurHorzShader : PFX_VolFogGlowBlurVertShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/glowBlurV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/VolFogGlowP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/gl/glowBlurV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gl/VolFogGlowP.glsl";
defines = "BLUR_DIR=float2(1.0,0.0)";
};
$VolFogGlowPostFx::glowStrength = 0.3;
singleton PostEffect( VolFogGlowPostFx )
{
// Do not allow the glow effect to work in reflection
// passes by default so we don't do the extra drawing.
allowReflectPass = false;
renderTime = "PFXAfterBin";
renderBin = "FogBin";
renderPriority = 1;
// First we down sample the glow buffer.
shader = PFX_PassthruShader;
stateBlock = PFX_DefaultStateBlock;
texture[0] = "$backbuffer";
target = "$outTex";
targetScale = "0.5 0.5";
isEnabled = true;
// Blur vertically
new PostEffect()
{
shader = PFX_VolFogGlowBlurVertShader;
stateBlock = PFX_DefaultStateBlock;
internalName = "vert";
texture[0] = "$inTex";
target = "$outTex";
};
// Blur horizontally
new PostEffect()
{
shader = PFX_VolFogGlowBlurHorzShader;
stateBlock = PFX_DefaultStateBlock;
internalName = "hor";
texture[0] = "$inTex";
target = "$outTex";
};
// Upsample and combine with the back buffer.
new PostEffect()
{
shader = PFX_PassthruShader;
stateBlock = PFX_GlowCombineStateBlock;
texture[0] = "$inTex";
target = "$backBuffer";
};
};
function VolFogGlowPostFx::setShaderConsts( %this )
{
%vp=%this-->vert;
%vp.setShaderConst( "$strength", $VolFogGlowPostFx::glowStrength );
%vp=%this-->hor;
%vp.setShaderConst( "$strength", $VolFogGlowPostFx::glowStrength );
}

View file

@ -0,0 +1,533 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
/// Blends between the scene and the tone mapped scene.
$HDRPostFX::enableToneMapping = 0.5;
/// The tone mapping middle grey or exposure value used
/// to adjust the overall "balance" of the image.
///
/// 0.18 is fairly common value.
///
$HDRPostFX::keyValue = 0.18;
/// The minimum luninace value to allow when tone mapping
/// the scene. Is particularly useful if your scene very
/// dark or has a black ambient color in places.
$HDRPostFX::minLuminace = 0.001;
/// The lowest luminance value which is mapped to white. This
/// is usually set to the highest visible luminance in your
/// scene. By setting this to smaller values you get a contrast
/// enhancement.
$HDRPostFX::whiteCutoff = 1.0;
/// The rate of adaptation from the previous and new
/// average scene luminance.
$HDRPostFX::adaptRate = 2.0;
/// Blends between the scene and the blue shifted version
/// of the scene for a cinematic desaturated night effect.
$HDRPostFX::enableBlueShift = 0.0;
/// The blue shift color value.
$HDRPostFX::blueShiftColor = "1.05 0.97 1.27";
/// Blends between the scene and the bloomed scene.
$HDRPostFX::enableBloom = 1.0;
/// The threshold luminace value for pixels which are
/// considered "bright" and need to be bloomed.
$HDRPostFX::brightPassThreshold = 1.0;
/// These are used in the gaussian blur of the
/// bright pass for the bloom effect.
$HDRPostFX::gaussMultiplier = 0.3;
$HDRPostFX::gaussMean = 0.0;
$HDRPostFX::gaussStdDev = 0.8;
/// The 1x255 color correction ramp texture used
/// by both the HDR shader and the GammaPostFx shader
/// for doing full screen color correction.
$HDRPostFX::colorCorrectionRamp = "data/postFX/art/null_color_ramp.png";
singleton ShaderData( HDR_BrightPassShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/brightPassFilterP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/gl/brightPassFilterP.glsl";
samplerNames[0] = "$inputTex";
samplerNames[1] = "$luminanceTex";
pixVersion = 3.0;
};
singleton ShaderData( HDR_DownScale4x4Shader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/downScale4x4V.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/downScale4x4P.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/gl/downScale4x4V.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/gl/downScale4x4P.glsl";
samplerNames[0] = "$inputTex";
pixVersion = 2.0;
};
singleton ShaderData( HDR_BloomGaussBlurHShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/bloomGaussBlurHP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/gl/bloomGaussBlurHP.glsl";
samplerNames[0] = "$inputTex";
pixVersion = 3.0;
};
singleton ShaderData( HDR_BloomGaussBlurVShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/bloomGaussBlurVP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/gl/bloomGaussBlurVP.glsl";
samplerNames[0] = "$inputTex";
pixVersion = 3.0;
};
singleton ShaderData( HDR_SampleLumShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/sampleLumInitialP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/gl/sampleLumInitialP.glsl";
samplerNames[0] = "$inputTex";
pixVersion = 3.0;
};
singleton ShaderData( HDR_DownSampleLumShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/sampleLumIterativeP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/gl/sampleLumIterativeP.glsl";
samplerNames[0] = "$inputTex";
pixVersion = 3.0;
};
singleton ShaderData( HDR_CalcAdaptedLumShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/calculateAdaptedLumP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/gl/calculateAdaptedLumP.glsl";
samplerNames[0] = "$currLum";
samplerNames[1] = "$lastAdaptedLum";
pixVersion = 3.0;
};
singleton ShaderData( HDR_CombineShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/finalPassCombineP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/gl/finalPassCombineP.glsl";
samplerNames[0] = "$sceneTex";
samplerNames[1] = "$luminanceTex";
samplerNames[2] = "$bloomTex";
samplerNames[3] = "$colorCorrectionTex";
samplerNames[4] = "prepassTex";
pixVersion = 3.0;
};
singleton GFXStateBlockData( HDR_SampleStateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampPoint;
samplerStates[1] = SamplerClampPoint;
};
singleton GFXStateBlockData( HDR_DownSampleStateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
samplerStates[1] = SamplerClampLinear;
};
singleton GFXStateBlockData( HDR_CombineStateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampPoint;
samplerStates[1] = SamplerClampLinear;
samplerStates[2] = SamplerClampLinear;
samplerStates[3] = SamplerClampLinear;
};
singleton GFXStateBlockData( HDRStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
samplerStates[1] = SamplerClampLinear;
samplerStates[2] = SamplerClampLinear;
samplerStates[3] = SamplerClampLinear;
blendDefined = true;
blendDest = GFXBlendOne;
blendSrc = GFXBlendZero;
zDefined = true;
zEnable = false;
zWriteEnable = false;
cullDefined = true;
cullMode = GFXCullNone;
};
function HDRPostFX::setShaderConsts( %this )
{
%this.setShaderConst( "$brightPassThreshold", $HDRPostFX::brightPassThreshold );
%this.setShaderConst( "$g_fMiddleGray", $HDRPostFX::keyValue );
%bloomH = %this-->bloomH;
%bloomH.setShaderConst( "$gaussMultiplier", $HDRPostFX::gaussMultiplier );
%bloomH.setShaderConst( "$gaussMean", $HDRPostFX::gaussMean );
%bloomH.setShaderConst( "$gaussStdDev", $HDRPostFX::gaussStdDev );
%bloomV = %this-->bloomV;
%bloomV.setShaderConst( "$gaussMultiplier", $HDRPostFX::gaussMultiplier );
%bloomV.setShaderConst( "$gaussMean", $HDRPostFX::gaussMean );
%bloomV.setShaderConst( "$gaussStdDev", $HDRPostFX::gaussStdDev );
%minLuminace = $HDRPostFX::minLuminace;
if ( %minLuminace <= 0.0 )
{
// The min should never be pure zero else the
// log() in the shader will generate INFs.
%minLuminace = 0.00001;
}
%this-->adaptLum.setShaderConst( "$g_fMinLuminace", %minLuminace );
%this-->finalLum.setShaderConst( "$adaptRate", $HDRPostFX::adaptRate );
%combinePass = %this-->combinePass;
%combinePass.setShaderConst( "$g_fEnableToneMapping", $HDRPostFX::enableToneMapping );
%combinePass.setShaderConst( "$g_fMiddleGray", $HDRPostFX::keyValue );
%combinePass.setShaderConst( "$g_fBloomScale", $HDRPostFX::enableBloom );
%combinePass.setShaderConst( "$g_fEnableBlueShift", $HDRPostFX::enableBlueShift );
%combinePass.setShaderConst( "$g_fBlueShiftColor", $HDRPostFX::blueShiftColor );
%clampedGamma = mClamp( $pref::Video::Gamma, 2.0, 2.5);
%combinePass.setShaderConst( "$g_fOneOverGamma", 1 / %clampedGamma );
%combinePass.setShaderConst( "$Brightness", $pref::Video::Brightness );
%combinePass.setShaderConst( "$Contrast", $pref::Video::Contrast );
%whiteCutoff = ( $HDRPostFX::whiteCutoff * $HDRPostFX::whiteCutoff ) *
( $HDRPostFX::whiteCutoff * $HDRPostFX::whiteCutoff );
%combinePass.setShaderConst( "$g_fWhiteCutoff", %whiteCutoff );
}
function HDRPostFX::preProcess( %this )
{
%combinePass = %this-->combinePass;
if ( %combinePass.texture[3] !$= $HDRPostFX::colorCorrectionRamp )
%combinePass.setTexture( 3, $HDRPostFX::colorCorrectionRamp );
}
function HDRPostFX::onEnabled( %this )
{
// We don't allow hdr on OSX yet.
if ( $platform $= "macos" )
return false;
// See what HDR format would be best.
%format = getBestHDRFormat();
if ( %format $= "" || %format $= "GFXFormatR8G8B8A8" )
{
// We didn't get a valid HDR format... so fail.
return false;
}
// HDR does it's own gamma calculation so
// disable this postFx.
GammaPostFX.disable();
// Set the right global shader define for HDR.
if ( %format $= "GFXFormatR10G10B10A2" )
addGlobalShaderMacro( "TORQUE_HDR_RGB10" );
else if ( %format $= "GFXFormatR16G16B16A16" )
addGlobalShaderMacro( "TORQUE_HDR_RGB16" );
echo( "HDR FORMAT: " @ %format );
// Change the format of the offscreen surface
// to an HDR compatible format.
AL_FormatToken.format = %format;
setReflectFormat( %format );
// Reset the light manager which will ensure the new
// hdr encoding takes effect in all the shaders and
// that the offscreen surface is enabled.
resetLightManager();
return true;
}
function HDRPostFX::onDisabled( %this )
{
// Enable a special GammaCorrection PostFX when this is disabled.
GammaPostFX.enable();
// Restore the non-HDR offscreen surface format.
%format = getBestHDRFormat();
AL_FormatToken.format = %format;
setReflectFormat( %format );
removeGlobalShaderMacro( "TORQUE_HDR_RGB10" );
removeGlobalShaderMacro( "TORQUE_HDR_RGB16" );
// Reset the light manager which will ensure the new
// hdr encoding takes effect in all the shaders.
resetLightManager();
}
singleton PostEffect( HDRPostFX )
{
isEnabled = false;
allowReflectPass = false;
// Resolve the HDR before we render any editor stuff
// and before we resolve the scene to the backbuffer.
renderTime = "PFXBeforeBin";
renderBin = "EditorBin";
renderPriority = 9999;
// The bright pass generates a bloomed version of
// the scene for pixels which are brighter than a
// fixed threshold value.
//
// This is then used in the final HDR combine pass
// at the end of this post effect chain.
//
shader = HDR_BrightPassShader;
stateBlock = HDR_DownSampleStateBlock;
texture[0] = "$backBuffer";
texture[1] = "#adaptedLum";
target = "$outTex";
targetFormat = "GFXFormatR16G16B16A16F";
targetScale = "0.5 0.5";
new PostEffect()
{
allowReflectPass = false;
shader = HDR_DownScale4x4Shader;
stateBlock = HDR_DownSampleStateBlock;
texture[0] = "$inTex";
target = "$outTex";
targetFormat = "GFXFormatR16G16B16A16F";
targetScale = "0.25 0.25";
};
new PostEffect()
{
allowReflectPass = false;
internalName = "bloomH";
shader = HDR_BloomGaussBlurHShader;
stateBlock = HDR_DownSampleStateBlock;
texture[0] = "$inTex";
target = "$outTex";
targetFormat = "GFXFormatR16G16B16A16F";
};
new PostEffect()
{
allowReflectPass = false;
internalName = "bloomV";
shader = HDR_BloomGaussBlurVShader;
stateBlock = HDR_DownSampleStateBlock;
texture[0] = "$inTex";
target = "#bloomFinal";
targetFormat = "GFXFormatR16G16B16A16F";
};
// BrightPass End
// Now calculate the adapted luminance.
new PostEffect()
{
allowReflectPass = false;
internalName = "adaptLum";
shader = HDR_SampleLumShader;
stateBlock = HDR_DownSampleStateBlock;
texture[0] = "$backBuffer";
target = "$outTex";
targetScale = "0.0625 0.0625"; // 1/16th
targetFormat = "GFXFormatR16F";
new PostEffect()
{
allowReflectPass = false;
shader = HDR_DownSampleLumShader;
stateBlock = HDR_DownSampleStateBlock;
texture[0] = "$inTex";
target = "$outTex";
targetScale = "0.25 0.25"; // 1/4
targetFormat = "GFXFormatR16F";
};
new PostEffect()
{
allowReflectPass = false;
shader = HDR_DownSampleLumShader;
stateBlock = HDR_DownSampleStateBlock;
texture[0] = "$inTex";
target = "$outTex";
targetScale = "0.25 0.25"; // 1/4
targetFormat = "GFXFormatR16F";
};
new PostEffect()
{
allowReflectPass = false;
shader = HDR_DownSampleLumShader;
stateBlock = HDR_DownSampleStateBlock;
texture[0] = "$inTex";
target = "$outTex";
targetScale = "0.25 0.25"; // At this point the target should be 1x1.
targetFormat = "GFXFormatR16F";
};
// Note that we're reading the adapted luminance
// from the previous frame when generating this new
// one... PostEffect takes care to manage that.
new PostEffect()
{
allowReflectPass = false;
internalName = "finalLum";
shader = HDR_CalcAdaptedLumShader;
stateBlock = HDR_DownSampleStateBlock;
texture[0] = "$inTex";
texture[1] = "#adaptedLum";
target = "#adaptedLum";
targetFormat = "GFXFormatR16F";
targetClear = "PFXTargetClear_OnCreate";
targetClearColor = "1 1 1 1";
};
};
// Output the combined bloom and toned mapped
// version of the scene.
new PostEffect()
{
allowReflectPass = false;
internalName = "combinePass";
shader = HDR_CombineShader;
stateBlock = HDR_CombineStateBlock;
texture[0] = "$backBuffer";
texture[1] = "#adaptedLum";
texture[2] = "#bloomFinal";
texture[3] = $HDRPostFX::colorCorrectionRamp;
target = "$backBuffer";
};
};
singleton ShaderData( LuminanceVisShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/luminanceVisP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/hdr/gl/luminanceVisP.glsl";
samplerNames[0] = "$inputTex";
pixVersion = 3.0;
};
singleton GFXStateBlockData( LuminanceVisStateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
};
function LuminanceVisPostFX::setShaderConsts( %this )
{
%this.setShaderConst( "$brightPassThreshold", $HDRPostFX::brightPassThreshold );
}
singleton PostEffect( LuminanceVisPostFX )
{
isEnabled = false;
allowReflectPass = false;
// Render before we do any editor rendering.
renderTime = "PFXBeforeBin";
renderBin = "EditorBin";
renderPriority = 9999;
shader = LuminanceVisShader;
stateBlock = LuminanceVisStateBlock;
texture[0] = "$backBuffer";
target = "$backBuffer";
//targetScale = "0.0625 0.0625"; // 1/16th
//targetFormat = "GFXFormatR16F";
};
function LuminanceVisPostFX::onEnabled( %this )
{
if ( !HDRPostFX.isEnabled() )
{
HDRPostFX.enable();
}
HDRPostFX.skip = true;
return true;
}
function LuminanceVisPostFX::onDisabled( %this )
{
HDRPostFX.skip = false;
}

View file

@ -0,0 +1,110 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
$LightRayPostFX::brightScalar = 0.75;
$LightRayPostFX::numSamples = 40;
$LightRayPostFX::density = 0.94;
$LightRayPostFX::weight = 5.65;
$LightRayPostFX::decay = 1.0;
$LightRayPostFX::exposure = 0.0005;
$LightRayPostFX::resolutionScale = 1.0;
singleton ShaderData( LightRayOccludeShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/lightRay/lightRayOccludeP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/lightRay/gl/lightRayOccludeP.glsl";
samplerNames[0] = "$backBuffer";
samplerNames[1] = "$prepassTex";
pixVersion = 3.0;
};
singleton ShaderData( LightRayShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/lightRay/lightRayP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/lightRay/gl/lightRayP.glsl";
samplerNames[0] = "$frameSampler";
samplerNames[1] = "$backBuffer";
pixVersion = 3.0;
};
singleton GFXStateBlockData( LightRayStateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
samplerStates[1] = SamplerClampLinear;
};
singleton PostEffect( LightRayPostFX )
{
isEnabled = false;
allowReflectPass = false;
renderTime = "PFXBeforeBin";
renderBin = "EditorBin";
renderPriority = 10;
shader = LightRayOccludeShader;
stateBlock = LightRayStateBlock;
texture[0] = "$backBuffer";
texture[1] = "#prepass";
target = "$outTex";
targetFormat = "GFXFormatR16G16B16A16F";
new PostEffect()
{
shader = LightRayShader;
stateBlock = LightRayStateBlock;
internalName = "final";
texture[0] = "$inTex";
texture[1] = "$backBuffer";
target = "$backBuffer";
};
};
function LightRayPostFX::preProcess( %this )
{
%this.targetScale = $LightRayPostFX::resolutionScale SPC $LightRayPostFX::resolutionScale;
}
function LightRayPostFX::setShaderConsts( %this )
{
%this.setShaderConst( "$brightScalar", $LightRayPostFX::brightScalar );
%pfx = %this-->final;
%pfx.setShaderConst( "$numSamples", $LightRayPostFX::numSamples );
%pfx.setShaderConst( "$density", $LightRayPostFX::density );
%pfx.setShaderConst( "$weight", $LightRayPostFX::weight );
%pfx.setShaderConst( "$decay", $LightRayPostFX::decay );
%pfx.setShaderConst( "$exposure", $LightRayPostFX::exposure );
}

View file

@ -0,0 +1,167 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Only load these shaders if an Oculus VR device is present
if(!isFunction(isOculusVRDeviceActive))
return;
//-----------------------------------------------------------------------------
// Shader data
//-----------------------------------------------------------------------------
singleton ShaderData( OVRMonoToStereoShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/oculusvr/monoToStereoP.hlsl";
//OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/gl/postFxV.hlsl";
//OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/oculusvr/gl/monoToStereoP.glsl";
samplerNames[0] = "$backBuffer";
pixVersion = 2.0;
};
singleton ShaderData( OVRBarrelDistortionShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/oculusvr/barrelDistortionP.hlsl";
//OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/gl/postFxV.glsl";
//OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/oculusvr/gl/barrelDistortionP.glsl";
samplerNames[0] = "$backBuffer";
pixVersion = 2.0;
};
singleton ShaderData( OVRBarrelDistortionChromaShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/oculusvr/barrelDistortionChromaP.hlsl";
pixVersion = 2.0;
};
//-----------------------------------------------------------------------------
// GFX state blocks
//-----------------------------------------------------------------------------
singleton GFXStateBlockData( OVRBarrelDistortionStateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
};
//-----------------------------------------------------------------------------
// Barrel Distortion PostFx
//
// To be used with the Oculus Rift.
// Expects a stereo pair to exist on the back buffer and then applies the
// appropriate barrel distortion.
//-----------------------------------------------------------------------------
singleton BarrelDistortionPostEffect( OVRBarrelDistortionPostFX )
{
isEnabled = false;
allowReflectPass = false;
renderTime = "PFXAfterDiffuse";
renderPriority = 100;
// The barrel distortion
shader = OVRBarrelDistortionShader;
stateBlock = OVRBarrelDistortionStateBlock;
texture[0] = "$backBuffer";
scaleOutput = 1.25;
};
//-----------------------------------------------------------------------------
// Barrel Distortion with Chromatic Aberration Correction PostFx
//
// To be used with the Oculus Rift.
// Expects a stereo pair to exist on the back buffer and then applies the
// appropriate barrel distortion.
// This version applies a chromatic aberration correction during the
// barrel distortion.
//-----------------------------------------------------------------------------
singleton BarrelDistortionPostEffect( OVRBarrelDistortionChromaPostFX )
{
isEnabled = false;
allowReflectPass = false;
renderTime = "PFXAfterDiffuse";
renderPriority = 100;
// The barrel distortion
shader = OVRBarrelDistortionChromaShader;
stateBlock = OVRBarrelDistortionStateBlock;
texture[0] = "$backBuffer";
scaleOutput = 1.25;
};
//-----------------------------------------------------------------------------
// Barrel Distortion Mono PostFx
//
// To be used with the Oculus Rift.
// Takes a non-stereo image and turns it into a stereo pair with barrel
// distortion applied. Only a vertical slice around the center of the back
// buffer is used to generate the pseudo stereo pair.
//-----------------------------------------------------------------------------
singleton PostEffect( OVRBarrelDistortionMonoPostFX )
{
isEnabled = false;
allowReflectPass = false;
renderTime = "PFXAfterDiffuse";
renderPriority = 100;
// Converts the mono display to a stereo one
shader = OVRMonoToStereoShader;
stateBlock = OVRBarrelDistortionStateBlock;
texture[0] = "$backBuffer";
target = "$outTex";
// The actual barrel distortion
new BarrelDistortionPostEffect(OVRBarrelDistortionMonoStage2PostFX)
{
shader = OVRBarrelDistortionShader;
stateBlock = OVRBarrelDistortionStateBlock;
texture[0] = "$inTex";
target = "$backBuffer";
scaleOutput = 1.25;
};
};
function OVRBarrelDistortionMonoPostFX::setShaderConsts( %this )
{
%HMDIndex = 0;
%xOffsets = getOVRHMDEyeXOffsets(%HMDIndex);
%this.setShaderConst( "$LensXOffsets", %xOffsets );
}

View file

@ -0,0 +1,446 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
$PostFXManager::vebose = true;
function postVerbose(%string)
{
if($PostFXManager::vebose == true)
{
echo(%string);
}
}
function PostFXManager::onDialogPush( %this )
{
//Apply the settings to the controls
postVerbose("% - PostFX Manager - Loading GUI.");
%this.settingsRefreshAll();
}
// :: Controls for the overall postFX manager dialog
function ppOptionsEnable::onAction(%this)
{
//Disable / Enable all PostFX
if(ppOptionsEnable.getValue())
{
%toEnable = true;
}
else
{
%toEnable = false;
}
PostFXManager.settingsSetEnabled(%toEnable);
}
function PostFXManager::getEnableResultFromControl(%this, %control)
{
%toEnable = -1;
%bTest = %control.getValue();
if(%bTest == 1)
{
%toEnable = true;
}
else
{
%toEnable = false;
}
return %toEnable;
}
function ppOptionsEnableSSAO::onAction(%this)
{
%toEnable = PostFXManager.getEnableResultFromControl(%this);
PostFXManager.settingsEffectSetEnabled("SSAO", %toEnable);
}
function ppOptionsEnableHDR::onAction(%this)
{
%toEnable = PostFXManager.getEnableResultFromControl(%this);
PostFXManager.settingsEffectSetEnabled("HDR", %toEnable);
}
function ppOptionsEnableLightRays::onAction(%this)
{
%toEnable = PostFXManager.getEnableResultFromControl(%this);
PostFXManager.settingsEffectSetEnabled("LightRays", %toEnable);
}
function ppOptionsEnableDOF::onAction(%this)
{
%toEnable = PostFXManager.getEnableResultFromControl(%this);
PostFXManager.settingsEffectSetEnabled("DOF", %toEnable);
}
function ppOptionsEnableVignette::onAction(%this)
{
%toEnable = PostFXManager.getEnableResultFromControl(%this);
PostFXManager.settingsEffectSetEnabled("Vignette", %toEnable);
}
function ppOptionsSavePreset::onClick(%this)
{
//Stores the current settings into a preset file for loading and use later on
}
function ppOptionsLoadPreset::onClick(%this)
{
//Loads and applies the settings from a postfxpreset file
}
//Other controls, Quality dropdown
function ppOptionsSSAOQuality::onSelect( %this, %id, %text )
{
if(%id > -1 && %id < 3)
{
$SSAOPostFx::quality = %id;
}
}
//SSAO Slider controls
//General Tab
function ppOptionsSSAOOverallStrength::onMouseDragged(%this)
{
$SSAOPostFx::overallStrength = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAOBlurDepth::onMouseDragged(%this)
{
$SSAOPostFx::blurDepthTol = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAOBlurNormal::onMouseDragged(%this)
{
$SSAOPostFx::blurNormalTol = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
//Near Tab
function ppOptionsSSAONearRadius::onMouseDragged(%this)
{
$SSAOPostFx::sRadius = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAONearStrength::onMouseDragged(%this)
{
$SSAOPostFx::sStrength = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAONearDepthMin::onMouseDragged(%this)
{
$SSAOPostFx::sDepthMin = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAONearDepthMax::onMouseDragged(%this)
{
$SSAOPostFx::sDepthMax = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAONearToleranceNormal::onMouseDragged(%this)
{
$SSAOPostFx::sNormalTol = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAONearTolerancePower::onMouseDragged(%this)
{
$SSAOPostFx::sNormalPow = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
//Far Tab
function ppOptionsSSAOFarRadius::onMouseDragged(%this)
{
$SSAOPostFx::lRadius = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAOFarStrength::onMouseDragged(%this)
{
$SSAOPostFx::lStrength = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAOFarDepthMin::onMouseDragged(%this)
{
$SSAOPostFx::lDepthMin = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAOFarDepthMax::onMouseDragged(%this)
{
$SSAOPostFx::lDepthMax = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAOFarToleranceNormal::onMouseDragged(%this)
{
$SSAOPostFx::lNormalTol = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsSSAOFarTolerancePower::onMouseDragged(%this)
{
$SSAOPostFx::lNormalPow = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
//HDR Slider Controls
//Brighness tab
function ppOptionsHDRToneMappingAmount::onMouseDragged(%this)
{
$HDRPostFX::enableToneMapping = %this.value;
%this.ToolTip = "value : " @ %this.value;
}
function ppOptionsHDRKeyValue::onMouseDragged(%this)
{
$HDRPostFX::keyValue = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsHDRMinLuminance::onMouseDragged(%this)
{
$HDRPostFX::minLuminace = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsHDRWhiteCutoff::onMouseDragged(%this)
{
$HDRPostFX::whiteCutoff = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsHDRBrightnessAdaptRate::onMouseDragged(%this)
{
$HDRPostFX::adaptRate = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
//Blur tab
function ppOptionsHDRBloomBlurBrightPassThreshold::onMouseDragged(%this)
{
$HDRPostFX::brightPassThreshold = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsHDRBloomBlurMultiplier::onMouseDragged(%this)
{
$HDRPostFX::gaussMultiplier = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsHDRBloomBlurMean::onMouseDragged(%this)
{
$HDRPostFX::gaussMean = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsHDRBloomBlurStdDev::onMouseDragged(%this)
{
$HDRPostFX::gaussStdDev = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsHDRBloom::onAction(%this)
{
$HDRPostFX::enableBloom = %this.getValue();
}
function ppOptionsHDRToneMapping::onAction(%this)
{
//$HDRPostFX::enableToneMapping = %this.getValue();
}
function ppOptionsHDREffectsBlueShift::onAction(%this)
{
$HDRPostFX::enableBlueShift = %this.getValue();
}
//Controls for color range in blue Shift dialog
function ppOptionsHDREffectsBlueShiftColorBlend::onAction(%this)
{
$HDRPostFX::blueShiftColor = %this.PickColor;
%this.ToolTip = "Color Values : " @ %this.PickColor;
}
function ppOptionsHDREffectsBlueShiftColorBaseColor::onAction(%this)
{
//This one feeds the one above
ppOptionsHDREffectsBlueShiftColorBlend.baseColor = %this.PickColor;
%this.ToolTip = "Color Values : " @ %this.PickColor;
}
//Light rays Brightness Slider Controls
function ppOptionsLightRaysBrightScalar::onMouseDragged(%this)
{
$LightRayPostFX::brightScalar = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
//Light rays Number of Samples Slider Control
function ppOptionsLightRaysSampleScalar::onMouseDragged(%this)
{
$LightRayPostFX::numSamples = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
//Light rays Density Slider Control
function ppOptionsLightRaysDensityScalar::onMouseDragged(%this)
{
$LightRayPostFX::density = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
//Light rays Weight Slider Control
function ppOptionsLightRaysWeightScalar::onMouseDragged(%this)
{
$LightRayPostFX::weight = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
//Light rays Decay Slider Control
function ppOptionsLightRaysDecayScalar::onMouseDragged(%this)
{
$LightRayPostFX::decay = %this.value;
%this.ToolTip = "Value : " @ %this.value;
}
function ppOptionsUpdateDOFSettings()
{
DOFPostEffect.setFocusParams( $DOFPostFx::BlurMin, $DOFPostFx::BlurMax, $DOFPostFx::FocusRangeMin, $DOFPostFx::FocusRangeMax, -($DOFPostFx::BlurCurveNear), $DOFPostFx::BlurCurveFar );
DOFPostEffect.setAutoFocus( $DOFPostFx::EnableAutoFocus );
DOFPostEffect.setFocalDist(0);
if($PostFXManager::PostFX::EnableDOF)
{
DOFPostEffect.enable();
}
else
{
DOFPostEffect.disable();
}
}
//DOF General Tab
//DOF Toggles
function ppOptionsDOFEnableDOF::onAction(%this)
{
$PostFXManager::PostFX::EnableDOF = %this.getValue();
ppOptionsUpdateDOFSettings();
}
function ppOptionsDOFEnableAutoFocus::onAction(%this)
{
$DOFPostFx::EnableAutoFocus = %this.getValue();
DOFPostEffect.setAutoFocus( %this.getValue() );
}
//DOF AutoFocus Slider controls
function ppOptionsDOFFarBlurMinSlider::onMouseDragged(%this)
{
$DOFPostFx::BlurMin = %this.value;
ppOptionsUpdateDOFSettings();
}
function ppOptionsDOFFarBlurMaxSlider::onMouseDragged(%this)
{
$DOFPostFx::BlurMax = %this.value;
ppOptionsUpdateDOFSettings();
}
function ppOptionsDOFFocusRangeMinSlider::onMouseDragged(%this)
{
$DOFPostFx::FocusRangeMin = %this.value;
ppOptionsUpdateDOFSettings();
}
function ppOptionsDOFFocusRangeMaxSlider::onMouseDragged(%this)
{
$DOFPostFx::FocusRangeMax = %this.value;
ppOptionsUpdateDOFSettings();
}
function ppOptionsDOFBlurCurveNearSlider::onMouseDragged(%this)
{
$DOFPostFx::BlurCurveNear = %this.value;
ppOptionsUpdateDOFSettings();
}
function ppOptionsDOFBlurCurveFarSlider::onMouseDragged(%this)
{
$DOFPostFx::BlurCurveFar = %this.value;
ppOptionsUpdateDOFSettings();
}
function ppOptionsEnableHDRDebug::onAction(%this)
{
if ( %this.getValue() )
LuminanceVisPostFX.enable();
else
LuminanceVisPostFX.disable();
}
function ppOptionsUpdateVignetteSettings()
{
if($PostFXManager::PostFX::EnableVignette)
{
VignettePostEffect.enable();
}
else
{
VignettePostEffect.disable();
}
}
function ppOptionsVignetteEnableVignette::onAction(%this)
{
$PostFXManager::PostFX::EnableVignette = %this.getValue();
ppOptionsUpdateVignetteSettings();
}
function ppColorCorrection_selectFile()
{
%filter = "Image Files (*.png, *.jpg, *.dds, *.bmp, *.gif, *.jng. *.tga)|*.png;*.jpg;*.dds;*.bmp;*.gif;*.jng;*.tga|All Files (*.*)|*.*|";
getLoadFilename( %filter, "ppColorCorrection_selectFileHandler");
}
function ppColorCorrection_selectFileHandler( %filename )
{
if ( %filename $= "" || !isFile( %filename ) )
%filename = "data/postFX/art/null_color_ramp.png";
else
%filename = makeRelativePath( %filename, getMainDotCsDir() );
$HDRPostFX::colorCorrectionRamp = %filename;
PostFXManager-->ColorCorrectionFileName.Text = %filename;
}

View file

@ -0,0 +1,439 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
$PostFXManager::defaultPreset = "data/postFX/scripts/client/default.postfxpreset.cs";
function PostFXManager::settingsSetEnabled(%this, %bEnablePostFX)
{
$PostFXManager::PostFX::Enabled = %bEnablePostFX;
//if to enable the postFX, apply the ones that are enabled
if ( %bEnablePostFX )
{
//SSAO, HDR, LightRays, DOF
if ( $PostFXManager::PostFX::EnableSSAO )
SSAOPostFx.enable();
else
SSAOPostFx.disable();
if ( $PostFXManager::PostFX::EnableHDR )
HDRPostFX.enable();
else
HDRPostFX.disable();
if ( $PostFXManager::PostFX::EnableLightRays )
LightRayPostFX.enable();
else
LightRayPostFX.disable();
if ( $PostFXManager::PostFX::EnableDOF )
DOFPostEffect.enable();
else
DOFPostEffect.disable();
if ( $PostFXManager::PostFX::EnableVignette )
VignettePostEffect.enable();
else
VignettePostEffect.disable();
postVerbose("% - PostFX Manager - PostFX enabled");
}
else
{
//Disable all postFX
SSAOPostFx.disable();
HDRPostFX.disable();
LightRayPostFX.disable();
DOFPostEffect.disable();
VignettePostEffect.disable();
postVerbose("% - PostFX Manager - PostFX disabled");
}
VolFogGlowPostFx.disable();
}
function PostFXManager::settingsEffectSetEnabled(%this, %sName, %bEnable)
{
%postEffect = 0;
//Determine the postFX to enable, and apply the boolean
if(%sName $= "SSAO")
{
%postEffect = SSAOPostFx;
$PostFXManager::PostFX::EnableSSAO = %bEnable;
//$pref::PostFX::SSAO::Enabled = %bEnable;
}
else if(%sName $= "HDR")
{
%postEffect = HDRPostFX;
$PostFXManager::PostFX::EnableHDR = %bEnable;
//$pref::PostFX::HDR::Enabled = %bEnable;
}
else if(%sName $= "LightRays")
{
%postEffect = LightRayPostFX;
$PostFXManager::PostFX::EnableLightRays = %bEnable;
//$pref::PostFX::LightRays::Enabled = %bEnable;
}
else if(%sName $= "DOF")
{
%postEffect = DOFPostEffect;
$PostFXManager::PostFX::EnableDOF = %bEnable;
//$pref::PostFX::DOF::Enabled = %bEnable;
}
else if(%sName $= "Vignette")
{
%postEffect = VignettePostEffect;
$PostFXManager::PostFX::EnableVignette = %bEnable;
//$pref::PostFX::Vignette::Enabled = %bEnable;
}
// Apply the change
if ( %bEnable == true )
{
%postEffect.enable();
postVerbose("% - PostFX Manager - " @ %sName @ " enabled");
}
else
{
%postEffect.disable();
postVerbose("% - PostFX Manager - " @ %sName @ " disabled");
}
}
function PostFXManager::settingsRefreshSSAO(%this)
{
//Apply the enabled flag
ppOptionsEnableSSAO.setValue($PostFXManager::PostFX::EnableSSAO);
//Add the items we need to display
ppOptionsSSAOQuality.clear();
ppOptionsSSAOQuality.add("Low", 0);
ppOptionsSSAOQuality.add("Medium", 1);
ppOptionsSSAOQuality.add("High", 2);
//Set the selected, after adding the items!
ppOptionsSSAOQuality.setSelected($SSAOPostFx::quality);
//SSAO - Set the values of the sliders, General Tab
ppOptionsSSAOOverallStrength.setValue($SSAOPostFx::overallStrength);
ppOptionsSSAOBlurDepth.setValue($SSAOPostFx::blurDepthTol);
ppOptionsSSAOBlurNormal.setValue($SSAOPostFx::blurNormalTol);
//SSAO - Set the values for the near tab
ppOptionsSSAONearDepthMax.setValue($SSAOPostFx::sDepthMax);
ppOptionsSSAONearDepthMin.setValue($SSAOPostFx::sDepthMin);
ppOptionsSSAONearRadius.setValue($SSAOPostFx::sRadius);
ppOptionsSSAONearStrength.setValue($SSAOPostFx::sStrength);
ppOptionsSSAONearToleranceNormal.setValue($SSAOPostFx::sNormalTol);
ppOptionsSSAONearTolerancePower.setValue($SSAOPostFx::sNormalPow);
//SSAO - Set the values for the far tab
ppOptionsSSAOFarDepthMax.setValue($SSAOPostFx::lDepthMax);
ppOptionsSSAOFarDepthMin.setValue($SSAOPostFx::lDepthMin);
ppOptionsSSAOFarRadius.setValue($SSAOPostFx::lRadius);
ppOptionsSSAOFarStrength.setValue($SSAOPostFx::lStrength);
ppOptionsSSAOFarToleranceNormal.setValue($SSAOPostFx::lNormalTol);
ppOptionsSSAOFarTolerancePower.setValue($SSAOPostFx::lNormalPow);
}
function PostFXManager::settingsRefreshHDR(%this)
{
//Apply the enabled flag
ppOptionsEnableHDR.setValue($PostFXManager::PostFX::EnableHDR);
ppOptionsHDRBloom.setValue($HDRPostFX::enableBloom);
ppOptionsHDRBloomBlurBrightPassThreshold.setValue($HDRPostFX::brightPassThreshold);
ppOptionsHDRBloomBlurMean.setValue($HDRPostFX::gaussMean);
ppOptionsHDRBloomBlurMultiplier.setValue($HDRPostFX::gaussMultiplier);
ppOptionsHDRBloomBlurStdDev.setValue($HDRPostFX::gaussStdDev);
ppOptionsHDRBrightnessAdaptRate.setValue($HDRPostFX::adaptRate);
ppOptionsHDREffectsBlueShift.setValue($HDRPostFX::enableBlueShift);
ppOptionsHDREffectsBlueShiftColor.BaseColor = $HDRPostFX::blueShiftColor;
ppOptionsHDREffectsBlueShiftColor.PickColor = $HDRPostFX::blueShiftColor;
ppOptionsHDRKeyValue.setValue($HDRPostFX::keyValue);
ppOptionsHDRMinLuminance.setValue($HDRPostFX::minLuminace);
ppOptionsHDRToneMapping.setValue($HDRPostFX::enableToneMapping);
ppOptionsHDRToneMappingAmount.setValue($HDRPostFX::enableToneMapping);
ppOptionsHDRWhiteCutoff.setValue($HDRPostFX::whiteCutoff);
%this-->ColorCorrectionFileName.Text = $HDRPostFX::colorCorrectionRamp;
}
function PostFXManager::settingsRefreshLightrays(%this)
{
//Apply the enabled flag
ppOptionsEnableLightRays.setValue($PostFXManager::PostFX::EnableLightRays);
ppOptionsLightRaysBrightScalar.setValue($LightRayPostFX::brightScalar);
ppOptionsLightRaysSampleScalar.setValue($LightRayPostFX::numSamples);
ppOptionsLightRaysDensityScalar.setValue($LightRayPostFX::density);
ppOptionsLightRaysWeightScalar.setValue($LightRayPostFX::weight);
ppOptionsLightRaysDecayScalar.setValue($LightRayPostFX::decay);
}
function PostFXManager::settingsRefreshDOF(%this)
{
//Apply the enabled flag
ppOptionsEnableDOF.setValue($PostFXManager::PostFX::EnableDOF);
//ppOptionsDOFEnableDOF.setValue($PostFXManager::PostFX::EnableDOF);
ppOptionsDOFEnableAutoFocus.setValue($DOFPostFx::EnableAutoFocus);
ppOptionsDOFFarBlurMinSlider.setValue($DOFPostFx::BlurMin);
ppOptionsDOFFarBlurMaxSlider.setValue($DOFPostFx::BlurMax);
ppOptionsDOFFocusRangeMinSlider.setValue($DOFPostFx::FocusRangeMin);
ppOptionsDOFFocusRangeMaxSlider.setValue($DOFPostFx::FocusRangeMax);
ppOptionsDOFBlurCurveNearSlider.setValue($DOFPostFx::BlurCurveNear);
ppOptionsDOFBlurCurveFarSlider.setValue($DOFPostFx::BlurCurveFar);
}
function PostFXManager::settingsRefreshVignette(%this)
{
//Apply the enabled flag
ppOptionsEnableVignette.setValue($PostFXManager::PostFX::EnableVignette);
}
function PostFXManager::settingsRefreshAll(%this)
{
$PostFXManager::PostFX::Enabled = $pref::enablePostEffects;
$PostFXManager::PostFX::EnableSSAO = SSAOPostFx.isEnabled();
$PostFXManager::PostFX::EnableHDR = HDRPostFX.isEnabled();
$PostFXManager::PostFX::EnableLightRays = LightRayPostFX.isEnabled();
$PostFXManager::PostFX::EnableDOF = DOFPostEffect.isEnabled();
$PostFXManager::PostFX::EnableVignette = VignettePostEffect.isEnabled();
//For all the postFX here, apply the active settings in the system
//to the gui controls.
%this.settingsRefreshSSAO();
%this.settingsRefreshHDR();
%this.settingsRefreshLightrays();
%this.settingsRefreshDOF();
%this.settingsRefreshVignette();
ppOptionsEnable.setValue($PostFXManager::PostFX::Enabled);
postVerbose("% - PostFX Manager - GUI values updated.");
}
function PostFXManager::settingsApplyFromPreset(%this)
{
postVerbose("% - PostFX Manager - Applying from preset");
//SSAO Settings
$SSAOPostFx::blurDepthTol = $PostFXManager::Settings::SSAO::blurDepthTol;
$SSAOPostFx::blurNormalTol = $PostFXManager::Settings::SSAO::blurNormalTol;
$SSAOPostFx::lDepthMax = $PostFXManager::Settings::SSAO::lDepthMax;
$SSAOPostFx::lDepthMin = $PostFXManager::Settings::SSAO::lDepthMin;
$SSAOPostFx::lDepthPow = $PostFXManager::Settings::SSAO::lDepthPow;
$SSAOPostFx::lNormalPow = $PostFXManager::Settings::SSAO::lNormalPow;
$SSAOPostFx::lNormalTol = $PostFXManager::Settings::SSAO::lNormalTol;
$SSAOPostFx::lRadius = $PostFXManager::Settings::SSAO::lRadius;
$SSAOPostFx::lStrength = $PostFXManager::Settings::SSAO::lStrength;
$SSAOPostFx::overallStrength = $PostFXManager::Settings::SSAO::overallStrength;
$SSAOPostFx::quality = $PostFXManager::Settings::SSAO::quality;
$SSAOPostFx::sDepthMax = $PostFXManager::Settings::SSAO::sDepthMax;
$SSAOPostFx::sDepthMin = $PostFXManager::Settings::SSAO::sDepthMin;
$SSAOPostFx::sDepthPow = $PostFXManager::Settings::SSAO::sDepthPow;
$SSAOPostFx::sNormalPow = $PostFXManager::Settings::SSAO::sNormalPow;
$SSAOPostFx::sNormalTol = $PostFXManager::Settings::SSAO::sNormalTol;
$SSAOPostFx::sRadius = $PostFXManager::Settings::SSAO::sRadius;
$SSAOPostFx::sStrength = $PostFXManager::Settings::SSAO::sStrength;
//HDR settings
$HDRPostFX::adaptRate = $PostFXManager::Settings::HDR::adaptRate;
$HDRPostFX::blueShiftColor = $PostFXManager::Settings::HDR::blueShiftColor;
$HDRPostFX::brightPassThreshold = $PostFXManager::Settings::HDR::brightPassThreshold;
$HDRPostFX::enableBloom = $PostFXManager::Settings::HDR::enableBloom;
$HDRPostFX::enableBlueShift = $PostFXManager::Settings::HDR::enableBlueShift;
$HDRPostFX::enableToneMapping = $PostFXManager::Settings::HDR::enableToneMapping;
$HDRPostFX::gaussMean = $PostFXManager::Settings::HDR::gaussMean;
$HDRPostFX::gaussMultiplier = $PostFXManager::Settings::HDR::gaussMultiplier;
$HDRPostFX::gaussStdDev = $PostFXManager::Settings::HDR::gaussStdDev;
$HDRPostFX::keyValue = $PostFXManager::Settings::HDR::keyValue;
$HDRPostFX::minLuminace = $PostFXManager::Settings::HDR::minLuminace;
$HDRPostFX::whiteCutoff = $PostFXManager::Settings::HDR::whiteCutoff;
$HDRPostFX::colorCorrectionRamp = $PostFXManager::Settings::ColorCorrectionRamp;
//Light rays settings
$LightRayPostFX::brightScalar = $PostFXManager::Settings::LightRays::brightScalar;
$LightRayPostFX::numSamples = $PostFXManager::Settings::LightRays::numSamples;
$LightRayPostFX::density = $PostFXManager::Settings::LightRays::density;
$LightRayPostFX::weight = $PostFXManager::Settings::LightRays::weight;
$LightRayPostFX::decay = $PostFXManager::Settings::LightRays::decay;
//DOF settings
$DOFPostFx::EnableAutoFocus = $PostFXManager::Settings::DOF::EnableAutoFocus;
$DOFPostFx::BlurMin = $PostFXManager::Settings::DOF::BlurMin;
$DOFPostFx::BlurMax = $PostFXManager::Settings::DOF::BlurMax;
$DOFPostFx::FocusRangeMin = $PostFXManager::Settings::DOF::FocusRangeMin;
$DOFPostFx::FocusRangeMax = $PostFXManager::Settings::DOF::FocusRangeMax;
$DOFPostFx::BlurCurveNear = $PostFXManager::Settings::DOF::BlurCurveNear;
$DOFPostFx::BlurCurveFar = $PostFXManager::Settings::DOF::BlurCurveFar;
//Vignette settings
$VignettePostEffect::VMax = $PostFXManager::Settings::Vignette::VMax;
$VignettePostEffect::VMin = $PostFXManager::Settings::Vignette::VMin;
if ( $PostFXManager::forceEnableFromPresets )
{
$PostFXManager::PostFX::Enabled = $PostFXManager::Settings::EnablePostFX;
$PostFXManager::PostFX::EnableDOF = $pref::PostFX::EnableDOF ? $PostFXManager::Settings::EnableDOF : false;
$PostFXManager::PostFX::EnableVignette = $pref::PostFX::EnableVignette ? $PostFXManager::Settings::EnableVignette : false;
$PostFXManager::PostFX::EnableLightRays = $pref::PostFX::EnableLightRays ? $PostFXManager::Settings::EnableLightRays : false;
$PostFXManager::PostFX::EnableHDR = $pref::PostFX::EnableHDR ? $PostFXManager::Settings::EnableHDR : false;
$PostFXManager::PostFX::EnableSSAO = $pref::PostFX::EnabledSSAO ? $PostFXManager::Settings::EnableSSAO : false;
%this.settingsSetEnabled( true );
}
//make sure we apply the correct settings to the DOF
ppOptionsUpdateDOFSettings();
// Update the actual GUI controls if its awake ( otherwise it will when opened ).
if ( PostFXManager.isAwake() )
%this.settingsRefreshAll();
}
function PostFXManager::settingsApplySSAO(%this)
{
$PostFXManager::Settings::SSAO::blurDepthTol = $SSAOPostFx::blurDepthTol;
$PostFXManager::Settings::SSAO::blurNormalTol = $SSAOPostFx::blurNormalTol;
$PostFXManager::Settings::SSAO::lDepthMax = $SSAOPostFx::lDepthMax;
$PostFXManager::Settings::SSAO::lDepthMin = $SSAOPostFx::lDepthMin;
$PostFXManager::Settings::SSAO::lDepthPow = $SSAOPostFx::lDepthPow;
$PostFXManager::Settings::SSAO::lNormalPow = $SSAOPostFx::lNormalPow;
$PostFXManager::Settings::SSAO::lNormalTol = $SSAOPostFx::lNormalTol;
$PostFXManager::Settings::SSAO::lRadius = $SSAOPostFx::lRadius;
$PostFXManager::Settings::SSAO::lStrength = $SSAOPostFx::lStrength;
$PostFXManager::Settings::SSAO::overallStrength = $SSAOPostFx::overallStrength;
$PostFXManager::Settings::SSAO::quality = $SSAOPostFx::quality;
$PostFXManager::Settings::SSAO::sDepthMax = $SSAOPostFx::sDepthMax;
$PostFXManager::Settings::SSAO::sDepthMin = $SSAOPostFx::sDepthMin;
$PostFXManager::Settings::SSAO::sDepthPow = $SSAOPostFx::sDepthPow;
$PostFXManager::Settings::SSAO::sNormalPow = $SSAOPostFx::sNormalPow;
$PostFXManager::Settings::SSAO::sNormalTol = $SSAOPostFx::sNormalTol;
$PostFXManager::Settings::SSAO::sRadius = $SSAOPostFx::sRadius;
$PostFXManager::Settings::SSAO::sStrength = $SSAOPostFx::sStrength;
postVerbose("% - PostFX Manager - Settings Saved - SSAO");
}
function PostFXManager::settingsApplyHDR(%this)
{
$PostFXManager::Settings::HDR::adaptRate = $HDRPostFX::adaptRate;
$PostFXManager::Settings::HDR::blueShiftColor = $HDRPostFX::blueShiftColor;
$PostFXManager::Settings::HDR::brightPassThreshold = $HDRPostFX::brightPassThreshold;
$PostFXManager::Settings::HDR::enableBloom = $HDRPostFX::enableBloom;
$PostFXManager::Settings::HDR::enableBlueShift = $HDRPostFX::enableBlueShift;
$PostFXManager::Settings::HDR::enableToneMapping = $HDRPostFX::enableToneMapping;
$PostFXManager::Settings::HDR::gaussMean = $HDRPostFX::gaussMean;
$PostFXManager::Settings::HDR::gaussMultiplier = $HDRPostFX::gaussMultiplier;
$PostFXManager::Settings::HDR::gaussStdDev = $HDRPostFX::gaussStdDev;
$PostFXManager::Settings::HDR::keyValue = $HDRPostFX::keyValue;
$PostFXManager::Settings::HDR::minLuminace = $HDRPostFX::minLuminace;
$PostFXManager::Settings::HDR::whiteCutoff = $HDRPostFX::whiteCutoff;
$PostFXManager::Settings::ColorCorrectionRamp = $HDRPostFX::colorCorrectionRamp;
postVerbose("% - PostFX Manager - Settings Saved - HDR");
}
function PostFXManager::settingsApplyLightRays(%this)
{
$PostFXManager::Settings::LightRays::brightScalar = $LightRayPostFX::brightScalar;
$PostFXManager::Settings::LightRays::numSamples = $LightRayPostFX::numSamples;
$PostFXManager::Settings::LightRays::density = $LightRayPostFX::density;
$PostFXManager::Settings::LightRays::weight = $LightRayPostFX::weight;
$PostFXManager::Settings::LightRays::decay = $LightRayPostFX::decay;
postVerbose("% - PostFX Manager - Settings Saved - Light Rays");
}
function PostFXManager::settingsApplyDOF(%this)
{
$PostFXManager::Settings::DOF::EnableAutoFocus = $DOFPostFx::EnableAutoFocus;
$PostFXManager::Settings::DOF::BlurMin = $DOFPostFx::BlurMin;
$PostFXManager::Settings::DOF::BlurMax = $DOFPostFx::BlurMax;
$PostFXManager::Settings::DOF::FocusRangeMin = $DOFPostFx::FocusRangeMin;
$PostFXManager::Settings::DOF::FocusRangeMax = $DOFPostFx::FocusRangeMax;
$PostFXManager::Settings::DOF::BlurCurveNear = $DOFPostFx::BlurCurveNear;
$PostFXManager::Settings::DOF::BlurCurveFar = $DOFPostFx::BlurCurveFar;
postVerbose("% - PostFX Manager - Settings Saved - DOF");
}
function PostFXManager::settingsApplyVignette(%this)
{
$PostFXManager::Settings::Vignette::VMax = $VignettePostEffect::VMax;
$PostFXManager::Settings::Vignette::VMin = $VignettePostEffect::VMin;
postVerbose("% - PostFX Manager - Settings Saved - Vignette");
}
function PostFXManager::settingsApplyAll(%this, %sFrom)
{
// Apply settings which control if effects are on/off altogether.
$PostFXManager::Settings::EnablePostFX = $PostFXManager::PostFX::Enabled;
$PostFXManager::Settings::EnableDOF = $PostFXManager::PostFX::EnableDOF;
$PostFXManager::Settings::EnableVignette = $PostFXManager::PostFX::EnableVignette;
$PostFXManager::Settings::EnableLightRays = $PostFXManager::PostFX::EnableLightRays;
$PostFXManager::Settings::EnableHDR = $PostFXManager::PostFX::EnableHDR;
$PostFXManager::Settings::EnableSSAO = $PostFXManager::PostFX::EnableSSAO;
// Apply settings should save the values in the system to the
// the preset structure ($PostFXManager::Settings::*)
// SSAO Settings
%this.settingsApplySSAO();
// HDR settings
%this.settingsApplyHDR();
// Light rays settings
%this.settingsApplyLightRays();
// DOF
%this.settingsApplyDOF();
// Vignette
%this.settingsApplyVignette();
postVerbose("% - PostFX Manager - All Settings applied to $PostFXManager::Settings");
}
function PostFXManager::settingsApplyDefaultPreset(%this)
{
PostFXManager::loadPresetHandler($PostFXManager::defaultPreset);
}

View file

@ -0,0 +1,79 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Used to name the saved files.
$PostFXManager::fileExtension = ".postfxpreset.cs";
// The filter string for file open/save dialogs.
$PostFXManager::fileFilter = "Post Effect Presets|*.postfxpreset.cs";
// Enable / disable PostFX when loading presets or just apply the settings?
$PostFXManager::forceEnableFromPresets = true;
//Load a preset file from the disk, and apply the settings to the
//controls. If bApplySettings is true - the actual values in the engine
//will be changed to reflect the settings from the file.
function PostFXManager::loadPresetFile()
{
//Show the dialog and set the flag
getLoadFilename($PostFXManager::fileFilter, "PostFXManager::loadPresetHandler");
}
function PostFXManager::loadPresetHandler( %filename )
{
//Check the validity of the file
if ( isScriptFile( %filename ) )
{
%filename = expandFilename(%filename);
postVerbose("% - PostFX Manager - Executing " @ %filename);
exec(%filename);
PostFXManager.settingsApplyFromPreset();
}
}
//Save a preset file to the specified file. The extension used
//is specified by $PostFXManager::fileExtension for on the fly
//name changes to the extension used.
function PostFXManager::savePresetFile(%this)
{
%defaultFile = filePath($Client::MissionFile) @ "/" @ fileBase($Client::MissionFile);
getSaveFilename($PostFXManager::fileFilter, "PostFXManager::savePresetHandler", %defaultFile);
}
//Called from the PostFXManager::savePresetFile() function
function PostFXManager::savePresetHandler( %filename )
{
%filename = makeRelativePath( %filename, getMainDotCsDir() );
if(strStr(%filename, ".") == -1)
%filename = %filename @ $PostFXManager::fileExtension;
//Apply the current settings to the preset
PostFXManager.settingsApplyAll();
export("$PostFXManager::Settings::*", %filename, false);
postVerbose("% - PostFX Manager - Save complete. Preset saved at : " @ %filename);
}

View file

@ -0,0 +1,302 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
///
$SSAOPostFx::overallStrength = 2.0;
// TODO: Add small/large param docs.
// The small radius SSAO settings.
$SSAOPostFx::sRadius = 0.1;
$SSAOPostFx::sStrength = 6.0;
$SSAOPostFx::sDepthMin = 0.1;
$SSAOPostFx::sDepthMax = 1.0;
$SSAOPostFx::sDepthPow = 1.0;
$SSAOPostFx::sNormalTol = 0.0;
$SSAOPostFx::sNormalPow = 1.0;
// The large radius SSAO settings.
$SSAOPostFx::lRadius = 1.0;
$SSAOPostFx::lStrength = 10.0;
$SSAOPostFx::lDepthMin = 0.2;
$SSAOPostFx::lDepthMax = 2.0;
$SSAOPostFx::lDepthPow = 0.2;
$SSAOPostFx::lNormalTol = -0.5;
$SSAOPostFx::lNormalPow = 2.0;
/// Valid values: 0, 1, 2
$SSAOPostFx::quality = 0;
///
$SSAOPostFx::blurDepthTol = 0.001;
///
$SSAOPostFx::blurNormalTol = 0.95;
///
$SSAOPostFx::targetScale = "0.5 0.5";
function SSAOPostFx::onAdd( %this )
{
%this.wasVis = "Uninitialized";
%this.quality = "Uninitialized";
}
function SSAOPostFx::preProcess( %this )
{
if ( $SSAOPostFx::quality !$= %this.quality )
{
%this.quality = mClamp( mRound( $SSAOPostFx::quality ), 0, 2 );
%this.setShaderMacro( "QUALITY", %this.quality );
}
%this.targetScale = $SSAOPostFx::targetScale;
}
function SSAOPostFx::setShaderConsts( %this )
{
%this.setShaderConst( "$overallStrength", $SSAOPostFx::overallStrength );
// Abbreviate is s-small l-large.
%this.setShaderConst( "$sRadius", $SSAOPostFx::sRadius );
%this.setShaderConst( "$sStrength", $SSAOPostFx::sStrength );
%this.setShaderConst( "$sDepthMin", $SSAOPostFx::sDepthMin );
%this.setShaderConst( "$sDepthMax", $SSAOPostFx::sDepthMax );
%this.setShaderConst( "$sDepthPow", $SSAOPostFx::sDepthPow );
%this.setShaderConst( "$sNormalTol", $SSAOPostFx::sNormalTol );
%this.setShaderConst( "$sNormalPow", $SSAOPostFx::sNormalPow );
%this.setShaderConst( "$lRadius", $SSAOPostFx::lRadius );
%this.setShaderConst( "$lStrength", $SSAOPostFx::lStrength );
%this.setShaderConst( "$lDepthMin", $SSAOPostFx::lDepthMin );
%this.setShaderConst( "$lDepthMax", $SSAOPostFx::lDepthMax );
%this.setShaderConst( "$lDepthPow", $SSAOPostFx::lDepthPow );
%this.setShaderConst( "$lNormalTol", $SSAOPostFx::lNormalTol );
%this.setShaderConst( "$lNormalPow", $SSAOPostFx::lNormalPow );
%blur = %this->blurY;
%blur.setShaderConst( "$blurDepthTol", $SSAOPostFx::blurDepthTol );
%blur.setShaderConst( "$blurNormalTol", $SSAOPostFx::blurNormalTol );
%blur = %this->blurX;
%blur.setShaderConst( "$blurDepthTol", $SSAOPostFx::blurDepthTol );
%blur.setShaderConst( "$blurNormalTol", $SSAOPostFx::blurNormalTol );
%blur = %this->blurY2;
%blur.setShaderConst( "$blurDepthTol", $SSAOPostFx::blurDepthTol );
%blur.setShaderConst( "$blurNormalTol", $SSAOPostFx::blurNormalTol );
%blur = %this->blurX2;
%blur.setShaderConst( "$blurDepthTol", $SSAOPostFx::blurDepthTol );
%blur.setShaderConst( "$blurNormalTol", $SSAOPostFx::blurNormalTol );
}
function SSAOPostFx::onEnabled( %this )
{
// This tells the AL shaders to reload and sample
// from our #ssaoMask texture target.
$AL::UseSSAOMask = true;
return true;
}
function SSAOPostFx::onDisabled( %this )
{
$AL::UseSSAOMask = false;
}
//-----------------------------------------------------------------------------
// GFXStateBlockData / ShaderData
//-----------------------------------------------------------------------------
singleton GFXStateBlockData( SSAOStateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampPoint;
samplerStates[1] = SamplerWrapLinear;
samplerStates[2] = SamplerClampPoint;
};
singleton GFXStateBlockData( SSAOBlurStateBlock : PFX_DefaultStateBlock )
{
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
samplerStates[1] = SamplerClampPoint;
};
singleton ShaderData( SSAOShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/ssao/SSAO_P.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/ssao/gl/SSAO_P.glsl";
samplerNames[0] = "$prepassMap";
samplerNames[1] = "$randNormalTex";
samplerNames[2] = "$powTable";
pixVersion = 3.0;
};
singleton ShaderData( SSAOBlurYShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/ssao/SSAO_Blur_V.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/ssao/SSAO_Blur_P.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/ssao/gl/SSAO_Blur_V.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/ssao/gl/SSAO_Blur_P.glsl";
samplerNames[0] = "$occludeMap";
samplerNames[1] = "$prepassMap";
pixVersion = 3.0;
defines = "BLUR_DIR=float2(0.0,1.0)";
};
singleton ShaderData( SSAOBlurXShader : SSAOBlurYShader )
{
defines = "BLUR_DIR=float2(1.0,0.0)";
};
//-----------------------------------------------------------------------------
// PostEffects
//-----------------------------------------------------------------------------
singleton PostEffect( SSAOPostFx )
{
allowReflectPass = false;
renderTime = "PFXBeforeBin";
renderBin = "AL_LightBinMgr";
renderPriority = 10;
shader = SSAOShader;
stateBlock = SSAOStateBlock;
texture[0] = "#prepass";
texture[1] = "data/postFX/art/noise.png";
texture[2] = "#ssao_pow_table";
target = "$outTex";
targetScale = "0.5 0.5";
targetViewport = "PFXTargetViewport_NamedInTexture0";
singleton PostEffect()
{
internalName = "blurY";
shader = SSAOBlurYShader;
stateBlock = SSAOBlurStateBlock;
texture[0] = "$inTex";
texture[1] = "#prepass";
target = "$outTex";
};
singleton PostEffect()
{
internalName = "blurX";
shader = SSAOBlurXShader;
stateBlock = SSAOBlurStateBlock;
texture[0] = "$inTex";
texture[1] = "#prepass";
target = "$outTex";
};
singleton PostEffect()
{
internalName = "blurY2";
shader = SSAOBlurYShader;
stateBlock = SSAOBlurStateBlock;
texture[0] = "$inTex";
texture[1] = "#prepass";
target = "$outTex";
};
singleton PostEffect()
{
internalName = "blurX2";
shader = SSAOBlurXShader;
stateBlock = SSAOBlurStateBlock;
texture[0] = "$inTex";
texture[1] = "#prepass";
// We write to a mask texture which is then
// read by the lighting shaders to mask ambient.
target = "#ssaoMask";
};
};
/// Just here for debug visualization of the
/// SSAO mask texture used during lighting.
singleton PostEffect( SSAOVizPostFx )
{
allowReflectPass = false;
shader = PFX_PassthruShader;
stateBlock = PFX_DefaultStateBlock;
texture[0] = "#ssaoMask";
target = "$backbuffer";
};
singleton ShaderData( SSAOPowTableShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/ssao/SSAO_PowerTable_V.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/ssao/SSAO_PowerTable_P.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/ssao/gl/SSAO_PowerTable_V.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/ssao/gl/SSAO_PowerTable_P.glsl";
pixVersion = 2.0;
};
singleton PostEffect( SSAOPowTablePostFx )
{
shader = SSAOPowTableShader;
stateBlock = PFX_DefaultStateBlock;
renderTime = "PFXTexGenOnDemand";
target = "#ssao_pow_table";
targetFormat = "GFXFormatR16F";
targetSize = "256 1";
};

View file

@ -0,0 +1,57 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
singleton GFXStateBlockData( PFX_TurbulenceStateBlock : PFX_DefaultStateBlock)
{
zDefined = false;
zEnable = false;
zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
};
singleton ShaderData( PFX_TurbulenceShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/turbulenceP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/gl/turbulenceP.glsl";
samplerNames[0] = "$inputTex";
pixVersion = 3.0;
};
singleton PostEffect( TurbulenceFx )
{
isEnabled = false;
allowReflectPass = true;
renderTime = "PFXAfterDiffuse";
renderBin = "GlowBin";
renderPriority = 0.5; // Render after the glows themselves
shader = PFX_TurbulenceShader;
stateBlock=PFX_TurbulenceStateBlock;
texture[0] = "$backBuffer";
};

View file

@ -0,0 +1,55 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
$VignettePostEffect::VMax = 0.6;
$VignettePostEffect::VMin = 0.2;
singleton ShaderData( VignetteShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/postFx/vignette/VignetteP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/postFx/vignette/gl/VignetteP.glsl";
samplerNames[0] = "$backBuffer";
pixVersion = 2.0;
};
singleton PostEffect( VignettePostEffect )
{
isEnabled = false;
allowReflectPass = false;
renderTime = "PFXAfterBin";
renderBin = "GlowBin";
shader = VignetteShader;
stateBlock = PFX_DefaultStateBlock;
texture[0] = "$backBuffer";
renderPriority = 10;
};
function VignettePostEffect::setShaderConsts(%this)
{
%this.setShaderConst("$Vmax", $VignettePostEffect::VMax);
%this.setShaderConst("$Vmin", $VignettePostEffect::VMin);
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,87 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Volumetric Fog final pixel shader V2.00
#include "../shaderModel.hlsl"
#include "../shaderModelAutoGen.hlsl"
#include "../torque.hlsl"
TORQUE_UNIFORM_SAMPLER2D(prepassTex, 0);
TORQUE_UNIFORM_SAMPLER2D(depthBuffer, 1);
TORQUE_UNIFORM_SAMPLER2D(frontBuffer, 2);
TORQUE_UNIFORM_SAMPLER2D(density, 3);
uniform float3 ambientColor;
uniform float accumTime;
uniform float4 fogColor;
uniform float4 modspeed;//xy speed layer 1, zw speed layer 2
uniform float2 viewpoint;
uniform float2 texscale;
uniform float fogDensity;
uniform float preBias;
uniform float textured;
uniform float modstrength;
uniform float numtiles;
uniform float fadesize;
uniform float2 PixelSize;
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 htpos : TEXCOORD0;
float2 uv0 : TEXCOORD1;
};
float4 main( ConnectData IN ) : TORQUE_TARGET0
{
float2 uvscreen=((IN.htpos.xy/IN.htpos.w) + 1.0 ) / 2.0;
uvscreen.y = 1.0 - uvscreen.y;
float obj_test = TORQUE_PREPASS_UNCONDITION(prepassTex, uvscreen).w * preBias;
float depth = TORQUE_TEX2D(depthBuffer, uvscreen).r;
float front = TORQUE_TEX2D(frontBuffer, uvscreen).r;
if (depth <= front)
return float4(0,0,0,0);
else if ( obj_test < depth )
depth = obj_test;
if ( front >= 0.0)
depth -= front;
float diff = 1.0;
float3 col = fogColor.rgb;
if (textured != 0.0)
{
float2 offset = viewpoint + ((-0.5 + (texscale * uvscreen)) * numtiles);
float2 mod1 = TORQUE_TEX2D(density, (offset + (modspeed.xy*accumTime))).rg;
float2 mod2 = TORQUE_TEX2D(density, (offset + (modspeed.zw*accumTime))).rg;
diff = (mod2.r + mod1.r) * modstrength;
col *= (2.0 - ((mod1.g + mod2.g) * fadesize))/2.0;
}
col *= ambientColor;
float4 resultColor = float4(col, 1.0 - saturate(exp(-fogDensity * depth * diff * fadesize)));
return hdrEncode(resultColor);
}

View file

@ -0,0 +1,40 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Volumetric Fog prepass pixel shader V1.00
#include "../shaderModel.hlsl"
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 pos : TEXCOORD0;
};
float4 main( ConnectData IN ) : TORQUE_TARGET0
{
float OUT;
clip( IN.pos.w );
OUT = IN.pos.w;
return float4(OUT,0,0,1);
}

View file

@ -0,0 +1,44 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Volumetric Fog prepass vertex shader V1.00
#include "../shaderModel.hlsl"
#include "../hlslStructs.hlsl"
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 pos : TEXCOORD0;
};
uniform float4x4 modelView;
ConnectData main( VertexIn_P IN)
{
ConnectData OUT;
OUT.hpos = mul(modelView, float4(IN.pos, 1.0));
OUT.pos = OUT.hpos;
return OUT;
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Volumetric Fog Reflection pixel shader V1.00
#include "../shaderModel.hlsl"
uniform float4 fogColor;
uniform float fogDensity;
uniform float reflStrength;
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 pos : TEXCOORD0;
};
float4 main( ConnectData IN ) : TORQUE_TARGET0
{
return float4(fogColor.rgb,saturate(fogDensity*reflStrength));
}

View file

@ -0,0 +1,46 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Volumetric Fog final vertex shader V1.00
#include "../shaderModel.hlsl"
#include "../hlslStructs.hlsl"
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 htpos : TEXCOORD0;
float2 uv0 : TEXCOORD1;
};
uniform float4x4 modelView;
ConnectData main( VertexIn_PNTT IN)
{
ConnectData OUT;
OUT.hpos = mul(modelView, float4(IN.pos,1.0));
OUT.htpos = OUT.hpos;
OUT.uv0 = IN.uv0;
return OUT;
}

View file

@ -0,0 +1,87 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
#include "../../gl/torque.glsl"
uniform sampler2D prepassTex;
uniform sampler2D depthBuffer;
uniform sampler2D frontBuffer;
uniform sampler2D density;
uniform float accumTime;
uniform vec4 fogColor;
uniform float fogDensity;
uniform float preBias;
uniform float textured;
uniform float modstrength;
uniform vec4 modspeed;//xy speed layer 1, zw speed layer 2
uniform vec2 viewpoint;
uniform vec2 texscale;
uniform vec3 ambientColor;
uniform float numtiles;
uniform float fadesize;
uniform vec2 PixelSize;
in vec4 _hpos;
#define IN_hpos _hpos
out vec4 OUT_col;
void main()
{
vec2 uvscreen=((IN_hpos.xy/IN_hpos.w) + 1.0 ) / 2.0;
uvscreen.y = 1.0 - uvscreen.y;
float obj_test = prepassUncondition( prepassTex, uvscreen).w * preBias;
float depth = tex2D(depthBuffer,uvscreen).r;
float front = tex2D(frontBuffer,uvscreen).r;
if (depth <= front)
{
OUT_col = vec4(0,0,0,0);
return;
}
else if ( obj_test < depth )
depth = obj_test;
if ( front >= 0.0)
depth -= front;
float diff = 1.0;
vec3 col = fogColor.rgb;
if (textured != 0.0)
{
vec2 offset = viewpoint + ((-0.5 + (texscale * uvscreen)) * numtiles);
vec2 mod1 = tex2D(density,(offset + (modspeed.xy*accumTime))).rg;
vec2 mod2= tex2D(density,(offset + (modspeed.zw*accumTime))).rg;
diff = (mod2.r + mod1.r) * modstrength;
col *= (2.0 - ((mod1.g + mod2.g) * fadesize))/2.0;
}
col *= ambientColor;
vec4 returnColor = vec4(col, 1.0 - saturate(exp(-fogDensity * depth * diff * fadesize)));
OUT_col = hdrEncode(returnColor);
}

View file

@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/hlslCompat.glsl"
in vec4 _hpos;
#define IN_hpos _hpos
out vec4 OUT_col;
void main()
{
float OUT;
clip( IN_hpos.w );
OUT = IN_hpos.w;
OUT_col = vec4(OUT,0,0,1);
}

View file

@ -0,0 +1,42 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/hlslCompat.glsl"
in vec4 vPosition;
#define IN_position vPosition
out vec4 _hpos;
#define OUT_hpos _hpos
uniform mat4 modelView;
void main()
{
vec4 inPos = IN_position;
inPos.w = 1.0;
OUT_hpos = tMul( modelView, inPos );
gl_Position = OUT_hpos;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,33 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/hlslCompat.glsl"
uniform vec4 fogColor;
uniform float fogDensity;
uniform float reflStrength;
out vec4 OUT_col;
void main()
{
OUT_col = vec4(fogColor.rgb,saturate(fogDensity*reflStrength));
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/hlslCompat.glsl"
in vec4 vPosition;
#define IN_position vPosition
out vec4 _hpos;
#define OUT_hpos _hpos
uniform mat4 modelView;
void main()
{
OUT_hpos = tMul(modelView, IN_position);
gl_Position = OUT_hpos;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// 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 "torque.hlsl"
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float2 texCoord : TEXCOORD0;
};
TORQUE_UNIFORM_SAMPLER2D(diffuseMap, 0);
float4 main( ConnectData IN ) : TORQUE_TARGET0
{
float4 col = TORQUE_TEX2D(diffuseMap, IN.texCoord);
return hdrEncode( col );
}

View file

@ -0,0 +1,58 @@
//-----------------------------------------------------------------------------
// 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 "shaderModel.hlsl"
struct CloudVert
{
float3 pos : POSITION;
float2 uv0 : TEXCOORD0;
};
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float2 texCoord : TEXCOORD0;
};
uniform float4x4 modelview;
uniform float2 texDirection;
uniform float2 texOffset;
uniform float accumTime;
uniform float texScale;
ConnectData main( CloudVert IN )
{
ConnectData OUT;
OUT.hpos = mul(modelview, float4(IN.pos,1.0));
float2 uv = IN.uv0;
uv += texOffset;
uv *= texScale;
uv += accumTime * texDirection;
OUT.texCoord = uv;
return OUT;
}

View file

@ -0,0 +1,146 @@
//-----------------------------------------------------------------------------
// 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 "shaderModel.hlsl"
#include "torque.hlsl"
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 texCoord12 : TEXCOORD0;
float4 texCoord34 : TEXCOORD1;
float3 vLightTS : TEXCOORD2; // light vector in tangent space, denormalized
float3 vViewTS : TEXCOORD3; // view vector in tangent space, denormalized
float worldDist : TEXCOORD4;
};
//-----------------------------------------------------------------------------
// Uniforms
//-----------------------------------------------------------------------------
TORQUE_UNIFORM_SAMPLER2D(normalHeightMap, 0);
uniform float3 ambientColor;
uniform float3 sunColor;
uniform float cloudCoverage;
uniform float3 cloudBaseColor;
uniform float cloudExposure;
//-----------------------------------------------------------------------------
// Globals
//-----------------------------------------------------------------------------
// The per-color weighting to be used for luminance calculations in RGB order.
static const float3 LUMINANCE_VECTOR = float3(0.2125f, 0.7154f, 0.0721f);
//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------
// Calculates the Rayleigh phase function
float getRayleighPhase( float angle )
{
return 0.75 * ( 1.0 + pow( angle, 2 ) );
}
// Returns the output rgb color given a texCoord and parameters it uses
// for lighting calculation.
float3 ComputeIllumination( float2 texCoord,
float3 vLightTS,
float3 vViewTS,
float3 vNormalTS )
{
//return noiseNormal;
//return vNormalTS;
float3 vLightTSAdj = float3( -vLightTS.x, -vLightTS.y, vLightTS.z );
float dp = dot( vNormalTS, vLightTSAdj );
// Calculate the amount of illumination (lightTerm)...
// We do both a rim lighting effect and a halfLambertian lighting effect
// and combine the result.
float halfLambertTerm = saturate( pow( dp * 0.5 + 0.5, 1 ) );
float rimLightTerm = pow( ( 1.0 - dp ), 1.0 );
float lightTerm = saturate( halfLambertTerm * 1.0 + rimLightTerm * dp );
lightTerm *= 0.5;
// Use a simple RayleighPhase function to simulate single scattering towards
// the camera.
float angle = dot( vLightTS, vViewTS );
lightTerm *= getRayleighPhase( angle );
// Combine terms and colors into the output color.
//float3 lightColor = ( lightTerm * sunColor * fOcclusionShadow ) + ambientColor;
float3 lightColor = lerp( ambientColor, sunColor, lightTerm );
//lightColor = lerp( lightColor, ambientColor, cloudCoverage );
float3 finalColor = cloudBaseColor * lightColor;
return finalColor;
}
float4 main( ConnectData IN ) : TORQUE_TARGET0
{
// Normalize the interpolated vectors:
float3 vViewTS = normalize( IN.vViewTS );
float3 vLightTS = normalize( IN.vLightTS );
float4 cResultColor = float4( 0, 0, 0, 1 );
float2 texSample = IN.texCoord12.xy;
float4 noise1 = TORQUE_TEX2D( normalHeightMap, IN.texCoord12.zw );
noise1 = normalize( ( noise1 - 0.5 ) * 2.0 );
//return noise1;
float4 noise2 = TORQUE_TEX2D(normalHeightMap, IN.texCoord34.xy);
noise2 = normalize( ( noise2 - 0.5 ) * 2.0 );
//return noise2;
float3 noiseNormal = normalize( noise1 + noise2 ).xyz;
//return float4( noiseNormal, 1.0 );
float noiseHeight = noise1.a * noise2.a * ( cloudCoverage / 2.0 + 0.5 );
float3 vNormalTS = normalize( TORQUE_TEX2D(normalHeightMap, texSample).xyz * 2.0 - 1.0);
vNormalTS += noiseNormal;
vNormalTS = normalize( vNormalTS );
// Compute resulting color for the pixel:
cResultColor.rgb = ComputeIllumination( texSample, vLightTS, vViewTS, vNormalTS );
float coverage = ( cloudCoverage - 0.5 ) * 2.0;
cResultColor.a = TORQUE_TEX2D(normalHeightMap, texSample).a + coverage + noiseHeight;
if ( cloudCoverage > -1.0 )
cResultColor.a /= 1.0 + coverage;
cResultColor.a = saturate( cResultColor.a * pow( saturate(cloudCoverage), 0.25 ) );
cResultColor.a = lerp( cResultColor.a, 0.0, 1.0 - pow(IN.worldDist,2.0) );
cResultColor.rgb *= cloudExposure;
return hdrEncode( cResultColor );
}

View file

@ -0,0 +1,106 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
#include "shaderModel.hlsl"
struct CloudVert
{
float3 pos : POSITION;
float3 normal : NORMAL;
float3 binormal : BINORMAL;
float3 tangent : TANGENT;
float2 uv0 : TEXCOORD0;
};
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 texCoord12 : TEXCOORD0;
float4 texCoord34 : TEXCOORD1;
float3 vLightTS : TEXCOORD2; // light vector in tangent space, denormalized
float3 vViewTS : TEXCOORD3; // view vector in tangent space, denormalized
float worldDist : TEXCOORD4;
};
//-----------------------------------------------------------------------------
// Uniforms
//-----------------------------------------------------------------------------
uniform float4x4 modelview;
uniform float3 eyePosWorld;
uniform float3 sunVec;
uniform float2 texOffset0;
uniform float2 texOffset1;
uniform float2 texOffset2;
uniform float3 texScale;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
ConnectData main( CloudVert IN )
{
ConnectData OUT;
OUT.hpos = mul(modelview, float4(IN.pos,1.0));
// Offset the uv so we don't have a seam directly over our head.
float2 uv = IN.uv0 + float2( 0.5, 0.5 );
OUT.texCoord12.xy = uv * texScale.x;
OUT.texCoord12.xy += texOffset0;
OUT.texCoord12.zw = uv * texScale.y;
OUT.texCoord12.zw += texOffset1;
OUT.texCoord34.xy = uv * texScale.z;
OUT.texCoord34.xy += texOffset2;
OUT.texCoord34.z = IN.pos.z;
OUT.texCoord34.w = 0.0;
// Transform the normal, tangent and binormal vectors from object space to
// homogeneous projection space:
float3 vNormalWS = -IN.normal;
float3 vTangentWS = -IN.tangent;
float3 vBinormalWS = -IN.binormal;
// Compute position in world space:
float4 vPositionWS = float4(IN.pos, 1.0) + float4(eyePosWorld, 1); //mul( IN.pos, objTrans );
// Compute and output the world view vector (unnormalized):
float3 vViewWS = eyePosWorld - vPositionWS.xyz;
// Compute denormalized light vector in world space:
float3 vLightWS = -sunVec;
// Normalize the light and view vectors and transform it to the tangent space:
float3x3 mWorldToTangent = float3x3( vTangentWS, vBinormalWS, vNormalWS );
// Propagate the view and the light vectors (in tangent space):
OUT.vLightTS = mul( vLightWS, mWorldToTangent );
OUT.vViewTS = mul( mWorldToTangent, vViewWS );
OUT.worldDist = saturate( pow( max( IN.pos.z, 0 ), 2 ) );
return OUT;
}

View file

@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// 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 "../shaderModel.hlsl"
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
TORQUE_UNIFORM_SAMPLER2D(diffuseMap, 0);
float4 main( Conn IN ) : TORQUE_TARGET0
{
return float4(IN.color.rgb, IN.color.a * TORQUE_TEX2D(diffuseMap, IN.texCoord).a);
}

View file

@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
// 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 "../shaderModel.hlsl"
struct Appdata
{
float3 position : POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
uniform float4x4 modelview;
Conn main( Appdata In )
{
Conn Out;
Out.HPOS = mul(modelview, float4(In.position,1.0));
Out.color = In.color;
Out.texCoord = In.texCoord;
return Out;
}

View file

@ -0,0 +1,34 @@
//-----------------------------------------------------------------------------
// 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 "../shaderModel.hlsl"
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
};
float4 main(Conn IN) : TORQUE_TARGET0
{
return IN.color;
}

View file

@ -0,0 +1,45 @@
//-----------------------------------------------------------------------------
// 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 "../shaderModel.hlsl"
struct Appdata
{
float3 position : POSITION;
float4 color : COLOR;
};
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
};
uniform float4x4 modelview;
Conn main( Appdata In )
{
Conn Out;
Out.HPOS = mul(modelview, float4(In.position,1.0));
Out.color = In.color;
return Out;
}

View file

@ -0,0 +1,32 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;
out vec4 OUT_col;
void main()
{
OUT_col = vec4(color.rgb, color.a * texture(diffuseMap, texCoord).a);
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec4 color;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
texCoord = vTexCoord0.st;
}

View file

@ -0,0 +1,30 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
in vec4 color;
out vec4 OUT_col;
void main()
{
OUT_col = color;
}

View file

@ -0,0 +1,35 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec4 vColor;
uniform mat4 modelview;
out vec4 color;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
}

View file

@ -0,0 +1,32 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;
out vec4 OUT_col;
void main()
{
OUT_col = texture(diffuseMap, texCoord) * color;
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec4 color;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
texCoord = vTexCoord0.st;
}

View file

@ -0,0 +1,31 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
uniform sampler2D colorTarget0Texture ;
vec4 main( vec2 ScreenPos : VPOS ) : COLOR0
{
vec2 TexCoord = ScreenPos;
vec4 diffuse;
asm { tfetch2D diffuse, TexCoord, colorTarget0Texture, UnnormalizedTextureCoords = true };
return diffuse;
}

View file

@ -0,0 +1,22 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------

View file

@ -0,0 +1,31 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
in vec2 texCoord;
out vec4 OUT_col;
void main()
{
OUT_col = texture(diffuseMap, texCoord);
}

View file

@ -0,0 +1,35 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
texCoord = vTexCoord0.st;
}

View file

@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// 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 "../shaderModel.hlsl"
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
TORQUE_UNIFORM_SAMPLER2D(diffuseMap, 0);
float4 main( Conn IN ) : TORQUE_TARGET0
{
return TORQUE_TEX2D(diffuseMap, IN.texCoord) * IN.color;
}

View file

@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
// 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 "../shaderModel.hlsl"
struct Appdata
{
float3 position : POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
uniform float4x4 modelview;
Conn main( Appdata In )
{
Conn Out;
Out.HPOS = mul(modelview, float4(In.position,1.0));
Out.color = In.color;
Out.texCoord = In.texCoord;
return Out;
}

View file

@ -0,0 +1,31 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
uniform sampler2D colorTarget0Texture : register(s0);
float4 main( float2 ScreenPos : VPOS ) : COLOR0
{
float2 TexCoord = ScreenPos;
float4 diffuse;
asm { tfetch2D diffuse, TexCoord, colorTarget0Texture, UnnormalizedTextureCoords = true };
return diffuse;
}

View file

@ -0,0 +1,26 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
float4 main( const float2 inPosition : POSITION ) : POSITION
{
return float4( inPosition, 0, 1 );
}

View file

@ -0,0 +1,36 @@
//-----------------------------------------------------------------------------
// 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 "../shaderModel.hlsl"
TORQUE_UNIFORM_SAMPLER2D(diffuseMap, 0);
struct Conn
{
float4 hpos : TORQUE_POSITION;
float2 texCoord : TEXCOORD0;
};
float4 main(Conn IN) : TORQUE_TARGET0
{
return TORQUE_TEX2D(diffuseMap, IN.texCoord);
}

View file

@ -0,0 +1,46 @@
//-----------------------------------------------------------------------------
// 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 "../shaderModel.hlsl"
struct Appdata
{
float3 position : POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
struct Conn
{
float4 hpos : TORQUE_POSITION;
float2 texCoord : TEXCOORD0;
};
uniform float4x4 modelview;
Conn main( Appdata In )
{
Conn Out;
Out.hpos = mul(modelview, float4(In.position, 1.0));
Out.texCoord = In.texCoord;
return Out;
}

View file

@ -0,0 +1,186 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// CornerId corresponds to this arrangement
// from the perspective of the camera.
//
// 3 ---- 2
// | |
// 0 ---- 1
//
#define MAX_COVERTYPES 8
uniform float2 gc_fadeParams;
uniform float2 gc_windDir;
uniform float3 gc_camRight;
uniform float3 gc_camUp;
uniform float4 gc_typeRects[MAX_COVERTYPES];
// .x = gust length
// .y = premultiplied simulation time and gust frequency
// .z = gust strength
uniform float3 gc_gustInfo;
// .x = premultiplied simulation time and turbulance frequency
// .y = turbulance strength
uniform float2 gc_turbInfo;
static float sCornerRight[4] = { -0.5, 0.5, 0.5, -0.5 };
static float sCornerUp[4] = { 0, 0, 1, 1 };
static float sMovableCorner[4] = { 0, 0, 1, 1 };
static float2 sUVCornerExtent[4] =
{
float2( 0, 1 ),
float2( 1, 1 ),
float2( 1, 0 ),
float2( 0, 0 )
};
///////////////////////////////////////////////////////////////////////////////
// The following wind effect was derived from the GPU Gems 3 chapter...
//
// "Vegetation Procedural Animation and Shading in Crysis"
// by Tiago Sousa, Crytek
//
float2 smoothCurve( float2 x )
{
return x * x * ( 3.0 - 2.0 * x );
}
float2 triangleWave( float2 x )
{
return abs( frac( x + 0.5 ) * 2.0 - 1.0 );
}
float2 smoothTriangleWave( float2 x )
{
return smoothCurve( triangleWave( x ) );
}
float windTurbulence( float bbPhase, float frequency, float strength )
{
// We create the input value for wave generation from the frequency and phase.
float2 waveIn = bbPhase.xx + frequency.xx;
// We use two square waves to generate the effect which
// is then scaled by the overall strength.
float2 waves = ( frac( waveIn.xy * float2( 1.975, 0.793 ) ) * 2.0 - 1.0 );
waves = smoothTriangleWave( waves );
// Sum up the two waves into a single wave.
return ( waves.x + waves.y ) * strength;
}
float2 windEffect( float bbPhase,
float2 windDirection,
float gustLength,
float gustFrequency,
float gustStrength,
float turbFrequency,
float turbStrength )
{
// Calculate the ambient wind turbulence.
float turbulence = windTurbulence( bbPhase, turbFrequency, turbStrength );
// We simulate the overall gust via a sine wave.
float gustPhase = clamp( sin( ( bbPhase - gustFrequency ) / gustLength ) , 0, 1 );
float gustOffset = ( gustPhase * gustStrength ) + ( ( 0.2 + gustPhase ) * turbulence );
// Return the final directional wind effect.
return gustOffset.xx * windDirection.xy;
}
void foliageProcessVert( inout float3 position,
inout float4 diffuse,
inout float4 texCoord,
inout float3 normal,
inout float3 T,
in float3 eyePos )
{
// Assign the normal and tagent values.
//normal = float3( 0, 0, 1 );//cross( gc_camUp, gc_camRight );
T = gc_camRight;
// Pull out local vars we need for work.
int corner = ( diffuse.a * 255.0f ) + 0.5f;
float2 size = texCoord.xy;
int type = texCoord.z;
// The billboarding is based on the camera direction.
float3 rightVec = gc_camRight * sCornerRight[corner];
float3 upVec = gc_camUp * sCornerUp[corner];
// Figure out the corner position.
float3 outPos = ( upVec * size.y ) + ( rightVec * size.x );
float len = length( outPos.xyz );
// We derive the billboard phase used for wind calculations from its position.
float bbPhase = dot( position.xyz, 1 );
// Get the overall wind gust and turbulence effects.
float3 wind;
wind.xy = windEffect( bbPhase,
gc_windDir,
gc_gustInfo.x, gc_gustInfo.y, gc_gustInfo.z,
gc_turbInfo.x, gc_turbInfo.y );
wind.z = 0;
// Add the summed wind effect into the point.
outPos.xyz += wind.xyz * texCoord.w;
// Do a simple spherical clamp to keep the foliage
// from stretching too much by wind effect.
outPos.xyz = normalize( outPos.xyz ) * len;
// Move the point into world space.
position += outPos;
// Grab the uv set and setup the texture coord.
float4 uvSet = gc_typeRects[type];
texCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
texCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
// Animate the normal to get lighting changes
// across the the wind swept foliage.
//
// TODO: Expose the 10x as a factor to control
// how much the wind effects the lighting on the grass.
//
normal.xy += wind.xy * ( 10.0 * texCoord.w );
normal = normalize( normal );
// Get the alpha fade value.
float fadeStart = gc_fadeParams.x;
float fadeEnd = gc_fadeParams.y;
const float fadeRange = fadeEnd - fadeStart;
float dist = distance( eyePos, position.xyz ) - fadeStart;
diffuse.a = 1 - clamp( dist / fadeRange, 0, 1 );
}

View file

@ -0,0 +1,60 @@
//-----------------------------------------------------------------------------
// 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 "shdrConsts.h"
#include "shaderModel.hlsl"
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float2 outTexCoord : TEXCOORD0;
float4 color : COLOR0;
float4 groundAlphaCoeff : COLOR1;
float2 alphaLookup : TEXCOORD1;
};
struct Fragout
{
float4 col : TORQUE_TARGET0;
};
TORQUE_UNIFORM_SAMPLER2D(diffuseMap, 0);
TORQUE_UNIFORM_SAMPLER2D(alphaMap, 1);
uniform float4 groundAlpha;
uniform float4 ambient;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Fragout main( ConnectData IN )
{
Fragout OUT;
float4 alpha = TORQUE_TEX2D(alphaMap, IN.alphaLookup);
OUT.col = float4( ambient.rgb * IN.lum.rgb, 1.0 ) * TORQUE_TEX2D(diffuseMap, IN.texCoord);
OUT.col.a = OUT.col.a * min(alpha, groundAlpha + IN.groundAlphaCoeff.x).x;
return OUT;
}

View file

@ -0,0 +1,129 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
#include "shaderModel.hlsl"
struct VertData
{
float3 position : POSITION;
float3 normal : NORMAL;
float2 texCoord : TEXCOORD0;
float2 waveScale : TEXCOORD1;
};
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float2 outTexCoord : TEXCOORD0;
float4 color : COLOR0;
float4 groundAlphaCoeff : COLOR1;
float2 alphaLookup : TEXCOORD1;
};
uniform float4x4 projection : register(C0);
uniform float4x4 world : register(C4);
uniform float GlobalSwayPhase : register(C8);
uniform float SwayMagnitudeSide : register(C9);
uniform float SwayMagnitudeFront : register(C10);
uniform float GlobalLightPhase : register(C11);
uniform float LuminanceMagnitude : register(C12);
uniform float LuminanceMidpoint : register(C13);
uniform float DistanceRange : register(C14);
uniform float3 CameraPos : register(C15);
uniform float TrueBillboard : register(C16);
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
ConnectData main( VertData IN )
{
ConnectData OUT;
// Init a transform matrix to be used in the following steps
float4x4 trans = 0;
trans[0][0] = 1;
trans[1][1] = 1;
trans[2][2] = 1;
trans[3][3] = 1;
trans[0][3] = IN.position.x;
trans[1][3] = IN.position.y;
trans[2][3] = IN.position.z;
// Billboard transform * world matrix
float4x4 o = world;
o = mul(o, trans);
// Keep only the up axis result and position transform.
// This gives us "cheating" cylindrical billboarding.
o[0][0] = 1;
o[1][0] = 0;
o[2][0] = 0;
o[3][0] = 0;
o[0][1] = 0;
o[1][1] = 1;
o[2][1] = 0;
o[3][1] = 0;
// Unless the user specified TrueBillboard,
// in which case we want the z axis to also be camera facing.
#ifdef TRUE_BILLBOARD
o[0][2] = 0;
o[1][2] = 0;
o[2][2] = 1;
o[3][2] = 0;
#endif
// Handle sway. Sway is stored in a texture coord. The x coordinate is the sway phase multiplier,
// the y coordinate determines if this vertex actually sways or not.
float xSway, ySway;
float wavePhase = GlobalSwayPhase * IN.waveScale.x;
sincos(wavePhase, ySway, xSway);
xSway = xSway * IN.waveScale.y * SwayMagnitudeSide;
ySway = ySway * IN.waveScale.y * SwayMagnitudeFront;
float4 p;
p = mul(o, float4(IN.normal.x + xSway, ySway, IN.normal.z, 1));
// Project the point
OUT.hpos = mul(projection, p);
// Lighting
float Luminance = LuminanceMidpoint + LuminanceMagnitude * cos(GlobalLightPhase + IN.normal.y);
// Alpha
float3 worldPos = IN.position;
float alpha = abs(distance(worldPos, CameraPos)) / DistanceRange;
alpha = clamp(alpha, 0.0f, 1.0f); //pass it through
OUT.alphaLookup = float2(alpha, 0.0f);
OUT.groundAlphaCoeff = all(IN.normal.z);
OUT.outTexCoord = IN.texCoord;
OUT.color = float4(Luminance, Luminance, Luminance, 1.0f);
return OUT;
}

View file

@ -0,0 +1,39 @@
//-----------------------------------------------------------------------------
// 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 "torque.glsl"
#include "hlslCompat.glsl"
//ConnectData
in vec2 texCoord;
#define IN_texCoord texCoord
uniform sampler2D diffuseMap ;
out vec4 OUT_col;
void main()
{
vec4 col = texture( diffuseMap, IN_texCoord );
OUT_col = hdrEncode( col );
}

View file

@ -0,0 +1,53 @@
//-----------------------------------------------------------------------------
// 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 "hlslCompat.glsl"
//CloudVert
in vec4 vPosition;
in vec2 vTexCoord0;
#define IN_pos vPosition
#define IN_uv0 vTexCoord0
uniform mat4 modelview;
uniform float accumTime;
uniform float texScale;
uniform vec2 texDirection;
uniform vec2 texOffset;
out vec2 texCoord;
#define OUT_texCoord texCoord
void main()
{
gl_Position = tMul(modelview, IN_pos);
vec2 uv = IN_uv0;
uv += texOffset;
uv *= texScale;
uv += accumTime * texDirection;
OUT_texCoord = uv;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,39 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//*****************************************************************************
// Glow Shader
//*****************************************************************************
uniform vec4 kernel;
uniform sampler2D diffuseMap;
in vec2 texc0, texc1, texc2, texc3;
out vec4 OUT_col;
void main()
{
OUT_col = texture(diffuseMap, texc0) * kernel.x;
OUT_col += texture(diffuseMap, texc1) * kernel.y;
OUT_col += texture(diffuseMap, texc2) * kernel.z;
OUT_col += texture(diffuseMap, texc3) * kernel.w;
}

View file

@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//*****************************************************************************
// Glow shader
//*****************************************************************************
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
uniform vec2 offset0, offset1, offset2, offset3;
out vec2 texc0, texc1, texc2, texc3;
void main()
{
gl_Position = modelview * vPosition;
vec2 tc = vTexCoord0.st;
tc.y = 1.0 - tc.y;
texc0 = tc + offset0;
texc1 = tc + offset1;
texc2 = tc + offset2;
texc3 = tc + offset3;
gl_Position.y *= -1;
}

View file

@ -0,0 +1,147 @@
//-----------------------------------------------------------------------------
// 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 "hlslCompat.glsl"
#include "torque.glsl"
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
//ConnectData
in vec4 texCoord12;
#define IN_texCoord12 texCoord12
in vec4 texCoord34;
#define IN_texCoord34 texCoord34
in vec3 vLightTS; // light vector in tangent space, denormalized
#define IN_vLightTS vLightTS
in vec3 vViewTS; // view vector in tangent space, denormalized
#define IN_vViewTS vViewTS
in float worldDist;
#define IN_worldDist worldDist
//-----------------------------------------------------------------------------
// Uniforms
//-----------------------------------------------------------------------------
uniform sampler2D normalHeightMap;
uniform vec3 ambientColor;
uniform vec3 sunColor;
uniform float cloudCoverage;
uniform vec3 cloudBaseColor;
uniform float cloudExposure;
out vec4 OUT_col;
//-----------------------------------------------------------------------------
// Globals
//-----------------------------------------------------------------------------
// The per-color weighting to be used for luminance calculations in RGB order.
const vec3 LUMINANCE_VECTOR = vec3(0.2125f, 0.7154f, 0.0721f);
//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------
// Calculates the Rayleigh phase function
float getRayleighPhase( float angle )
{
return 0.75 * ( 1.0 + pow( angle, 2.0 ) );
}
// Returns the output rgb color given a texCoord and parameters it uses
// for lighting calculation.
vec3 ComputeIllumination( vec2 texCoord,
vec3 vLightTS,
vec3 vViewTS,
vec3 vNormalTS )
{
//return noiseNormal;
//return vNormalTS;
vec3 vLightTSAdj = vec3( -vLightTS.x, -vLightTS.y, vLightTS.z );
float dp = dot( vNormalTS, vLightTSAdj );
// Calculate the amount of illumination (lightTerm)...
// We do both a rim lighting effect and a halfLambertian lighting effect
// and combine the result.
float halfLambertTerm = clamp( pow( dp * 0.5 + 0.5, 1.0 ), 0.0, 1.0 );
float rimLightTerm = pow( ( 1.0 - dp ), 1.0 );
float lightTerm = clamp( halfLambertTerm * 1.0 + rimLightTerm * dp, 0.0, 1.0 );
lightTerm *= 0.5;
// Use a simple RayleighPhase function to simulate single scattering towards
// the camera.
float angle = dot( vLightTS, vViewTS );
lightTerm *= getRayleighPhase( angle );
// Combine terms and colors into the output color.
//vec3 lightColor = ( lightTerm * sunColor * fOcclusionShadow ) + ambientColor;
vec3 lightColor = mix( ambientColor, sunColor, lightTerm );
//lightColor = mix( lightColor, ambientColor, cloudCoverage );
vec3 finalColor = cloudBaseColor * lightColor;
return finalColor;
}
void main()
{
// Normalize the interpolated vectors:
vec3 vViewTS = normalize( vViewTS );
vec3 vLightTS = normalize( vLightTS );
vec4 cResultColor = vec4( 0, 0, 0, 1 );
vec2 texSample = IN_texCoord12.xy;
vec4 noise1 = texture( normalHeightMap, IN_texCoord12.zw );
noise1 = normalize( ( noise1 - 0.5 ) * 2.0 );
//return noise1;
vec4 noise2 = texture( normalHeightMap, IN_texCoord34.xy );
noise2 = normalize( ( noise2 - 0.5 ) * 2.0 );
//return noise2;
vec3 noiseNormal = normalize( noise1 + noise2 ).xyz;
//return vec4( noiseNormal, 1.0 );
float noiseHeight = noise1.a * noise2.a * ( cloudCoverage / 2.0 + 0.5 );
vec3 vNormalTS = normalize( texture( normalHeightMap, texSample ).xyz * 2.0 - 1.0 );
vNormalTS += noiseNormal;
vNormalTS = normalize( vNormalTS );
// Compute resulting color for the pixel:
cResultColor.rgb = ComputeIllumination( texSample, vLightTS, vViewTS, vNormalTS );
float coverage = ( cloudCoverage - 0.5 ) * 2.0;
cResultColor.a = texture( normalHeightMap, texSample ).a + coverage + noiseHeight;
if ( cloudCoverage > -1.0 )
cResultColor.a /= 1.0 + coverage;
cResultColor.a = clamp( cResultColor.a * pow( saturate(cloudCoverage), 0.25 ), 0.0, 1.0 );
cResultColor.a = mix( cResultColor.a, 0.0, 1.0 - pow(IN_worldDist,2.0) );
OUT_col = hdrEncode(cResultColor);
}

View file

@ -0,0 +1,106 @@
//-----------------------------------------------------------------------------
// 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 "hlslCompat.glsl"
in vec4 vPosition;
in vec3 vNormal;
in vec3 vBinormal;
in vec3 vTangent;
in vec2 vTexCoord0;
out vec4 texCoord12;
#define OUT_texCoord12 texCoord12
out vec4 texCoord34;
#define OUT_texCoord34 texCoord34
out vec3 vLightTS; // light vector in tangent space, denormalized
#define OUT_vLightTS vLightTS
out vec3 vViewTS; // view vector in tangent space, denormalized
#define OUT_vViewTS vViewTS
out float worldDist;
#define OUT_worldDist worldDist
//-----------------------------------------------------------------------------
// Uniforms
//-----------------------------------------------------------------------------
uniform mat4 modelview;
uniform vec3 eyePosWorld;
uniform vec3 sunVec;
uniform vec2 texOffset0;
uniform vec2 texOffset1;
uniform vec2 texOffset2;
uniform vec3 texScale;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
vec4 IN_pos = vPosition;
vec3 IN_normal = vNormal;
vec3 IN_binormal = vBinormal;
vec3 IN_tangent = vTangent;
vec2 IN_uv0 = vTexCoord0.st;
gl_Position = modelview * IN_pos;
// Offset the uv so we don't have a seam directly over our head.
vec2 uv = IN_uv0 + vec2( 0.5, 0.5 );
OUT_texCoord12.xy = uv * texScale.x;
OUT_texCoord12.xy += texOffset0;
OUT_texCoord12.zw = uv * texScale.y;
OUT_texCoord12.zw += texOffset1;
OUT_texCoord34.xy = uv * texScale.z;
OUT_texCoord34.xy += texOffset2;
OUT_texCoord34.z = IN_pos.z;
OUT_texCoord34.w = 0.0;
// Transform the normal, tangent and binormal vectors from object space to
// homogeneous projection space:
vec3 vNormalWS = -IN_normal;
vec3 vTangentWS = -IN_tangent;
vec3 vBinormalWS = -IN_binormal;
// Compute position in world space:
vec4 vPositionWS = IN_pos + vec4( eyePosWorld, 1 ); //tMul( IN_pos, objTrans );
// Compute and output the world view vector (unnormalized):
vec3 vViewWS = eyePosWorld - vPositionWS.xyz;
// Compute denormalized light vector in world space:
vec3 vLightWS = -sunVec;
// Normalize the light and view vectors and transform it to the IN_tangent space:
mat3 mWorldToTangent = mat3( vTangentWS, vBinormalWS, vNormalWS );
// Propagate the view and the light vectors (in tangent space):
OUT_vLightTS = vLightWS * mWorldToTangent;
OUT_vViewTS = mWorldToTangent * vViewWS;
OUT_worldDist = clamp( pow( max( IN_pos.z, 0 ), 2 ), 0.0, 1.0 );
correctSSP(gl_Position);
}

View file

@ -0,0 +1,186 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// CornerId corresponds to this arrangement
// from the perspective of the camera.
//
// 3 ---- 2
// | |
// 0 ---- 1
//
#define MAX_COVERTYPES 8
uniform vec3 gc_camRight;
uniform vec3 gc_camUp;
uniform vec4 gc_typeRects[MAX_COVERTYPES];
uniform vec2 gc_fadeParams;
uniform vec2 gc_windDir;
// .x = gust length
// .y = premultiplied simulation time and gust frequency
// .z = gust strength
uniform vec3 gc_gustInfo;
// .x = premultiplied simulation time and turbulance frequency
// .y = turbulance strength
uniform vec2 gc_turbInfo;
const float sCornerRight[4] = float[]( -0.5, 0.5, 0.5, -0.5 );
const float sCornerUp[4] = float[]( 0, 0, 1, 1 );
const float sMovableCorner[4] = float[]( 0, 0, 1, 1 );
const vec2 sUVCornerExtent[4] = vec2[]
(
vec2( 0, 1 ),
vec2( 1, 1 ),
vec2( 1, 0 ),
vec2( 0, 0 )
);
///////////////////////////////////////////////////////////////////////////////
// The following wind effect was derived from the GPU Gems 3 chapter...
//
// "Vegetation Procedural Animation and Shading in Crysis"
// by Tiago Sousa, Crytek
//
vec2 smoothCurve( vec2 x )
{
return x * x * ( 3.0 - 2.0 * x );
}
vec2 triangleWave( vec2 x )
{
return abs( fract( x + 0.5 ) * 2.0 - 1.0 );
}
vec2 smoothTriangleWave( vec2 x )
{
return smoothCurve( triangleWave( x ) );
}
float windTurbulence( float bbPhase, float frequency, float strength )
{
// We create the input value for wave generation from the frequency and phase.
vec2 waveIn = vec2( bbPhase + frequency );
// We use two square waves to generate the effect which
// is then scaled by the overall strength.
vec2 waves = ( fract( waveIn.xy * vec2( 1.975, 0.793 ) ) * 2.0 - 1.0 );
waves = smoothTriangleWave( waves );
// Sum up the two waves into a single wave.
return ( waves.x + waves.y ) * strength;
}
vec2 windEffect( float bbPhase,
vec2 windDirection,
float gustLength,
float gustFrequency,
float gustStrength,
float turbFrequency,
float turbStrength )
{
// Calculate the ambient wind turbulence.
float turbulence = windTurbulence( bbPhase, turbFrequency, turbStrength );
// We simulate the overall gust via a sine wave.
float gustPhase = clamp( sin( ( bbPhase - gustFrequency ) / gustLength ) , 0.0, 1.0 );
float gustOffset = ( gustPhase * gustStrength ) + ( ( 0.2 + gustPhase ) * turbulence );
// Return the final directional wind effect.
return vec2(gustOffset) * windDirection.xy;
}
void foliageProcessVert( inout vec3 position,
inout vec4 diffuse,
inout vec4 texCoord,
inout vec3 normal,
inout vec3 T,
in vec3 eyePos )
{
// Assign the normal and tagent values.
//normal = vec3( 0, 0, 1 );//cross( gc_camUp, gc_camRight );
T = gc_camRight;
// Pull out local vars we need for work.
int corner = int( ( diffuse.a * 255.0 ) + 0.5 );
vec2 size = texCoord.xy;
int type = int( texCoord.z );
// The billboarding is based on the camera direction.
vec3 rightVec = gc_camRight * sCornerRight[corner];
vec3 upVec = gc_camUp * sCornerUp[corner];
// Figure out the corner position.
vec3 outPos = ( upVec * size.y ) + ( rightVec * size.x );
float len = length( outPos.xyz );
// We derive the billboard phase used for wind calculations from its position.
float bbPhase = dot( position.xyz, vec3( 1.0 ) );
// Get the overall wind gust and turbulence effects.
vec3 wind;
wind.xy = windEffect( bbPhase,
gc_windDir,
gc_gustInfo.x, gc_gustInfo.y, gc_gustInfo.z,
gc_turbInfo.x, gc_turbInfo.y );
wind.z = 0.0;
// Add the summed wind effect into the point.
outPos.xyz += wind.xyz * texCoord.w;
// Do a simple spherical clamp to keep the foliage
// from stretching too much by wind effect.
outPos.xyz = normalize( outPos.xyz ) * len;
// Move the point into world space.
position += outPos;
// Grab the uv set and setup the texture coord.
vec4 uvSet = gc_typeRects[type];
texCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
texCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
// Animate the normal to get lighting changes
// across the the wind swept foliage.
//
// TODO: Expose the 10x as a factor to control
// how much the wind effects the lighting on the grass.
//
normal.xy += wind.xy * ( 10.0 * texCoord.w );
normal = normalize( normal );
// Get the alpha fade value.
float fadeStart = gc_fadeParams.x;
float fadeEnd = gc_fadeParams.y;
float fadeRange = fadeEnd - fadeStart;
float dist = distance( eyePos, position.xyz ) - fadeStart;
diffuse.a = 1.0 - clamp( dist / fadeRange, 0.0, 1.0 );
}

View file

@ -0,0 +1,42 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap, alphaMap;
uniform vec4 groundAlpha;
in vec4 color, groundAlphaCoeff;
in vec2 outTexCoord, alphaLookup;
out vec4 OUT_col;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
vec4 alpha = texture(alphaMap, alphaLookup);
OUT_col = color * texture(diffuseMap, outTexCoord);
OUT_col.a = OUT_col.a * min(alpha, groundAlpha + groundAlphaCoeff.x).x;
}

View file

@ -0,0 +1,99 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec3 vNormal;
in vec4 vColor;
in vec2 vTexCoord0;
in vec2 vTexCoord1;
in vec2 vTexCoord2;
uniform mat4 projection, world;
uniform vec3 CameraPos;
uniform float GlobalSwayPhase, SwayMagnitudeSide, SwayMagnitudeFront,
GlobalLightPhase, LuminanceMagnitude, LuminanceMidpoint, DistanceRange;
out vec4 color, groundAlphaCoeff;
out vec2 outTexCoord, alphaLookup;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
// Init a transform matrix to be used in the following steps
mat4 trans = mat4(0.0);
trans[0][0] = 1.0;
trans[1][1] = 1.0;
trans[2][2] = 1.0;
trans[3][3] = 1.0;
trans[3][0] = vPosition.x;
trans[3][1] = vPosition.y;
trans[3][2] = vPosition.z;
// Billboard transform * world matrix
mat4 o = world;
o = o * trans;
// Keep only the up axis result and position transform.
// This gives us "cheating" cylindrical billboarding.
o[0][0] = 1.0;
o[0][1] = 0.0;
o[0][2] = 0.0;
o[0][3] = 0.0;
o[1][0] = 0.0;
o[1][1] = 1.0;
o[1][2] = 0.0;
o[1][3] = 0.0;
// Handle sway. Sway is stored in a texture coord. The x coordinate is the sway phase multiplier,
// the y coordinate determines if this vertex actually sways or not.
float xSway, ySway;
float wavePhase = GlobalSwayPhase * vTexCoord1.x;
ySway = sin(wavePhase);
xSway = cos(wavePhase);
xSway = xSway * vTexCoord1.y * SwayMagnitudeSide;
ySway = ySway * vTexCoord1.y * SwayMagnitudeFront;
vec4 p;
p = o * vec4(vNormal.x + xSway, ySway, vNormal.z, 1.0);
// Project the point
gl_Position = projection * p;
// Lighting
float Luminance = LuminanceMidpoint + LuminanceMagnitude * cos(GlobalLightPhase + vNormal.y);
// Alpha
vec3 worldPos = vec3(vPosition.x, vPosition.y, vPosition.z);
float alpha = abs(distance(worldPos, CameraPos)) / DistanceRange;
alpha = clamp(alpha, 0.0, 1.0); //pass it through
alphaLookup = vec2(alpha, 0.0);
bool alphaCoeff = bool(vNormal.z);
groundAlphaCoeff = vec4(float(alphaCoeff));
outTexCoord = vTexCoord0.st;
color = vec4(Luminance, Luminance, Luminance, 1.0);
gl_Position.y *= -1;
}

View file

@ -0,0 +1,39 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4x4 modelview;
out vec4 hpos;
out vec2 uv0;
void main()
{
hpos = vec4( modelview * vPosition );
gl_Position = hpos;
uv0 = vTexCoord0.st;
gl_Position.y *= -1;
}

View file

@ -0,0 +1,103 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// These are some simple wrappers for simple
// HLSL compatibility.
#define float4 vec4
#define float3 vec3
#define float2 vec2
#define half float
#define half2 vec2
#define half3 vec3
#define half4 vec4
#define float4x4 mat4
#define float3x3 mat3
#define float2x2 mat2
#define texCUBE texture
#define tex2D texture
#define tex1D texture
#define tex2Dproj textureProj
#define tex2Dlod( sampler, texCoord ) textureLod(sampler, texCoord.xy, texCoord.w)
#define samplerCUBE samplerCube
#define frac fract
#define lerp mix
void tSetMatrixRow(inout float3x3 m, int row, float3 value)
{
m[0][row] = value.x;
m[1][row] = value.y;
m[2][row] = value.z;
}
void tSetMatrixRow(inout float4x4 m, int row, float4 value)
{
m[0][row] = value.x;
m[1][row] = value.y;
m[2][row] = value.z;
m[3][row] = value.w;
}
#define tGetMatrix3Row(matrix, row) float3(matrix[0][row], matrix[1][row], matrix[2][row])
#define tGetMatrix4Row(matrix, row) float4(matrix[0][row], matrix[1][row], matrix[2][row], matrix[3][row])
float3x3 float4x4to3x3(float4x4 m)
{
return float3x3( vec3(m[0]).xyz, m[1].xyz, m[2].xyz);
}
float3x3 float4x4to3x3_(float4x4 m)
{
return float3x3( vec3(m[0]), m[1].xyz, m[2].xyz);
}
mat4 mat4FromRow( float r0c0, float r0c1, float r0c2, float r0c3,
float r1c0, float r1c1, float r1c2, float r1c3,
float r2c0, float r2c1, float r2c2, float r2c3,
float r3c0, float r3c1, float r3c2, float r3c3 )
{
return mat4( r0c0, r1c0, r2c0, r3c0,
r0c1, r1c1, r2c1, r3c1,
r0c2, r1c2, r2c2, r3c2,
r0c3, r1c3, r2c3, r3c3 );
}
#define saturate( val ) clamp( val, 0.0, 1.0 )
#define round( n ) (sign( n ) * floor( abs( n ) + 0.5 ))
#define tMul(a, b) (a*b)
#define inversesqrt( n ) inversesqrt( n )
#define correctSSP(vec) vec.y *= -1
#ifdef TORQUE_PIXEL_SHADER
void clip(float a) { if(a < 0) discard;}
#endif

View file

@ -0,0 +1,161 @@
//-----------------------------------------------------------------------------
// 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 "torque.glsl"
#define IMPOSTER_MAX_UVS 64
void imposter_v(
// These parameters usually come from the vertex.
vec3 center,
int corner,
float halfSize,
vec3 imposterUp,
vec3 imposterRight,
// These are from the imposter shader constant.
int numEquatorSteps,
int numPolarSteps,
float polarAngle,
bool includePoles,
// Other shader constants.
vec3 camPos,
vec4 uvs[IMPOSTER_MAX_UVS],
// The outputs of this function.
out vec3 outWsPosition,
out vec2 outTexCoord,
out mat3 outWorldToTangent
)
{
float M_HALFPI_F = 1.57079632679489661923;
float M_PI_F = 3.14159265358979323846;
float M_2PI_F = 6.28318530717958647692;
float sCornerRight[4];// = float[]( -1.0, 1.0, 1.0, -1.0 );
sCornerRight[0] = -1.0;
sCornerRight[1] = 1.0;
sCornerRight[2] = 1.0;
sCornerRight[3] = -1.0;
float sCornerUp[4];// = float[]( -1.0, -1.0, 1.0, 1.0 );
sCornerUp[0] = -1.0;
sCornerUp[1] = -1.0;
sCornerUp[2] = 1.0;
sCornerUp[3] = 1.0;
vec2 sUVCornerExtent[4];// = vec2[](vec2( 0.0, 1.0 ), vec2( 1.0, 1.0 ), vec2( 1.0, 0.0 ), vec2( 0.0, 0.0 ));
sUVCornerExtent[0] = vec2( 0.0, 1.0 );
sUVCornerExtent[1] = vec2( 1.0, 1.0 );
sUVCornerExtent[2] = vec2( 1.0, 0.0 );
sUVCornerExtent[3] = vec2( 0.0, 0.0 );
// TODO: This could all be calculated on the CPU.
float equatorStepSize = M_2PI_F / float( numEquatorSteps );
float equatorHalfStep = ( equatorStepSize / 2.0 ) - 0.0001;
float polarStepSize = M_PI_F / float( numPolarSteps );
float polarHalfStep = ( polarStepSize / 2.0 ) - 0.0001;
// The vector between the camera and the billboard.
vec3 lookVec = normalize( camPos - center );
// Generate the camera up and right vectors from
// the object transform and camera forward.
vec3 camUp = imposterUp;
vec3 camRight = cross( -lookVec, camUp );
// The billboarding is based on the camera directions.
vec3 rightVec = camRight * sCornerRight[corner];
vec3 upVec = camUp * sCornerUp[corner];
float lookPitch = acos( dot( imposterUp, lookVec ) );
// First check to see if we need to render the top billboard.
int index;
/*
if ( includePoles && ( lookPitch < polarAngle || lookPitch > sPi - polarAngle ) )
{
index = numEquatorSteps * 3;
// When we render the top/bottom billboard we always use
// a fixed vector that matches the rotation of the object.
rightVec = vec3( 1, 0, 0 ) * sCornerRight[corner];
upVec = vec3( 0, 1, 0 ) * sCornerUp[corner];
if ( lookPitch > sPi - polarAngle )
{
upVec = -upVec;
index++;
}
}
else
*/
{
// Calculate the rotation around the z axis then add the
// equator half step. This gets the images to switch a
// half step before the captured angle is met.
float lookAzimuth = atan( lookVec.y, lookVec.x );
float azimuth = atan( imposterRight.y, imposterRight.x );
float rotZ = ( lookAzimuth - azimuth ) + equatorHalfStep;
// The y rotation is calculated from the look vector and
// the object up vector.
float rotY = lookPitch - polarHalfStep;
// TODO: How can we do this without conditionals?
// Normalize the result to 0 to 2PI.
if ( rotZ < 0.0 )
rotZ += M_2PI_F;
if ( rotZ > M_2PI_F )
rotZ -= M_2PI_F;
if ( rotY < 0.0 )
rotY += M_2PI_F;
if ( rotY > M_PI_F ) // Not M_2PI_F?
rotY -= M_2PI_F;
float polarIdx = round( abs( rotY ) / polarStepSize );
// Get the index to the start of the right polar
// images for this viewing angle.
int numPolarOffset = int( float( numEquatorSteps ) * polarIdx );
// Calculate the final image index for lookup
// of the texture coords.
index = int( rotZ / equatorStepSize ) + numPolarOffset;
}
// Generate the final world space position.
outWsPosition = center + ( upVec * halfSize ) + ( rightVec * halfSize );
// Grab the uv set and setup the texture coord.
vec4 uvSet = uvs[index];
outTexCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
outTexCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
// Needed for normal mapping and lighting.
outWorldToTangent[0] = vec3( 1, 0, 0 );
outWorldToTangent[1] = vec3( 0, 1, 0 );
outWorldToTangent[2] = vec3( 0, 0, -1 );
}

View file

@ -0,0 +1,249 @@
//-----------------------------------------------------------------------------
// 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 "./torque.glsl"
#ifndef TORQUE_SHADERGEN
// These are the uniforms used by most lighting shaders.
uniform vec4 inLightPos[3];
uniform vec4 inLightInvRadiusSq;
uniform vec4 inLightColor[4];
#ifndef TORQUE_BL_NOSPOTLIGHT
uniform vec4 inLightSpotDir[3];
uniform vec4 inLightSpotAngle;
uniform vec4 inLightSpotFalloff;
#endif
uniform vec4 ambient;
#define ambientCameraFactor 0.3
uniform float specularPower;
uniform vec4 specularColor;
#endif // !TORQUE_SHADERGEN
void compute4Lights( vec3 wsView,
vec3 wsPosition,
vec3 wsNormal,
vec4 shadowMask,
#ifdef TORQUE_SHADERGEN
vec4 inLightPos[3],
vec4 inLightInvRadiusSq,
vec4 inLightColor[4],
vec4 inLightSpotDir[3],
vec4 inLightSpotAngle,
vec4 inLightSpotFalloff,
float specularPower,
vec4 specularColor,
#endif // TORQUE_SHADERGEN
out vec4 outDiffuse,
out vec4 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;
vec4 lightVectors[3];
for ( i = 0; i < 3; i++ )
lightVectors[i] = wsPosition[i] - inLightPos[i];
vec4 squareDists = vec4(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.
//
vec4 nDotL = vec4(0);
for ( i = 0; i < 3; i++ )
nDotL += lightVectors[i] * -wsNormal[i];
vec4 rDotL = vec4(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.
//
vec3 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(inversesqrt( 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.
//
vec4 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.
vec4 spotAtten = vec4(0);
for ( i = 0; i < 3; i++ )
spotAtten += lightVectors[i] * inLightSpotDir[i];
vec4 cosAngle = ( spotAtten * correction ) - inLightSpotAngle;
atten *= saturate( cosAngle * inLightSpotFalloff );
#endif
// Finally apply the shadow masking on the attenuation.
atten *= shadowMask;
// Get the final light intensity.
vec4 intensity = nDotL * atten;
// Combine the light colors for output.
outDiffuse = vec4(0);
for ( i = 0; i < 4; i++ )
outDiffuse += intensity[i] * inLightColor[i];
// Output the specular power.
vec4 specularIntensity = pow( rDotL, vec4(specularPower) ) * atten;
// Apply the per-light specular attenuation.
vec4 specular = vec4(0,0,0,1);
for ( i = 0; i < 4; i++ )
specular += vec4( 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 = specularColor * specular;
}
// This value is used in AL as a constant power to raise specular values
// to, before storing them into the light info buffer. The per-material
// specular value is then computer by using the integer identity of
// exponentiation:
//
// (a^m)^n = a^(m*n)
//
// or
//
// (specular^constSpecular)^(matSpecular/constSpecular) = specular^(matSpecular*constSpecular)
//
#define AL_ConstantSpecularPower 12.0f
/// The specular calculation used in Advanced Lighting.
///
/// @param toLight Normalized vector representing direction from the pixel
/// being lit, to the light source, in world space.
///
/// @param normal Normalized surface normal.
///
/// @param toEye The normalized vector representing direction from the pixel
/// being lit to the camera.
///
float AL_CalcSpecular( vec3 toLight, vec3 normal, vec3 toEye )
{
// (R.V)^c
float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye );
// Return the specular factor.
return pow( max( specVal, 0.00001f ), AL_ConstantSpecularPower );
}
/// The output for Deferred Lighting
///
/// @param toLight Normalized vector representing direction from the pixel
/// being lit, to the light source, in world space.
///
/// @param normal Normalized surface normal.
///
/// @param toEye The normalized vector representing direction from the pixel
/// being lit to the camera.
///
vec4 AL_DeferredOutput(
vec3 lightColor,
vec3 diffuseColor,
vec4 matInfo,
vec4 ambient,
float specular,
float shadowAttenuation)
{
vec3 specularColor = vec3(specular);
bool metalness = getFlag(matInfo.r, 3);
if ( metalness )
{
specularColor = 0.04 * (1 - specular) + diffuseColor * specular;
}
//specular = color * map * spec^gloss
float specularOut = (specularColor * matInfo.b * min(pow(max(specular,1.0f), max((matInfo.a / AL_ConstantSpecularPower),1.0f)),matInfo.a)).r;
lightColor *= vec3(shadowAttenuation);
lightColor += ambient.rgb;
return vec4(lightColor.rgb, specularOut);
}

View file

@ -0,0 +1,62 @@
//-----------------------------------------------------------------------------
// 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 "torque.glsl"
#include "hlslCompat.glsl"
in vec4 offscreenPos;
in vec4 backbufferPos;
#define IN_offscreenPos offscreenPos
#define IN_backbufferPos backbufferPos
uniform sampler2D colorSource;
uniform vec4 offscreenTargetParams;
#ifdef TORQUE_LINEAR_DEPTH
#define REJECT_EDGES
uniform sampler2D edgeSource;
uniform vec4 edgeTargetParams;
#endif
out vec4 OUT_col;
void main()
{
// Off-screen particle source screenspace position in XY
// Back-buffer screenspace position in ZW
vec4 ssPos = vec4(offscreenPos.xy / offscreenPos.w, backbufferPos.xy / backbufferPos.w);
vec4 uvScene = ( ssPos + 1.0 ) / 2.0;
uvScene.yw = 1.0 - uvScene.yw;
uvScene.xy = viewportCoordToRenderTarget(uvScene.xy, offscreenTargetParams);
#ifdef REJECT_EDGES
// Cut out particles along the edges, this will create the stencil mask
uvScene.zw = viewportCoordToRenderTarget(uvScene.zw, edgeTargetParams);
float edge = texture( edgeSource, uvScene.zw ).r;
clip( -edge );
#endif
// Sample offscreen target and return
OUT_col = texture( colorSource, uvScene.xy );
}

View file

@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
// 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 "hlslCompat.glsl"
in vec2 vTexCoord0;
#define uvCoord vTexCoord0
out vec4 offscreenPos;
out vec4 backbufferPos;
#define OUT_hpos gl_Position
#define OUT_offscreenPos offscreenPos
#define OUT_backbufferPos backbufferPos
uniform vec4 screenRect; // point, extent
void main()
{
OUT_hpos = vec4(uvCoord.xy, 1.0, 1.0);
OUT_hpos.xy *= screenRect.zw;
OUT_hpos.xy += screenRect.xy;
OUT_backbufferPos = OUT_hpos;
OUT_offscreenPos = OUT_hpos;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,113 @@
//-----------------------------------------------------------------------------
// 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 "torque.glsl"
#include "hlslCompat.glsl"
// With advanced lighting we get soft particles.
#ifdef TORQUE_LINEAR_DEPTH
#define SOFTPARTICLES
#endif
#ifdef SOFTPARTICLES
#include "shadergen:/autogenConditioners.h"
uniform float oneOverSoftness;
uniform float oneOverFar;
uniform sampler2D prepassTex;
//uniform vec3 vEye;
uniform vec4 prePassTargetParams;
#endif
#define CLIP_Z // TODO: Make this a proper macro
in vec4 color;
in vec2 uv0;
in vec4 pos;
#define IN_color color
#define IN_uv0 uv0
#define IN_pos pos
uniform sampler2D diffuseMap;
uniform sampler2D paraboloidLightMap;
vec4 lmSample( vec3 nrm )
{
bool calcBack = (nrm.z < 0.0);
if ( calcBack )
nrm.z = nrm.z * -1.0;
vec2 lmCoord;
lmCoord.x = (nrm.x / (2*(1 + nrm.z))) + 0.5;
lmCoord.y = 1-((nrm.y / (2*(1 + nrm.z))) + 0.5);
// If this is the back, offset in the atlas
if ( calcBack )
lmCoord.x += 1.0;
// Atlasing front and back maps, so scale
lmCoord.x *= 0.5;
return texture(paraboloidLightMap, lmCoord);
}
uniform float alphaFactor;
uniform float alphaScale;
out vec4 OUT_col;
void main()
{
float softBlend = 1;
#ifdef SOFTPARTICLES
vec2 tc = IN_pos.xy * vec2(1.0, -1.0) / IN_pos.w;
tc = viewportCoordToRenderTarget(saturate( ( tc + 1.0 ) * 0.5 ), prePassTargetParams);
float sceneDepth = prepassUncondition( prepassTex, tc ).w;
float depth = IN_pos.w * oneOverFar;
float diff = sceneDepth - depth;
#ifdef CLIP_Z
// If drawing offscreen, this acts as the depth test, since we don't line up with the z-buffer
// When drawing high-res, though, we want to be able to take advantage of hi-z
// so this is #ifdef'd out
//clip(diff);
#endif
softBlend = saturate( diff * oneOverSoftness );
#endif
vec4 diffuse = texture( diffuseMap, IN_uv0 );
//OUT_col = vec4( lmSample(vec3(0, 0, -1)).rgb, IN_color.a * diffuse.a * softBlend * alphaScale);
// Scale output color by the alpha factor (turn LerpAlpha into pre-multiplied alpha)
vec3 colorScale = ( alphaFactor < 0.0 ? IN_color.rgb * diffuse.rgb : vec3( alphaFactor > 0.0 ? IN_color.a * diffuse.a * alphaFactor * softBlend : softBlend ) );
OUT_col = hdrEncode( vec4( IN_color.rgb * diffuse.rgb * colorScale,
IN_color.a * diffuse.a * softBlend * alphaScale ) );
}

View file

@ -0,0 +1,54 @@
//-----------------------------------------------------------------------------
// 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 "hlslCompat.glsl"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
#define In_pos vPosition
#define In_color vColor
#define In_uv0 vTexCoord0
out vec4 color;
out vec2 uv0;
out vec4 pos;
#define OUT_hpos gl_Position
#define OUT_color color
#define OUT_uv0 uv0
#define OUT_pos pos
uniform mat4 modelViewProj;
uniform mat4 fsModelViewProj;
void main()
{
OUT_hpos = tMul( modelViewProj, In_pos );
OUT_pos = tMul( fsModelViewProj, In_pos );
OUT_color = In_color;
OUT_uv0 = In_uv0;
correctSSP(gl_Position);
}

Some files were not shown because too many files have changed in this diff Show more