Przeglądaj źródła

Script integration for Ribbons

LukasPJ 11 lat temu
rodzic
commit
35f88a77b1

+ 48 - 0
Templates/Empty/game/art/ribbons/materials.cs

@@ -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.
+//-----------------------------------------------------------------------------
+
+// This material should work fine for uniformly colored ribbons.
+
+//Basic ribbon shader/////////////////////////////////////////////
+ 
+new ShaderData( basicRibbonShader )
+{
+   DXVertexShaderFile   = "shaders/common/ribbons/basicRibbonShaderV.hlsl";
+   DXPixelShaderFile    = "shaders/common/ribbons/basicRibbonShaderP.hlsl";
+ 
+   pixVersion = 2.0;
+};
+ 
+singleton CustomMaterial( basicRibbonMat )
+{
+   shader = basicRibbonShader;
+   version = 2.0;
+   
+   emissive[0] = true;
+   
+   doubleSided = true;
+   translucent = true;
+   BlendOp = AddAlpha;
+   translucentBlendOp = AddAlpha;
+   
+   preload = true;
+};

+ 23 - 0
Templates/Empty/game/art/ribbons/ribbonExec.cs

@@ -0,0 +1,23 @@
+//-----------------------------------------------------------------------------
+// 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.
+//-----------------------------------------------------------------------------
+
+exec("./ribbons.cs");

+ 44 - 0
Templates/Empty/game/art/ribbons/ribbons.cs

@@ -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.
+//-----------------------------------------------------------------------------
+  
+datablock RibbonNodeData(DefaultRibbonNodeData)
+{
+   timeMultiple = 1.0;
+};
+
+//ribbon data////////////////////////////////////////
+
+datablock RibbonData(basicRibbon)
+{
+   size[0] = 0.5;
+   color[0] = "1.0 0.0 0.0 1.0";
+   position[0] = 0.0;
+ 
+   size[1] = 0.0;
+   color[1] = "1.0 0.0 0.0 0.0";
+   position[1] = 1.0;
+ 
+   RibbonLength = 40;
+   fadeAwayStep = 0.1;
+   UseFadeOut = true;
+   RibbonMaterial = basicRibbonMat;
+};

+ 1 - 0
Templates/Empty/game/core/scripts/server/game.cs

@@ -34,6 +34,7 @@ function onServerCreated()
    
    // Load up any objects or datablocks saved to the editor managed scripts
    %datablockFiles = new ArrayObject();
+   %datablockFiles.add( "art/ribbons/ribbonExec.cs" );   
    %datablockFiles.add( "art/particles/managedParticleData.cs" );
    %datablockFiles.add( "art/particles/managedParticleEmitterData.cs" );
    %datablockFiles.add( "art/decals/managedDecalData.cs" );

+ 1 - 0
Templates/Empty/game/scripts/server/game.cs

@@ -144,6 +144,7 @@ function onServerCreated()
    
    // Load up any objects or datablocks saved to the editor managed scripts
    %datablockFiles = new ArrayObject();
+   %datablockFiles.add( "art/ribbons/ribbonExec.cs" );   
    %datablockFiles.add( "art/particles/managedParticleData.cs" );
    %datablockFiles.add( "art/particles/managedParticleEmitterData.cs" );
    %datablockFiles.add( "art/decals/managedDecalData.cs" );

+ 18 - 0
Templates/Empty/game/shaders/common/ribbons/basicRibbonShaderP.hlsl

@@ -0,0 +1,18 @@
+#define IN_HLSL
+#include "../common/shdrConsts.h"
+ 
+struct v2f
+{
+       
+   float2 texCoord        : TEXCOORD0;
+   float2 shiftdata       : TEXCOORD1;
+   float4 color           : COLOR0;
+};
+ 
+float4 main(v2f IN) : COLOR0
+{
+   float fade = 1.0 - abs(IN.shiftdata.y - 0.5) * 2.0;
+   IN.color.xyz = IN.color.xyz + pow(fade, 4) / 10;
+   IN.color.a = IN.color.a * fade;
+   return IN.color;
+}

+ 34 - 0
Templates/Empty/game/shaders/common/ribbons/basicRibbonShaderV.hlsl

@@ -0,0 +1,34 @@
+#define IN_HLSL
+#include "../common/shdrConsts.h"
+ 
+struct a2v
+{
+        float2 texCoord        : TEXCOORD0;
+        float2 shiftdata       : TEXCOORD1;
+        float3 normal          : NORMAL;
+        float4 position        : POSITION;
+        float4 color           : COLOR0;
+};
+ 
+struct v2f
+{
+        float4 hpos            : POSITION;
+        float2 texCoord        : TEXCOORD0;
+        float2 shiftdata       : TEXCOORD1;
+        float4 color           : COLOR0;
+};
+ 
+uniform float4x4 modelview;
+uniform float3   eyePos;
+ 
+v2f main(a2v IN)
+{
+    v2f OUT;
+ 
+    OUT.hpos = mul(modelview, IN.position);
+    OUT.color = IN.color;
+    OUT.texCoord = IN.texCoord;
+    OUT.shiftdata = IN.shiftdata;
+   
+    return OUT;
+}

+ 8 - 0
Templates/Empty/game/tools/worldEditor/gui/objectBuilderGui.ed.gui

@@ -862,6 +862,14 @@ function ObjectBuilderGui::buildParticleEmitterNode(%this)
    %this.process();
 }
 
+function ObjectBuilderGui::buildRibbonNode(%this)
+{
+   %this.objectClassName = "RibbonNode";
+   %this.addField("dataBlock", "TypeDataBlock", "datablock", "RibbonNodeData");
+   %this.addField("ribbon",   "TypeDataBlock", "Ribbon data", "RibbonData");
+   %this.process();
+}
+
 function ObjectBuilderGui::buildParticleSimulation(%this)
 {
    %this.objectClassName = "ParticleSimulation";

+ 1 - 0
Templates/Empty/game/tools/worldEditor/scripts/editors/creator.ed.cs

@@ -46,6 +46,7 @@ function EWCreatorWindow::init( %this )
       %this.registerMissionObject( "SFXEmitter",          "Sound Emitter" );
       %this.registerMissionObject( "Precipitation" );
       %this.registerMissionObject( "ParticleEmitterNode", "Particle Emitter" );
+      %this.registerMissionObject( "RibbonNode", "Ribbon" );
       
       // Legacy features. Users should use Ground Cover and the Forest Editor.   
       //%this.registerMissionObject( "fxShapeReplicator",   "Shape Replicator" );

+ 77 - 0
Templates/Full/game/art/ribbons/materials.cs

@@ -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.
+//-----------------------------------------------------------------------------
+
+// This material should work fine for uniformly colored ribbons.
+
+//Basic ribbon shader/////////////////////////////////////////////
+ 
+new ShaderData( basicRibbonShader )
+{
+   DXVertexShaderFile   = "shaders/common/ribbons/basicRibbonShaderV.hlsl";
+   DXPixelShaderFile    = "shaders/common/ribbons/basicRibbonShaderP.hlsl";
+ 
+   pixVersion = 2.0;
+};
+ 
+singleton CustomMaterial( basicRibbonMat )
+{
+   shader = basicRibbonShader;
+   version = 2.0;
+   
+   emissive[0] = true;
+   
+   doubleSided = true;
+   translucent = true;
+   BlendOp = AddAlpha;
+   translucentBlendOp = AddAlpha;
+   
+   preload = true;
+};
+
+// This material can render a texture on top of a ribbon.
+
+//Texture ribbon shader/////////////////////////////////////////////
+ 
+new ShaderData( texRibbonShader )
+{
+   DXVertexShaderFile   = "shaders/common/ribbons/texRibbonShaderV.hlsl";
+   DXPixelShaderFile    = "shaders/common/ribbons/texRibbonShaderP.hlsl";
+ 
+   pixVersion = 2.0;
+};
+ 
+singleton CustomMaterial( texRibbonMat )
+{
+   shader = texRibbonShader;
+   version = 2.0;
+   
+   emissive[0] = true;
+   
+   doubleSided = true;
+   translucent = true;
+   BlendOp = AddAlpha;
+   translucentBlendOp = AddAlpha;
+
+   sampler["ribTex"] = "art/ribbons/ribTex.png";
+   
+   preload = true;
+};

BIN
Templates/Full/game/art/ribbons/ribTex.png


+ 23 - 0
Templates/Full/game/art/ribbons/ribbonExec.cs

@@ -0,0 +1,23 @@
+//-----------------------------------------------------------------------------
+// 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.
+//-----------------------------------------------------------------------------
+
+exec("./ribbons.cs");

+ 63 - 0
Templates/Full/game/art/ribbons/ribbons.cs

@@ -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.
+//-----------------------------------------------------------------------------
+  
+datablock RibbonNodeData(DefaultRibbonNodeData)
+{
+   timeMultiple = 1.0;
+};
+
+//ribbon data////////////////////////////////////////
+
+datablock RibbonData(basicRibbon)
+{
+   size[0] = 0.5;
+   color[0] = "1.0 0.0 0.0 1.0";
+   position[0] = 0.0;
+ 
+   size[1] = 0.0;
+   color[1] = "1.0 0.0 0.0 0.0";
+   position[1] = 1.0;
+ 
+   RibbonLength = 40;
+   fadeAwayStep = 0.1;
+   UseFadeOut = true;
+   RibbonMaterial = basicRibbonMat;
+};
+
+datablock RibbonData(texRibbon)
+{
+   RibbonMaterial = texRibbonMat;
+   size[0] = 0.5;
+   color[0] = "1.0 1.0 1.0 1.0";
+   position[0] = 0.0;
+ 
+   size[1] = 0.5;
+   color[1] = "1.0 1.0 1.0 1.0";
+   position[1] = 1.0;
+ 
+   RibbonLength = 40;
+   fadeAwayStep = 0.1;
+   UseFadeOut = true;
+   tileScale = 1;
+   fixedTexCoords = true;
+   TexcoordsRelativeToDistance = true;
+};

+ 1 - 0
Templates/Full/game/core/scripts/server/game.cs

@@ -34,6 +34,7 @@ function onServerCreated()
    
    // Load up any objects or datablocks saved to the editor managed scripts
    %datablockFiles = new ArrayObject();
+   %datablockFiles.add( "art/ribbons/ribbonExec.cs" );   
    %datablockFiles.add( "art/particles/managedParticleData.cs" );
    %datablockFiles.add( "art/particles/managedParticleEmitterData.cs" );
    %datablockFiles.add( "art/decals/managedDecalData.cs" );

+ 1 - 0
Templates/Full/game/scripts/server/game.cs

@@ -50,6 +50,7 @@ function onServerCreated()
 
    // Load up any objects or datablocks saved to the editor managed scripts
    %datablockFiles = new ArrayObject();
+   %datablockFiles.add( "art/ribbons/ribbonExec.cs" );   
    %datablockFiles.add( "art/particles/managedParticleData.cs" );
    %datablockFiles.add( "art/particles/managedParticleEmitterData.cs" );
    %datablockFiles.add( "art/decals/managedDecalData.cs" );

+ 18 - 0
Templates/Full/game/shaders/common/ribbons/basicRibbonShaderP.hlsl

@@ -0,0 +1,18 @@
+#define IN_HLSL
+#include "../common/shdrConsts.h"
+ 
+struct v2f
+{
+       
+   float2 texCoord        : TEXCOORD0;
+   float2 shiftdata       : TEXCOORD1;
+   float4 color           : COLOR0;
+};
+ 
+float4 main(v2f IN) : COLOR0
+{
+   float fade = 1.0 - abs(IN.shiftdata.y - 0.5) * 2.0;
+   IN.color.xyz = IN.color.xyz + pow(fade, 4) / 10;
+   IN.color.a = IN.color.a * fade;
+   return IN.color;
+}

+ 34 - 0
Templates/Full/game/shaders/common/ribbons/basicRibbonShaderV.hlsl

@@ -0,0 +1,34 @@
+#define IN_HLSL
+#include "../common/shdrConsts.h"
+ 
+struct a2v
+{
+        float2 texCoord        : TEXCOORD0;
+        float2 shiftdata       : TEXCOORD1;
+        float3 normal          : NORMAL;
+        float4 position        : POSITION;
+        float4 color           : COLOR0;
+};
+ 
+struct v2f
+{
+        float4 hpos            : POSITION;
+        float2 texCoord        : TEXCOORD0;
+        float2 shiftdata       : TEXCOORD1;
+        float4 color           : COLOR0;
+};
+ 
+uniform float4x4 modelview;
+uniform float3   eyePos;
+ 
+v2f main(a2v IN)
+{
+    v2f OUT;
+ 
+    OUT.hpos = mul(modelview, IN.position);
+    OUT.color = IN.color;
+    OUT.texCoord = IN.texCoord;
+    OUT.shiftdata = IN.shiftdata;
+   
+    return OUT;
+}

+ 20 - 0
Templates/Full/game/shaders/common/ribbons/texRibbonShaderP.hlsl

@@ -0,0 +1,20 @@
+#define IN_HLSL
+#include "../common/shdrConsts.h"
+#include "shaders/common/torque.hlsl"
+ 
+uniform sampler2D ribTex : register(S0);
+ 
+struct v2f
+{
+           
+   float2 texCoord        : TEXCOORD0;
+   float2 shiftdata       : TEXCOORD1;
+   float4 color           : COLOR0;
+};
+ 
+float4 main(v2f IN) : COLOR0
+{
+    float4 Tex = tex2D(ribTex,IN.texCoord);
+	Tex.a *= IN.color.a;
+	return hdrEncode(Tex);
+}

+ 34 - 0
Templates/Full/game/shaders/common/ribbons/texRibbonShaderV.hlsl

@@ -0,0 +1,34 @@
+#define IN_HLSL
+#include "../common/shdrConsts.h"
+ 
+struct a2v
+{
+        float2 texCoord        : TEXCOORD0;
+        float2 shiftdata       : TEXCOORD1;
+        float3 normal          : NORMAL;
+        float4 position        : POSITION;
+        float4 color           : COLOR0;
+};
+ 
+struct v2f
+{
+        float4 hpos            : POSITION;
+        float2 texCoord        : TEXCOORD0;
+        float2 shiftdata       : TEXCOORD1;
+        float4 color           : COLOR0;
+};
+ 
+uniform float4x4 modelview;
+uniform float3   eyePos;
+ 
+v2f main(a2v IN)
+{
+    v2f OUT;
+ 
+    OUT.hpos = mul(modelview, IN.position);
+    OUT.color = IN.color;
+    OUT.texCoord = IN.texCoord;
+    OUT.shiftdata = IN.shiftdata;
+   
+    return OUT;
+}

+ 8 - 0
Templates/Full/game/tools/worldEditor/gui/objectBuilderGui.ed.gui

@@ -862,6 +862,14 @@ function ObjectBuilderGui::buildParticleEmitterNode(%this)
    %this.process();
 }
 
+function ObjectBuilderGui::buildRibbonNode(%this)
+{
+   %this.objectClassName = "RibbonNode";
+   %this.addField("dataBlock", "TypeDataBlock", "datablock", "RibbonNodeData");
+   %this.addField("ribbon",   "TypeDataBlock", "Ribbon data", "RibbonData");
+   %this.process();
+}
+
 function ObjectBuilderGui::buildParticleSimulation(%this)
 {
    %this.objectClassName = "ParticleSimulation";

+ 1 - 0
Templates/Full/game/tools/worldEditor/scripts/editors/creator.ed.cs

@@ -46,6 +46,7 @@ function EWCreatorWindow::init( %this )
       %this.registerMissionObject( "SFXEmitter",          "Sound Emitter" );
       %this.registerMissionObject( "Precipitation" );
       %this.registerMissionObject( "ParticleEmitterNode", "Particle Emitter" );
+      %this.registerMissionObject( "RibbonNode", "Ribbon" );
       
       // Legacy features. Users should use Ground Cover and the Forest Editor.   
       //%this.registerMissionObject( "fxShapeReplicator",   "Shape Replicator" );