Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Add tooltips with the full name of the (graphics) compositor properties to properly show large names that otherwise are clipped by the UI (case 1263590)
- Composition profile .asset files cannot be manually edited/reset by users (to avoid breaking things - case 1265631)
- Preparation pass for RTSSShadows to be supported by render graph.
- Optimized Grain and sRGB Dithering.

## [10.0.0] - 2019-06-10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3916,17 +3916,24 @@ static void DoFinalPass( in FinalPassParameters parameters,
if (parameters.filmGrainTexture != null) // Fail safe if the resources asset breaks :/
{
#if HDRP_DEBUG_STATIC_POSTFX
int offsetX = 0;
int offsetY = 0;
float offsetX = 0;
float offsetY = 0;
#else
int offsetX = (int)(parameters.random.NextDouble() * parameters.filmGrainTexture.width);
int offsetY = (int)(parameters.random.NextDouble() * parameters.filmGrainTexture.height);
float offsetX = (float)(parameters.random.NextDouble());
float offsetY = (float)(parameters.random.NextDouble());
#endif

finalPassMaterial.EnableKeyword("GRAIN");
finalPassMaterial.SetTexture(HDShaderIDs._GrainTexture, parameters.filmGrainTexture);
finalPassMaterial.SetVector(HDShaderIDs._GrainParams, new Vector2(parameters.filmGrainIntensity * 4f, parameters.filmGrainResponse));
finalPassMaterial.SetVector(HDShaderIDs._GrainTextureParams, new Vector4(parameters.filmGrainTexture.width, parameters.filmGrainTexture.height, offsetX, offsetY));

float uvScaleX = parameters.hdCamera.actualWidth / (float)parameters.filmGrainTexture.width;
float uvScaleY = parameters.hdCamera.actualHeight / (float)parameters.filmGrainTexture.height;
float scaledOffsetX = offsetX * uvScaleX;
float scaledOffsetY = offsetY * uvScaleY;

finalPassMaterial.SetVector(HDShaderIDs._GrainTextureParams, new Vector4(uvScaleX, uvScaleY, offsetX, offsetY));

}
}

Expand All @@ -3942,7 +3949,8 @@ static void DoFinalPass( in FinalPassParameters parameters,

finalPassMaterial.EnableKeyword("DITHER");
finalPassMaterial.SetTexture(HDShaderIDs._BlueNoiseTexture, blueNoiseTexture);
finalPassMaterial.SetVector(HDShaderIDs._DitherParams, new Vector3(blueNoiseTexture.width, blueNoiseTexture.height, textureId));
finalPassMaterial.SetVector(HDShaderIDs._DitherParams, new Vector3(parameters.hdCamera.actualWidth / blueNoiseTexture.width,
parameters.hdCamera.actualHeight / blueNoiseTexture.height, textureId));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Shader "Hidden/HDRP/FinalPass"
SAMPLER(sampler_LinearRepeat);

float2 _GrainParams; // x: intensity, y: response
float4 _GrainTextureParams; // x: width, y: height, zw: random offset
float3 _DitherParams; // x: width, y: height, z: texture_id
float4 _GrainTextureParams; // xy: _ScreenSize.xy / GrainTextureSize.xy, zw: (random offset in UVs) * _GrainTextureParams.xy
float3 _DitherParams; // xy: _ScreenSize.xy / DitherTextureSize.xy, z: texture_id
float4 _UVTransform;
float _KeepAlpha;

Expand Down Expand Up @@ -114,8 +114,7 @@ Shader "Hidden/HDRP/FinalPass"
#if GRAIN
{
// Grain in range [0;1] with neutral at 0.5
uint2 icoords = fmod(positionSS + _GrainTextureParams.zw, _GrainTextureParams.xy);
float grain = LOAD_TEXTURE2D(_GrainTexture, icoords).w;
float grain = SAMPLE_TEXTURE2D(_GrainTexture, s_linear_repeat_sampler, (positionNDC * _GrainTextureParams.xy) + _GrainTextureParams.zw).w;

// Remap [-1;1]
grain = (grain - 0.5) * 2.0;
Expand All @@ -132,14 +131,14 @@ Shader "Hidden/HDRP/FinalPass"
// sRGB 8-bit dithering
{
float3 ditherParams = _DitherParams;
uint2 icoords = fmod(positionSS, ditherParams.xy);

// Symmetric triangular distribution on [-1,1] with maximal density at 0
float noise = LOAD_TEXTURE2D_ARRAY(_BlueNoiseTexture, icoords, ditherParams.z).a * 2.0 - 1.0;
float noise = SAMPLE_TEXTURE2D_ARRAY(_BlueNoiseTexture, s_linear_repeat_sampler, positionNDC * ditherParams.xy, ditherParams.z).a;
float3 sRGBColor = LinearToSRGB(outColor.xyz);
noise = noise * 2.0 - 1.0;
noise = FastSign(noise) * (1.0 - sqrt(1.0 - abs(noise)));

//outColor += noise / 255.0;
outColor.xyz = SRGBToLinear(LinearToSRGB(outColor.xyz) + noise / 255.0);
outColor.xyz = SRGBToLinear(sRGBColor + noise / 255.0);
}
#endif

Expand Down