瀏覽代碼

BloomWIP 1

Samuel Skiff 2 年之前
父節點
當前提交
ade74c1016

+ 2 - 0
.gitignore

@@ -184,3 +184,5 @@ Project Manager.exe
 projects.xml
 Qt*.dll
 .vs
+Engine/lib/assimp/include/assimp/config.h
+Engine/lib/assimp/revision.h

+ 153 - 0
Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript

@@ -0,0 +1,153 @@
+//-----------------------------------------------------------------------------
+// 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_Bloom_Shader )
+{
+   DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl";
+	 DXPixelShaderFile  = "./bloomP.hlsl";
+	 
+	 samplerNames[0] = "$inputTex";
+	 
+	 pixVersion = 3.0;
+};
+
+singleton ShaderData( PFX_BloomDownSample_Shader )
+{
+   DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl";
+	 DXPixelShaderFile  = "./downSampleP.hlsl";
+	 
+	 samplerNames[0] = "$inputTex";
+	 
+	 pixVersion = 3.0;
+};
+
+singleton GFXStateBlockData( BloomPostFX_SampleStateBlock : PFX_DefaultStateBlock )
+{
+   samplersDefined = true;
+   samplerStates[0] = SamplerClampLinear;
+};
+
+function BloomPostFX::setShaderConsts( %this )
+{
+}
+
+function BloomPostFX::preProcess( %this )
+{
+}
+
+function BloomPostFX::onAdd(%this)
+{
+   //Register the postFX with the manager
+   PostFXManager.registerPostEffect(%this);
+}
+
+function BloomPostFX::onEnabled( %this )
+{
+   return true;
+}
+
+function BloomPostFX::onDisabled( %this )
+{
+   return true;
+}
+
+//This is used to populate the PostFXEditor's settings so the post FX can be edited
+//This is automatically polled for any postFX that has been registered(in our onAdd) and the settings
+//are thus exposed for editing
+function BloomPostFX::populatePostFXSettings(%this)
+{
+   PostEffectEditorInspector.startGroup("BloomPostFX - General");
+   PostEffectEditorInspector.addCallbackField("$PostFX::BloomPostFX::Enabled", "Enabled", "bool", "", $PostFX::BloomPostFX::Enabled, "", "toggleBloomPostFX");
+   PostEffectEditorInspector.endGroup();
+}
+
+//This is called back from our callbackField defined in populatePostFXSettings to
+//Allow us to easily toggle the postFX and have it respond immediately
+function PostEffectEditorInspector::toggleBloomPostFX(%this)
+{
+   if($PostFX::BloomPostFX::Enabled)
+      BloomPostFX.enable();
+   else
+      BloomPostFX.disable();
+}
+
+//This function pair(applyFromPreset and settingsApply) are done the way they are, with the separated variables
+//so that we can effectively store the 'settings' away from the live variables that the postFX's actually utilize
+//when rendering. This allows us to modify things but still leave room for reverting or temporarily applying them
+function BloomPostFX::applyFromPreset(%this)
+{
+   if($PostFX::BloomPostFX::Enabled)
+      %this.enable();
+   else
+      %this.disable();
+}
+
+function BloomPostFX::savePresetSettings(%this)
+{
+   PostFXManager::savePresetSetting("$PostFX::BloomPostFX::Enabled");
+}
+
+//Our actual postFX
+singleton PostEffect( BloomPostFX )
+{
+   enabled = false;
+	 allowReflectPass = false;
+   
+   renderTime = "PFXAfterBin";
+	 renderBin = "EditorBin";
+   renderPriority = 9999; 
+	 
+   shader = PFX_Bloom_Shader;
+   stateBlock = BloomPostFX_SampleStateBlock;
+   texture[0] = "$backBuffer";
+   target = "$outTex";
+	 targetFormat = "GFXFormatR16G16B16A16F";
+	 
+	 new PostEffect()
+	 {
+		allowReflectPass = false;
+		shader = PFX_BloomDownSample_Shader;
+		stateBlock = BloomPostFX_SampleStateBlock;
+		texture[0] = "$inTex";
+		target = "#bloom0";
+		targetScale = "0.5 0.5";
+	 };
+	 
+	 new PostEffect()
+	 {
+		allowReflectPass = false;
+		shader = PFX_BloomDownSample_Shader;
+		stateBlock = BloomPostFX_SampleStateBlock;
+		texture[0] = "#bloom0";
+		target = "#bloom1";
+		targetScale = "0.25 0.25";
+	 };
+	 
+	 new PostEffect()
+	 {
+		allowReflectPass = false;
+		shader = PFX_PassthruShader;
+		stateBlock = BloomPostFX_SampleStateBlock;
+		texture[0] = "#bloom1";
+		target = "$backBuffer";
+	 };
+};

+ 32 - 0
Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomP.hlsl

@@ -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.
+//-----------------------------------------------------------------------------
+
+#include "core/rendering/shaders/postFX/postFx.hlsl"
+
+TORQUE_UNIFORM_SAMPLER2D(inputTex, 0);
+
+float4 main(PFXVertToPix IN) : TORQUE_TARGET0
+{
+	float4 color = TORQUE_TEX2D(inputTex, IN.uv0);
+	float brightness = max(color.r, max(color.g, color.b));
+	return float4(color.rgb * pow(brightness, 8.0f), color.a);
+}

+ 62 - 0
Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl

@@ -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 "core/rendering/shaders/postFX/postFx.hlsl"
+
+//-----------------------------------------------------------------------------
+// Data 
+//-----------------------------------------------------------------------------
+
+TORQUE_UNIFORM_SAMPLER2D(inputTex, 0);
+//uniform float2 targetSize;
+ 
+//-----------------------------------------------------------------------------
+// Main
+//-----------------------------------------------------------------------------
+float4 main(PFXVertToPix IN) : TORQUE_TARGET0
+{
+	float2 texSize = 1.0f / float2(1024.0f, 1024.0f);
+	float x = texSize.x;
+	float y = texSize.y;
+	float4 a = TORQUE_TEX2D( inputTex, IN.uv0 + float2(-x*2.0f, y*2.0f));
+	float4 b = TORQUE_TEX2D( inputTex, IN.uv0 + float2( 0.0f  , y*2.0f));
+	float4 c = TORQUE_TEX2D( inputTex, IN.uv0 + float2( x*2.0f, y*2.0f));
+																		
+	float4 d = TORQUE_TEX2D( inputTex, IN.uv0 + float2(-x*2.0f,   0.0f));
+	float4 e = TORQUE_TEX2D( inputTex, IN.uv0);
+	float4 f = TORQUE_TEX2D( inputTex, IN.uv0 + float2( x*2.0f,   0.0f));
+																		
+	float4 g = TORQUE_TEX2D( inputTex, IN.uv0 + float2(-x*2.0f,-y*2.0f));
+	float4 h = TORQUE_TEX2D( inputTex, IN.uv0 + float2( 0.0f  ,-y*2.0f));
+	float4 i = TORQUE_TEX2D( inputTex, IN.uv0 + float2( x*2.0f,-y*2.0f));
+																		
+	float4 j = TORQUE_TEX2D( inputTex, IN.uv0 + float2(-x, y));
+	float4 k = TORQUE_TEX2D( inputTex, IN.uv0 + float2( x, y));
+	float4 l = TORQUE_TEX2D( inputTex, IN.uv0 + float2(-x,-y));
+	float4 m = TORQUE_TEX2D( inputTex, IN.uv0 + float2( x,-y));
+	
+	float4 sample = e * 0.125f;
+	sample += (a+c+g+i) * 0.03125f;
+	sample += (b+d+f+h) * 0.0625;
+	sample += (j+k+l+m) * 0.125;
+	return sample;
+}

+ 57 - 0
Templates/BaseGame/game/core/postFX/scripts/Bloom/upSampleP.hlsl

@@ -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.
+//-----------------------------------------------------------------------------
+
+#include "core/rendering/shaders/postFX/postFx.hlsl"
+
+struct Conn
+{
+	float4 hpos : TORQUE_POSITION;
+  float2 texCoord : TEXCOORD0;
+};
+
+TORQUE_UNIFORM_SAMPLER2D(inputTex0, 0);
+TORQUE_UNIFORM_SAMPLER2D(inputTex1, 1);
+uniform float filterRadius;
+
+float4 main( Conn V_IN ) : TORQUE_TARGET0
+{
+	float x = filterRadius;
+	float y = filterRadius;
+	
+	float4 a = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2(-x, y));
+	float4 b = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2( 0, y));
+	float4 c = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2( x, y));
+	
+	float4 d = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2(-x, 0));
+	float4 e = TORQUE_TEX2D( inputTex0, V_IN.texCoord);
+	float4 f = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2( x, 0));
+	
+	float4 g = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2(-x,-y));
+	float4 h = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2( 0,-y));
+	float4 i = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2( x,-y));
+	
+	float4 sample = e * 4.0f;
+	sample += (b+d+f+h) * 2.0f;
+	sample += (a+c+g+i);
+	sample *= 1.0f / 16.0f;
+	return sample * 0.75f + TORQUE_TEX2D(inputTex1, V_IN.texCoord) * 0.25f;
+}

+ 1 - 21
Templates/BaseGame/game/core/postFX/scripts/default.postfxpreset.tscript

@@ -1,21 +1 @@
-$PostFX::HDRPostFX::Enabled = 1;
-$PostFX::HDRPostFX::ExposureValue = "1";
-$PostFX::HDRPostFX::minLuminace = "0.001";
-$PostFX::HDRPostFX::whiteCutoff = "1.0";
-$PostFX::HDRPostFX::adaptRate = "1";
-$PostFX::HDRPostFX::tonemapMode = "ACES";
-$PostFX::HDRPostFX::enableBloom = "1";
-$PostFX::HDRPostFX::brightPassThreshold = "0.2";
-$PostFX::HDRPostFX::gaussMultiplier = "0.145";
-$PostFX::HDRPostFX::gaussMean = "0";
-$PostFX::HDRPostFX::gaussStdDev = "0.5";
-$PostFX::HDRPostFX::enableAutoExposure = "0";
-$PostFX::HDRPostFX::keyValue = "0.18";
-$PostFX::HDRPostFX::enableBlueShift = "0";
-$PostFX::HDRPostFX::blueShiftColor = "1.05 0.97 1.27";
-$PostFX::SharpenPostFX::Enabled = "1";
-$PostFX::SharpenPostFX::sharpness = "0.15";
-$PostFX::VignettePostFX::Enabled = "1";
-$PostFX::VignettePostFX::VMin = "0.25";
-$PostFX::VignettePostFX::VMax = "0.9";
-$PostFX::VignettePostFX::Color = "0 0 0 1";
+