Skip to content

Commit

Permalink
Adds support for multiple textures used in the strike rendering per @…
Browse files Browse the repository at this point in the history
  • Loading branch information
Areloch committed Jan 20, 2017
1 parent c7b041f commit ec8b657
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Engine/source/T3D/fx/lightning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ LightningData::LightningData()
dMemset( strikeTextureNames, 0, sizeof( strikeTextureNames ) );
dMemset( strikeTextures, 0, sizeof( strikeTextures ) );
dMemset( thunderSounds, 0, sizeof( thunderSounds ) );
mNumStrikeTextures = 0;
}

LightningData::~LightningData()
Expand Down Expand Up @@ -297,10 +298,14 @@ bool LightningData::preload(bool server, String &errorStr)
if( !sfxResolve( &strikeSound, sfxErrorStr ) )
Con::errorf(ConsoleLogEntry::General, "LightningData::preload: Invalid packet: %s", sfxErrorStr.c_str());

mNumStrikeTextures = 0;
for (U32 i = 0; i < MaxTextures; i++)
{
if (strikeTextureNames[i][0])
{
strikeTextures[i] = GFXTexHandle(strikeTextureNames[i], &GFXDefaultStaticDiffuseProfile, avar("%s() - strikeTextures[%d] (line %d)", __FUNCTION__, i, __LINE__));
mNumStrikeTextures++;
}
}
}

Expand All @@ -317,6 +322,9 @@ void LightningData::packData(BitStream* stream)
U32 i;
for (i = 0; i < MaxThunders; i++)
sfxWrite( stream, thunderSounds[ i ] );

stream->writeInt(mNumStrikeTextures, 4);

for (i = 0; i < MaxTextures; i++) {
stream->writeString(strikeTextureNames[i]);
}
Expand All @@ -331,6 +339,9 @@ void LightningData::unpackData(BitStream* stream)
U32 i;
for (i = 0; i < MaxThunders; i++)
sfxRead( stream, &thunderSounds[ i ] );

mNumStrikeTextures = stream->readInt(4);

for (i = 0; i < MaxTextures; i++) {
strikeTextureNames[i] = stream->readSTString();
}
Expand Down Expand Up @@ -479,7 +490,7 @@ void Lightning::renderObject(ObjectRenderInst *ri, SceneRenderState *state, Base
desc.setCullMode(GFXCullNone);
desc.zWriteEnable = false;

if (mDataBlock->strikeTextures[0].isValid())
if (mDataBlock->mNumStrikeTextures != 0)
{
desc.samplersDefined = true;
desc.samplers[0].magFilter = GFXTextureFilterLinear;
Expand All @@ -498,8 +509,14 @@ void Lightning::renderObject(ObjectRenderInst *ri, SceneRenderState *state, Base
Strike* walk = mStrikeListHead;
while (walk != NULL)
{
if (mDataBlock->strikeTextures[0].isValid())
if (mDataBlock->mNumStrikeTextures > 1)
{
GFX->setTexture(0, mDataBlock->strikeTextures[sgLightningRand.randI(0, mDataBlock->mNumStrikeTextures - 1)]);
}
else if (mDataBlock->mNumStrikeTextures > 0)
{
GFX->setTexture(0, mDataBlock->strikeTextures[0]);
}

for( U32 i=0; i<3; i++ )
{
Expand Down
1 change: 1 addition & 0 deletions Engine/source/T3D/fx/lightning.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class LightningData : public GameBaseData

GFXTexHandle strikeTextures[MaxTextures];
U32 numThunders;
U32 mNumStrikeTextures;

protected:
bool onAdd();
Expand Down
2 changes: 2 additions & 0 deletions Templates/Full/game/art/datablocks/environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ datablock LightningData(DefaultStorm)
thunderSounds[1] = ThunderCrash2Sound;
thunderSounds[2] = ThunderCrash3Sound;
thunderSounds[3] = ThunderCrash4Sound;

strikeTextures[0] = "art/environment/lightning";
};

datablock ReflectorDesc( DefaultCubeDesc )
Expand Down
Binary file added Templates/Full/game/art/environment/lightning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ec8b657

Please sign in to comment.