You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
4.1 KiB
164 lines
4.1 KiB
using System;
|
|
using System.Runtime.InteropServices;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
|
|
namespace WW1.PlayStation
|
|
{
|
|
public static class PSSRPlugin
|
|
{
|
|
public static readonly uint MaxNumContexts = 4;
|
|
|
|
public enum Event
|
|
{
|
|
Create,
|
|
Dispatch,
|
|
Destroy,
|
|
Capture,
|
|
}
|
|
|
|
public static void IssuePluginEvent<T>(CommandBuffer cmd, Event pluginEvent, NativeData<T> data) where T : struct
|
|
{
|
|
cmd.IssuePluginEventAndData(GetRenderEventAndDataFunc(), (int)pluginEvent, data.GetPointer());
|
|
}
|
|
|
|
[DllImport(LibraryInfo.LibraryName)]
|
|
public static extern IntPtr GetRenderEventAndDataFunc();
|
|
|
|
[DllImport(LibraryInfo.LibraryName, EntryPoint = "PSSR_Init")]
|
|
public static extern int Init();
|
|
|
|
[DllImport(LibraryInfo.LibraryName, EntryPoint = "PSSR_Release")]
|
|
public static extern void Release();
|
|
|
|
[DllImport(LibraryInfo.LibraryName, EntryPoint = "PSSR_CreateContext")]
|
|
public static extern int CreateContext(ref InitParams initParams, out IntPtr outputColorTexturePtr);
|
|
|
|
[DllImport(LibraryInfo.LibraryName, EntryPoint = "PSSR_DestroyContext")]
|
|
public static extern void DestroyContext(uint contextIndex);
|
|
|
|
[DllImport(LibraryInfo.LibraryName, EntryPoint = "PSSR_Dispatch")]
|
|
public static extern void Dispatch(ref DispatchParams dispatchParams);
|
|
|
|
[DllImport(LibraryInfo.LibraryName, EntryPoint = "PSSR_RequestCapture")]
|
|
public static extern int RequestCapture(uint contextIndex, byte frameNum = 64);
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct InitParams
|
|
{
|
|
public uint contextIndex;
|
|
|
|
public uint displayWidth;
|
|
public uint displayHeight;
|
|
public uint maxRenderWidth;
|
|
public uint maxRenderHeight;
|
|
|
|
public uint autoKeepCopies;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct DispatchParams
|
|
{
|
|
public uint contextIndex;
|
|
|
|
public IntPtr color;
|
|
public IntPtr depth;
|
|
public IntPtr prevDepth;
|
|
public IntPtr motionVectors;
|
|
public IntPtr prevMotionVectors;
|
|
public IntPtr exposure;
|
|
public IntPtr reactiveMask;
|
|
public IntPtr outputColor;
|
|
|
|
public uint renderWidth;
|
|
public uint renderHeight;
|
|
|
|
public Vector2 jitter;
|
|
public Vector2 motionVectorScale;
|
|
|
|
public Matrix4x4 camProjectionNoJitter;
|
|
public Vector3 camForward;
|
|
public Vector3 camUp;
|
|
public Vector3 camRight;
|
|
public double camPositionX;
|
|
public double camPositionY;
|
|
public double camPositionZ;
|
|
public float camNear;
|
|
public float camFar;
|
|
public float preExposure;
|
|
public uint resetHistory;
|
|
public OptionFlags flags;
|
|
|
|
public void FromCamera(Camera cam)
|
|
{
|
|
camProjectionNoJitter = cam.nonJitteredProjectionMatrix;
|
|
camForward = cam.transform.forward;
|
|
camUp = cam.transform.up;
|
|
camRight = cam.transform.right;
|
|
camPositionX = cam.transform.position.x;
|
|
camPositionY = cam.transform.position.y;
|
|
camPositionZ = cam.transform.position.z;
|
|
camNear = cam.nearClipPlane;
|
|
camFar = cam.farClipPlane;
|
|
}
|
|
}
|
|
|
|
[Flags]
|
|
public enum OptionFlags: uint
|
|
{
|
|
None = 0u,
|
|
ViewSpaceDepth = 1u << 14,
|
|
ReverseDepth = 1u << 15,
|
|
AutoExposure = 1u << 16,
|
|
PassThrough = 1u << 31,
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct DestroyParams
|
|
{
|
|
public uint contextIndex;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct CaptureParams
|
|
{
|
|
public uint contextIndex;
|
|
|
|
public byte frameNum;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Helper class to deal with all the nasty business of converting managed struct data into a pointer to native memory for use with plugin events.
|
|
/// </summary>
|
|
public class NativeData<T> where T : struct
|
|
{
|
|
private T _value;
|
|
private IntPtr _nativeBuffer = IntPtr.Zero;
|
|
|
|
public ref T Value => ref _value;
|
|
|
|
public void Initialize()
|
|
{
|
|
if (_nativeBuffer != IntPtr.Zero)
|
|
return;
|
|
|
|
_nativeBuffer = Marshal.AllocHGlobal(Marshal.SizeOf<T>());
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
if (_nativeBuffer == IntPtr.Zero)
|
|
return;
|
|
|
|
Marshal.FreeHGlobal(_nativeBuffer);
|
|
_nativeBuffer = IntPtr.Zero;
|
|
}
|
|
|
|
public IntPtr GetPointer()
|
|
{
|
|
Marshal.StructureToPtr(_value, _nativeBuffer, false);
|
|
return _nativeBuffer;
|
|
}
|
|
}
|
|
}
|
|
}
|