Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cbuffer cb0 : register (b0)
- {
- float4 cb0_v0;
- float4 cb0_v1;
- }
- cbuffer cb3 : register (b3)
- {
- float4 cb3_v0;
- float4 cb3_v1;
- float4 cb3_v2;
- }
- Texture2D texture0 : register (t0);
- SamplerState sampler0 : register (s0);
- struct VS_OUTPUT
- {
- float4 PositionH : SV_Position;
- float2 Texcoords : Texcoord0;
- };
- static const float2 pointsAroundPixel[8] =
- {
- float2(1.0, 0.0),
- float2(-1.0, 0.0),
- float2(0.707, 0.707),
- float2(-0.707, -0.707),
- float2(0.0, 1.0),
- float2(0.0, -1.0),
- float2(-0.707, 0.707),
- float2(0.707, -0.707)
- };
- float4 DrunkPS( in VS_OUTPUT Input ) : SV_Target0
- {
- /* Inputs */
- float rotationAroundPixelRadius = cb3_v0.x;
- float drunkIntensity = cb3_v0.y;
- float2 texelSize = cb0_v1.zw;
- float2 centerPoint = cb3_v2.xy;
- float2 rotationSinCos = cb3_v1.xy;
- float rotationSpeed = 0.05;
- float2 rotationDirection = rotationSinCos.xy * rotationSpeed;
- float2 pixelPosition = Input.PositionH.xy * texelSize;
- float2 centerToPixel = pixelPosition - centerPoint;
- /* Rotation part */
- float distanceFromCenterToPixel = length(centerToPixel);
- float intensityMask = dot(centerToPixel, centerToPixel);
- intensityMask *= 10.0;
- intensityMask = min( intensityMask, 1.0 );
- intensityMask *= drunkIntensity;
- // Scale rotation direction (sin/cos pair) by distance from center
- float2 rotationOffsets = rotationDirection * distanceFromCenterToPixel;
- float zoomFactor = -0.1 * drunkIntensity + 1; // 1.0 - 0.1*drunkIntensity (clearer for me)
- /* Calculating base rotation texcoords: */
- /* Approach #1 (closest approximation to original shader in terms of assembly) */
- float2 baseTexcoords0 = zoomFactor*centerToPixel + rotationDirection * distanceFromCenterToPixel;;
- float2 baseTexcoords1 = zoomFactor*centerToPixel - rotationDirection * distanceFromCenterToPixel;;
- baseTexcoords0 += centerPoint;
- baseTexcoords1 += centerPoint;
- /* Approach #2 (less instructions and more understandable (lerp) */
- //float2 zoomedTexcoords = lerp( centerPoint, pixelPosition, zoomFactor );
- //float2 baseTexcoords0 = zoomedTexcoords + rotationOffsets;
- //float2 baseTexcoords1 = zoomedTexcoords - rotationOffsets;
- float rotationTexcoordsOffsetIntensity = intensityMask * rotationAroundPixelRadius.x;
- rotationTexcoordsOffsetIntensity *= 5.0;
- float2 rotationTexcoordsOffset = rotationTexcoordsOffsetIntensity * texelSize;
- // For opposite directions (difference by 180 degrees)
- float4 rotation0 = 0.0;
- float4 rotation1 = 0.0;
- int i=0;
- [unroll] for (i = 0; i < 8; i++)
- {
- rotation0 += texture0.Sample( sampler0, baseTexcoords0 + rotationTexcoordsOffset * pointsAroundPixel[i] );
- }
- rotation0 /= 16.0;
- [unroll] for (i = 0; i < 8; i++)
- {
- rotation1 += texture0.Sample( sampler0, baseTexcoords1 + rotationTexcoordsOffset * pointsAroundPixel[i] );
- }
- rotation1 /= 16.0;
- float4 rotationPart = rotation0 + rotation1;
- /* Zooming in/out part */
- float zoomInOutScalePixels = drunkIntensity * 8.0;
- float2 zoomInOutScaleNormalizedScreenCoordinates = texelSize.xy * zoomInOutScalePixels;
- float zoomInOutAmplitude = 1.0 + 0.02 * rotationSinCos.y;
- float2 zoomInOutfromCenterToTexel = zoomInOutAmplitude * centerToPixel;
- float2 zoomInOutBaseTextureUV = lerp(centerPoint, pixelPosition, zoomInOutAmplitude);
- float2 zoomInOutAddTextureUV0 = zoomInOutBaseTextureUV + zoomInOutfromCenterToTexel * zoomInOutScaleNormalizedScreenCoordinates;
- float2 zoomInOutAddTextureUV1 = zoomInOutBaseTextureUV + 2.0 * zoomInOutfromCenterToTexel * zoomInOutScaleNormalizedScreenCoordinates;
- float4 zoomColor0 = texture0.Sample( sampler0, zoomInOutBaseTextureUV );
- float4 zoomColor1 = texture0.Sample( sampler0, zoomInOutAddTextureUV0 );
- float4 zoomColor2 = texture0.Sample( sampler0, zoomInOutAddTextureUV1 );
- float4 zoomingPart = ( zoomColor0 + zoomColor1 + zoomColor2 ) / 3.0;
- /* Combine rotation & zooming */
- /* Approach 1 (closest approximation to assembly from original shader) */
- float4 finalColor = intensityMask * (rotationPart - zoomingPart);
- finalColor = drunkIntensity * finalColor + zoomingPart;
- /* Approach 2 (you can deduce it from #1 formula, makes more sense for me */
- //finalColor = lerp(zoomingPart, rotationPart, intensityMask * drunkIntensity);
- return finalColor;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement