Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
- //// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- //// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- //// PARTICULAR PURPOSE.
- ////
- //// Copyright (c) Microsoft Corporation. All rights reserved
- #include <WRL.h>
- #include <math.h>
- #include <InitGuid.h>
- #include <d2d1_1.h>
- #include <d2d1effectauthor.h>
- #include <d2d1effecthelpers.h>
- #include <d2d1effects.h>
- #include "BasicReaderWriter.h"
- DEFINE_GUID(GUID_RipplePixelShader, 0x6716FB29, 0x06A0, 0x460F, 0xAA, 0x9C, 0x8B, 0x8F, 0xF0, 0x33, 0x5E, 0xA6);
- DEFINE_GUID(CLSID_CustomRippleEffect, 0xB7B36C92, 0x3498, 0x4A94, 0x9E, 0x95, 0x9F, 0x24, 0x6F, 0x92, 0x45, 0xBF);
- typedef enum RIPPLE_PROP
- {
- RIPPLE_PROP_FREQUENCY = 0,
- RIPPLE_PROP_PHASE = 1,
- RIPPLE_PROP_AMPLITUDE = 2,
- RIPPLE_PROP_SPREAD = 3,
- RIPPLE_PROP_CENTER = 4
- };
- // Our effect contains one transform, which is simply a wrapper around a pixel shader. As such,
- // we can simply make the effect itself act as the transform.
- class Ripple : public ID2D1EffectImpl, public ID2D1DrawTransform
- {
- public:
- // Declare effect registration methods.
- static HRESULT Register(_In_ ID2D1Factory1* pFactory);
- static HRESULT __stdcall CreateRippleImpl(_Outptr_ IUnknown** effectImpl);
- // Declare property getter/setter methods.
- HRESULT SetCenter(D2D1_POINT_2F center);
- D2D1_POINT_2F GetCenter() const;
- HRESULT SetFrequency(float frequency);
- float GetFrequency() const;
- HRESULT SetPhase(float phase);
- float GetPhase() const;
- HRESULT SetAmplitude(float amplitude);
- float GetAmplitude() const;
- HRESULT SetSpread(float spread);
- float GetSpread() const;
- // Declare ID2D1EffectImpl implementation methods.
- HRESULT __stdcall Initialize(
- _In_ ID2D1EffectContext* contextInternal,
- _In_ ID2D1TransformGraph* transformGraph
- );
- HRESULT __stdcall PrepareForRender(D2D1_CHANGE_TYPE changeType);
- HRESULT __stdcall SetGraph(_In_ ID2D1TransformGraph* graph);
- // Declare ID2D1DrawTransform implementation methods.
- HRESULT __stdcall SetDrawInfo(_In_ ID2D1DrawInfo* renderInfo);
- // Declare ID2D1Transform implementation methods.
- HRESULT __stdcall SetInputRects(
- _In_reads_(inputRectsCount) const D2D1_RECT_L* inputRects,
- UINT inputRectsCount
- );
- HRESULT __stdcall MapOutputRectToInputRects(
- _In_ const D2D1_RECT_L *outputRect,
- _Out_writes_(cTransformInputs) D2D1_RECT_L* inputRects,
- UINT32 transformInputs
- ) const;
- HRESULT __stdcall MapInputRectsToOutputRect(
- _In_reads_(inputRectsCount) const D2D1_RECT_L* inputRects,
- UINT inputRectsCount,
- _Out_ D2D1_RECT_L* outputRect
- ) const;
- // Declare ID2D1TransformNode implementation methods.
- UINT32 __stdcall GetInputCount() const;
- // Declare IUnknown implementation methods.
- ULONG __stdcall AddRef();
- ULONG __stdcall Release();
- HRESULT __stdcall QueryInterface(_In_ REFIID riid, _Outptr_ void** output);
- private:
- Ripple();
- void UpdateConstants();
- inline static float Clamp(float v, float low, float high)
- {
- return (v < low) ? low : (v > high) ? high : v;
- }
- inline static float Round(float v)
- {
- return floor(v + 0.5f);
- }
- // This struct defines the constant buffer of our pixel shader.
- struct
- {
- float frequency;
- float phase;
- float amplitude;
- float spread;
- D2D1_POINT_2F center;
- } m_constants;
- Microsoft::WRL::ComPtr<ID2D1DrawInfo> m_drawInfo;
- LONG m_refCount;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement