Jump to content
Sign in to follow this  
AndyCYXU

after update cloud.fx and rain.fx

Recommended Posts

I updated to 2.4 using method described in AvsimForum by Rob so basically deleted everything p3d related from documents/data roaming and local and program data...
well all went smooth (i think) i replaced few files, actually left the new prepar3d.cfg alone did not use my old one.. so all working fine i think...

One question I made adjustments to cloud.fx the multiply by 0.5 earlier and also made some adjustments to rain.fx
before update i backed up and deleted) rain.fx also backed up (but forgot to delete) cloud.fx file...

after update i check for these files and rain.fx was replaced with an EMPTY rain.fx 0KB file there was nothing in it (there was no rain either :D  ) and cloud.fx was not modified i base that on file date of 9-8-2014 when i edited it.

well i just replaced rain.fx with my backed up copy and removed the 0.5 multiplier from cloud.fx

I think if i did not forget to delete the cloud.fx before update it would also get replaced with an EMPTY cloud.fx

removing the 0.5 multiplier made clouds very big I suppose it impacts performance I am not complaining but for sure i will be putting the multiplier back in cause they were pretty big in major thunderstorms scenario.

OK so I guess what i am trying to ask/find out is if I am missing on something since it seems these files were never touched by updater.. mainly the cloud.fx as this was one of the things updated to remove the quadruple cloud size.

should i have new cloud.fx file created by updater or should i simply remove the multiplier as changes that updater perform had nothing to do with FX files anyways and the quadruple error was fixed somewhere else?

Other then that all seems to be working fine I am just somewhat confused as to this issue.

Thanks
Andy

 

PS: I know there was no updates to rain.fx but just mentioning it as i would expect it to be replaced with a new one after update but all i got was an Empty rain.fx file not an issue i just put my old one back in, just concern about the cloud.fx file.

Share this post


Link to post

I believe there were a few other changes other than just the multiplier. You should be able to delete cloud.fx and re-run the update - it will add the file back in.

 

I can copy the contents of the new cloud.fx file when I get back home (if that helps)...

Share this post


Link to post

Here you go (mods please let me know if this is okay):

 

 

#include "ShaderMacros.h"
#include "ConstantBuffers.fxh"
#include <FuncLibrary.fxh>
#include <IRSim.fxh>
#include <InstanceIndexing.fxh>
#define MAX_COLOR_LEVELS 5

shared Texture2DArray txBase : REGISTER(t,0);
shared Texture2D txNoise : REGISTER(t,1);
shared Texture2D txSceneDepth : REGISTER(t,SCENE_DEPTH_TEXTURE_REGISTER);

//perObject
shared cbuffer cbPerObjectCloudData : REGISTER(b,PER_MATERIAL_CB_REGISTER)
{
    float   fAlpha :                                packoffset(c0.x);
    float   fAlphaEdges :                            packoffset(c0.y);
    float   fRadius :                                packoffset(c0.z);
    float   fCloudExpandScale :                     packoffset(c0.w);

    float   fCloudExpandDistance :                  packoffset(c1.x);
    float   fCloudFadeDistanceInverse :             packoffset(c1.y);
    float   fCloudFadeDistance :                    packoffset(c1.z);
    float   ColorLevelHeightLow :                    packoffset(c1.w);

    float   ColorLevelHeightMediumLow :                packoffset(c2.x);
    float   ColorLevelHeightMedium :                packoffset(c2.y);
    float   ColorLevelHeightMediumHigh :            packoffset(c2.z);
    float   ColorLevelHeightHigh :                    packoffset(c2.w);

    float   fCloudEndFadeDistance :                 packoffset(c3.x);
    float   fCloudExpandSizeScale :                 packoffset(c3.y);
    float   fFiller0 :                              packoffset(c3.z);
    float   fFiller1 :                              packoffset(c3.w);

    float4  ColorLevelColors[MAX_COLOR_LEVELS] :    packoffset(c4);
    
};

struct VS_OUTPUT
{
    float4x4 position : POSITION;
    float4x4 diffuse : COLORS;
    float4 cornerDots : DOT;
    float4 uv : TEXCOORD;
    float2 fFogDistance : FOG;
    float BaseTextureIndex : TEXCOORD1;
    float4 mAlt : ALTITUDE;
};

struct GS_OUTPUT
{
    float4 position : SV_POSITION;
    float2 uv : TEXCOORD;
    float BaseTextureIndex : TEXCOORD1;
    float2 localUV : TEXCOORD2;
    
    #if !defined(SHD_CLOUD_SHADOWS)
        float  eyeDot :  TEXCOORD3;
        float mAlt : ALTITUDE;
        float4 diffuse : COLOR;
        float2 fFogDistance : FOG;
    #else
        float z  : BroughtToYouByTheLatterZ;
        uint RTIndex : SV_RenderTargetArrayIndex;
    #endif
};

struct PS_INPUT
{
#if !defined(SHD_CLOUD_SHADOWS)
        float4 position : SV_POSITION;
#endif
    float2 uv : TEXCOORD;
    float BaseTextureIndex : TEXCOORD1;
    float2 localUV : TEXCOORD2;
    
    #if !defined(SHD_CLOUD_SHADOWS)
        float  eyeDot :  TEXCOORD3;
        float mAlt : ALTITUDE;
        float4 diffuse : COLOR;
        float2 fFogDistance : FOG;
    #else
        float z  : BroughtToYouByTheLatterZ;
    #endif
};

void GetScreenQuadPositions( out float4x3 output, in float width, in float height )
{
    float halfWidth = width;
    float halfHeight = height;
    /// VALUE // Quadrant
    output[0].x = -halfWidth;   //-1
    output[0].y = -halfHeight;  //-1
    output[0].z = 0;

    output[1].x =  halfWidth;   // 1
    output[1].y = -halfHeight;  //-1
    output[1].z = 0;

    output[2].x = -halfWidth;   // -1
    output[2].y =  halfHeight;  //  1
    output[2].z = 0;

    output[3].x = halfWidth;    // 1
    output[3].y = halfHeight;   // 1
    output[3].z = 0;
}

void GetPointDiffuse( out float4 diffuse, in float3 corner, in float3 groupCenter )
{
   
    //
    // Sun lighting
    //
    // See bglfp.cpp, g2d_LightCloudFromNormal() - KEEP SHADER IN SYNC!
    float3 cloudGroupNormal = normalize(corner.xyz - groupCenter);
    float  fIntensity = dot( cb_mLights[sUN_LIGHT].mDirection, cloudGroupNormal );

    if (fIntensity < -cb_mMedianLine)
    {
        // The "1.0001" in the line above is a hack to fix a bug
        // observed on some hardware. Even though the else branch
        // of this if/else was taken a divide by zero in this
        // branch (when cb_mMedianLine is 1.0) caused the whole
        // shader to go crazy.
        fIntensity = cb_mMinIntensity + (cb_mMedianIntensity - cb_mMinIntensity) *
        ((1 + fIntensity) / (1.0001 - cb_mMedianLine));
            
    }
    else
    {
        fIntensity = cb_mMedianIntensity +
            (1 - cb_mMedianIntensity) *
            ((fIntensity + cb_mMedianLine) / (1 + cb_mMedianLine));
    }

    fIntensity = ( .5f * fIntensity * fIntensity ) + saturate( .75f * dot( cb_mLights[sUN_LIGHT].mDirection, float3( 0, 1, 0 ) ));
    float fRed   = fIntensity * cb_mCloudDirectional.r + cb_mCloudAmbient.r;
    float fGreen = fIntensity * cb_mCloudDirectional.g + cb_mCloudAmbient.g;
    float fBlue  = fIntensity * cb_mCloudDirectional.b + cb_mCloudAmbient.b;

    //
    // Height band lighting/coloring
    //
    // See SwarmCloud.cpp, GetColor() - KEEP SHADER IN SYNC!
    float height = corner.y;
    float4 baseColor;
    float4 topColor;
    float  baseHeight;
    float  topHeight;
    
    if (height <= ColorLevelHeightLow)
    {
        baseColor  = ColorLevelColors[0];
        topColor   = ColorLevelColors[0];
        baseHeight = ColorLevelHeightLow;
        topHeight  = ColorLevelHeightLow + 1; // +1 to avoid division by zero below
    }
    else if (height <= ColorLevelHeightMediumLow)
    {
        baseColor  = ColorLevelColors[0];
        topColor   = ColorLevelColors[1];
        baseHeight = ColorLevelHeightLow;
        topHeight  = ColorLevelHeightMediumLow;
    }
    else if (height <= ColorLevelHeightMedium)
    {
        baseColor  = ColorLevelColors[1];
        topColor   = ColorLevelColors[2];
        baseHeight = ColorLevelHeightMediumLow;
        topHeight  = ColorLevelHeightMedium;
    }
    else if (height <= ColorLevelHeightMediumHigh)
    {
        baseColor  = ColorLevelColors[2];
        topColor   = ColorLevelColors[3];
        baseHeight = ColorLevelHeightMedium;
        topHeight  = ColorLevelHeightMediumHigh;
    }
    else if (height <= ColorLevelHeightHigh)
    {
        baseColor  = ColorLevelColors[3];
        topColor   = ColorLevelColors[4];
        baseHeight = ColorLevelHeightMediumHigh;
        topHeight  = ColorLevelHeightHigh;
    }
    else
    {
        baseColor  = ColorLevelColors[4];
        topColor   = ColorLevelColors[4];
        baseHeight = ColorLevelHeightHigh;
        topHeight  = ColorLevelHeightHigh + 1; // +1 to avoid division by zero below
    }
    float s = (height - baseHeight) / (topHeight - baseHeight);
    float4 color = lerp(baseColor, topColor, s);

    //
    // Fade in/out alpha
    float distance_from_center = length(corner);
    float alpha = 1.0f;
    if (fAlpha > 0)
    {
        // Fading in from or out to the edges
        float fMagnitude = 1.3f * fRadius - distance_from_center;
        fMagnitude = max(0, fMagnitude);
        alpha = fAlpha - fAlphaEdges * (fMagnitude / fRadius);
    }
    else
    {
        // Fading out to the core
        alpha = -fAlpha - fAlphaEdges * (distance_from_center / fRadius);
    }
    float4 colorIntensity = float4(fRed, fGreen, fBlue, saturate(alpha)) * color;
    diffuse = saturate( float4( .85f * colorIntensity.rgb + ( 0.33f * saturate( colorIntensity.rgb - 1 )), colorIntensity.a ));
}

VS_OUTPUT VS(VS_INPUT In)
{
    VS_OUTPUT Out = (VS_OUTPUT)0;

    float4 spriteCenter  = In.vPosition;
    float3 groupCenter   = In.vNormal.xyz;
    float4 packedUV      = In.cColor;
    float2 packedCorner  = In.Tex;
    float  bankRadian    = In.fRBias[0];
    float  puffRadius    = In.fRBias[1];
    
    Out.BaseTextureIndex = GetTextureInstanceData( In.mInstanceIndex ).FirstFourIndices.x;

    GeoidTranform geoTrans = GetGeoidTranform( In.mInstanceIndex +2 );
    
    // Get round world matrix
    matrix matWorld = ComputeRoundWorldMatrix( geoTrans, cb_ViewOrigin );
    
    // Set UV
    Out.uv = packedUV;

    // Offset the spritecenter with cluster offset. The cluster is a group of sprite to make up
    // a cloud. This is needed b/c sometime we draw one cluster at a time to do sorting
    float4 clusterOffset = GetCloudClusterOffset( In.mInstanceIndex );

    float3x3 rotationMatrix;
    #if !defined(SHD_CLOUD_SHADOWS)

        // We baked a value [0 or 1] into the w component to tell us if this draw call is per puff
        int IsPuffDraw = saturate( clusterOffset.w );

        float3 positionVector = ( -mul( spriteCenter - clusterOffset, matWorld ).xyz * (1 - IsPuffDraw ) ) + ( -matWorld[3].xyz * IsPuffDraw );

        float3 cameraFacingVector = normalize( positionVector );

        float3 screenFacingVector = normalize( -cb_mInverseView[ 2 ].xyz );

        float cloudDistance = length( positionVector );

        float spriteSize = max( packedCorner.y, packedCorner.x );

        float blendDistance = max( spriteSize, 800 );

        float facingBlend = saturate( (( blendDistance - cloudDistance ) / blendDistance ) + 2 ) * IsPuffDraw;

        rotationMatrix[2] = normalize( lerp( cameraFacingVector, screenFacingVector, facingBlend  ));

        rotationMatrix[0] = normalize( cross( rotationMatrix[2], float3( 0, 1, 0 )));

        rotationMatrix[1] = normalize( -cross( rotationMatrix[2], rotationMatrix[0] ));

        matrix worldView = mul( matWorld, cb_mViewToDevice );
        #if defined(SHD_NO_NEAR_CLIP)
        matrix worldViewProj = mul( worldView, cb_mNoNearProj );
        #elif defined(SHD_NO_FAR_CLIP)
            matrix worldViewProj = mul( worldView, cb_mNoFarProj );        
        #else
            matrix worldViewProj = mul( worldView, cb_mProjToDevice );
        #endif

    #else

        float3 shadowFacingVector = normalize( cb_mShadowLightDirection );

        rotationMatrix[2] = shadowFacingVector;

        rotationMatrix[0] = normalize( cross( rotationMatrix[2], float3( 0, 1.0f, 0 )));

        rotationMatrix[1] = normalize( -cross( rotationMatrix[2], rotationMatrix[0] ));

    #endif

    Out.diffuse = (float4x4)0;

    float4x3 quad = (float4x3)0;
    float height = packedCorner.y ;
    float width = packedCorner.x;
    GetScreenQuadPositions( quad, width*0.5, height*0.5 );

    [unroll]for(int i=0; i<4; i++)
    {
        // Perform rotation
        float3 position = mul( quad.xyz,  rotationMatrix);
        /// Add the sprite center without scale to keep the diffuse color calculation identicle
        position = spriteCenter.xyz + position;

    #if !defined(SHD_CLOUD_SHADOWS)
        
        /// Calculate the lighting of the clouds based on position of each corner
        GetPointDiffuse( Out.diffuse, position, spriteCenter.xyz );

        //Out.diffuse = float4( IsPuffDraw, facingBlend, 0, 1 );

        /// Apply cluster offset and scale factor
        position -= clusterOffset.xyz;

        float4 worldPos = mul( float4(position,1.0), matWorld );
        Out.mAlt = worldPos.y;

        Out.position = mul( float4(position,1.0), worldViewProj );

        // Calculate fade distance and alpha
        float fFadeDistance = Out.position.w;
        fFadeDistance = min(fFadeDistance, fCloudFadeDistance);
        fFadeDistance -= fCloudEndFadeDistance;

        float fOneOverRange = rcp( fCloudFadeDistance -  fCloudEndFadeDistance );
        float fAlphaFade = fFadeDistance * fOneOverRange;

        /// Apply fading at the far clip. This prevents clouds popping in/out at the far clip
        #if defined(SHD_FADE_AT_FAR_CLIP)
            fAlphaFade = FarClipAlphaFade(Out.position.w, fAlphaFade);
        #endif
        /// Apply a distance fade relative to the camera
        Out.diffuse.w *= fAlphaFade;

        /// Apply fade when sprite is behind the near clip
        ////if( Out.position.w < cb_NearClip && Out.position.w > fCloudEndFadeDistance )
        ////{
        ////    Out.position.z = 0;
        ////    Out.position.w = cb_NearClip;
        ////}
        bool bOverrideZ = (Out.position.w < cb_NearClip);
        bOverrideZ = bOverrideZ && (Out.position.w > fCloudEndFadeDistance);

        Out.position.z *= !bOverrideZ;

        float fUseNear = cb_NearClip * bOverrideZ;
        Out.position.w = Out.position.w * !bOverrideZ + fUseNear;
        Out.cornerDots = 1 - abs( dot( normalize( worldPos.xyz ), cb_mInverseView[ 2 ].xyz ));
    }

        // Compute fog
        float3 vSpriteCenter = spriteCenter.xyz - clusterOffset.xyz;
        Out.fFogDistance.x = FogVS( float4(vSpriteCenter, 1) , matWorld, float4(cb_mEyePoint.xyz,1));
        Out.fFogDistance.y = facingBlend;
    #else
        position = -clusterOffset.xyz + position;
        Out.position = mul( float4(position,1.0), matWorld );
        
    }
    #endif

    return Out;
}

#if !defined(SHD_CLOUD_SHADOWS)
[maxvertexcount(4)]
void GS(point VS_OUTPUT input[1], inout TriangleStream<GS_OUTPUT> SpriteStream)
#else
[instance(SHD_GS_INSTANCE_COUNT)]
[maxvertexcount(4)]
void GS(point VS_OUTPUT input[1], inout TriangleStream<GS_OUTPUT> SpriteStream, uint InstanceID : SV_GSInstanceID)
#endif
{
    GS_OUTPUT output;
    
    output.BaseTextureIndex = input[0].BaseTextureIndex;
    float2 lowerleft = input[0].uv.xy;
    float2 upperright = input[0].uv.zw;
    #if !defined(SHD_CLOUD_SHADOWS)
        output.fFogDistance = input[0].fFogDistance;
        output.mAlt = input[0].mAlt.y;
        
        // Bottom left
        output.position = input[0].position[0];
        output.diffuse = input[0].diffuse[0];
        output.eyeDot = input[0].cornerDots[0];
        output.uv.x = lowerleft.x;
        output.uv.y = lowerleft.y;
        output.localUV.x = -1;
        output.localUV.y = 1;
        SpriteStream.Append(output);

        // Bottom right
        output.position = input[0].position[2];
        output.diffuse = input[0].diffuse[2];
        output.eyeDot = input[0].cornerDots[2];
        output.uv.x = lowerleft.x;
        output.uv.y = upperright.y;
        output.localUV.x = 1;
        output.localUV.y = 1;
        SpriteStream.Append(output);

        // Top Left
        output.position = input[0].position[1];
        output.diffuse = input[0].diffuse[1];
        output.eyeDot = input[0].cornerDots[1];
        output.uv.x = upperright.x;
        output.uv.y = lowerleft.y;
        output.localUV.x = -1;
        output.localUV.y = -1;
        SpriteStream.Append(output);

        // Top right
        output.position = input[0].position[3];
        output.diffuse = input[0].diffuse[3];
        output.eyeDot = input[0].cornerDots[3];
        output.uv.x = upperright.x;
        output.uv.y = upperright.y;
        output.localUV.x = 1;
        output.localUV.y = -1;
        SpriteStream.Append(output);

        SpriteStream.RestartStrip();
    #else
        output.RTIndex = InstanceID;

        // Bottom left
        output.position = mul(input[0].position[0], cb_mCloudViewProjection[instanceID]);
        output.z = output.position.z;                            // pass down real z to PS
        output.position.z *= saturate(output.position.z); // pancake just in case
        output.uv.x = lowerleft.x;
        output.uv.y = lowerleft.y;
        output.localUV.x = -1;
        output.localUV.y = 1;
        SpriteStream.Append(output);

        // Bottom right
        output.position = mul(input[0].position[2], cb_mCloudViewProjection[instanceID]);
        output.z = output.position.z;                            // pass down real z to PS
        output.position.z *= saturate(output.position.z); // pancake just in case
        output.uv.x = lowerleft.x;
        output.uv.y = upperright.y;
        output.localUV.x = 1;
        output.localUV.y = 1;
        SpriteStream.Append(output);

        // Top Left
        output.position = mul(input[0].position[1], cb_mCloudViewProjection[instanceID]);
        output.z = output.position.z;                            // pass down real z to PS
        output.position.z *= saturate(output.position.z); // pancake just in case
        output.uv.x = upperright.x;
        output.uv.y = lowerleft.y;
        output.localUV.x = -1;
        output.localUV.y = -1;
        SpriteStream.Append(output);

        // Top right
        output.position = mul(input[0].position[3], cb_mCloudViewProjection[instanceID]);
        output.z = output.position.z;                            // pass down real z to PS
        output.position.z *= saturate(output.position.z); // pancake just in case
        output.uv.x = upperright.x;
        output.uv.y = upperright.y;
        output.localUV.x = 1;
        output.localUV.y = -1;
        SpriteStream.Append(output);

        SpriteStream.RestartStrip();
    #endif
}

#if defined(SHD_CLOUD_SHADOWS)
    #if USE_VARIANCE_SHADOWS==1
    float2 PS(PS_INPUT In): SV_TARGET
    {    
        float2 depthValues = float2(0.0f,0.0f);

        float4 cColor = txBase.Sample( samWrap, float3(In.uv,In.BaseTextureIndex) );

        [branch]if (cColor.a < 0.5f)
        {
            discard;
        }

        depthValues.x = In.z;
        depthValues.y = depthValues.x * depthValues.x;

        return depthValues;
    }
    #else
    float2 PS(GS_OUTPUT In): SV_TARGET
    {
        float4 cColor = txBase.Sample( samWrap, float3(In.uv,In.BaseTextureIndex) );
        return float2(1.0f-cColor.a,In.z);
    }
    #endif
#else
float4 PS(PS_INPUT In): SV_TARGET
{    
    float4 cColor = In.diffuse * txBase.Sample( samWrap, float3(In.uv,In.BaseTextureIndex) );

#define VOLUMIZE
#ifdef VOLUMIZE
    if( In.fFogDistance.y > .001f )
    {
        float3 noise = 0;
        float noiseScale = saturate( 1 - ( In.localUV.x * In.localUV.x + In.localUV.y * In.localUV.y )) / 2.75;

        [unroll]for(int i =2; i<3; i++)
        {
            noise += dot( normalize( txNoise.Sample( samWrap, In.uv / i ).rgb ), float3( 0, 1, 0 )) * cb_mCloudDirectional.rgb / 8;
        }
        
        cColor.rgb = saturate( cColor.rgb +  ( In.fFogDistance.y * noise ) );
        //cColor.r = 0;
        cColor.a = max( saturate( In.fFogDistance.y * In.eyeDot * noiseScale ), cColor.a );
    }
#endif
    // Apply IR if active
    #if defined(SHD_IR_ACTIVE)
        cColor = ApplyIr(cColor);
        return FogIR(cColor, In.fFogDistance.x);
    #endif //SHD_IR_ACTIVE

    //Soft edges.
    #if defined(SHD_CLOUD_FADE_AT_Z)
    #endif

    //Compute fog contribution.
    #if defined(SHD_VOLUMETRIC_FOG)
        cColor = VolumetricFogPS( In.mAlt, cColor, In.fFogDistance.x / 2.0, cb_mFogDensity, cb_mFogColor.xyz, float3( 1, 1, 1 ));
    #else
        cColor = float4( FogPS( cColor.xyz, In.fFogDistance.x / 2.0, cb_mFogDensity, cb_mFogColor.xyz ), cColor.a );
    #endif //SHD_VOLUMETRIC_FOG
    DEBUG_MARK(cColor)
    return cColor;
}
#endif

Share this post


Link to post

great thanks after looking at it seems the same as mine but i will use it instead in case there might be something and i dont feel like to scan letter by letter LOL

 

I see they did use the 0.5 multiplier and one other value cough my eye from line 263.

        float blendDistance = max( spriteSize, 800 );  mine was 1500 (whatever that is...)

well anyways Thanks and i just use yours.

 

Andy

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...