tgjones/HlslTools

preprocessor #if folding is incorrect

Opened this issue · 0 comments

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.

Code_-_Insiders_w9FPANr0ph.mp4
#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