tgjones / HlslTools

A Visual Studio extension that provides enhanced support for editing High Level Shading Language (HLSL) files
http://timjones.io/blog/archive/2016/04/25/hlsl-tools-for-visual-studio-v1.0-released
Other
553 stars 95 forks source link

preprocessor #if folding is incorrect #250

Open Andrej730 opened 1 year ago

Andrej730 commented 1 year ago

For the code below I was expecting folding #if 1 to fold the entire thing or for #else to fold the second half but what it does it folds the part of the code until next #if statement. It's a real pain to work with.

https://github.com/tgjones/HlslTools/assets/9417531/c557b7b7-2ede-4244-ad09-6800c5b38c43

#if 1 // shadow sample distribution
                    // Non-linear shadow sample distribution, hardcoded to x^2
                    float PreviousNormT = 0.0f;
                    for (float ShadowT = InvShadowStepCount; ShadowT <= 1.00001f; ShadowT += InvShadowStepCount)
                    {
                        DebugGroundShadowMaterialSampleCount++;
                        float CurrentNormT = ShadowT * ShadowT; // CurrentNormT is the end of the considered segment to integrate, PreviousNormT is its beginning.
                        const float DetlaNormT = CurrentNormT - PreviousNormT;
                        const float ShadowSampleDistance = ShadowLengthTest * (CurrentNormT - 0.5 * DetlaNormT);
                        UpdateMaterialCloudParam(MaterialParameters, LWCAdd(SampleWorldPosition, LWCPromote(float3(0.0f, 0.0f, -1.0f) * ShadowSampleDistance)),
                            ResolvedView, CloudLayerParams, ShadowSampleDistance);
                        PreviousNormT = CurrentNormT;
#if MATERIAL_VOLUMETRIC_ADVANCED_CONSERVATIVE_DENSITY
                        if (MaterialParameters.VolumeSampleConservativeDensity.x <= 0.0f)
                        {
                            continue; // Conservative density is 0 so skip and go to the next sample
                        }
#endif
                        CalcPixelMaterialInputs(MaterialParameters, PixelMaterialInputs);
                        OpticalDepth += SampleExtinctionCoefficients(PixelMaterialInputs) * ShadowLengthTest * CENTIMETER_TO_METER * DetlaNormT;
                    }
#else // shadow sample distribution
                    // Linear shadow sample distribution.
                    const float ShadowDtMeter = ShadowLengthTest * CENTIMETER_TO_METER / ShadowStepCount;
                    const float ShadowJitteringSeed = float(ResolvedView.StateFrameIndexMod8) + PseudoRandom(SvPosition.xy) + i * 17;
                    const float ShadowJitterNorm = InterleavedGradientNoise(SvPosition.xy, ShadowJitteringSeed) - 0.5f;
                    for (float ShadowT = 0.5; ShadowT < ShadowStepCount; ShadowT += 1.0f)
                    {
                        const float ShadowSampleDistance = ShadowLengthTest * (ShadowT * InvShadowStepCount);
                        UpdateMaterialCloudParam(MaterialParameters, LWCAdd(SampleWorldPosition, LWCPromote(float3(0.0f, 0.0f, -1.0f) * ShadowSampleDistance)),
                            ResolvedView, CloudLayerParams, ShadowSampleDistance);
#if MATERIAL_VOLUMETRIC_ADVANCED_CONSERVATIVE_DENSITY
                        if (MaterialParameters.VolumeSampleConservativeDensity.x <= 0.0f)
                        {
                            continue; // Conservative density is 0 so skip and go to the next sample
                        }
#endif // MATERIAL_VOLUMETRIC_ADVANCED_CONSERVATIVE_DENSITY
                        CalcPixelMaterialInputs(MaterialParameters, PixelMaterialInputs);
                        OpticalDepth += SampleExtinctionCoefficients(PixelMaterialInputs) * ShadowDtMeter;
                    }
#endif // shadow sample distribution