mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-02-08 05:30:59 -05:00
* DDGI stub with rasterized path * Debug probes and fix stuff * Simplify all of this, add system later * Iterate, start integrate * Integrate depth, allow copying depth to another format * Iterate, fix depth, send ddgi volume data to gpu, start integrating on lighting compositing, almost there * DDGIVolume gets bake button, doesnt bake automatically, correct transformation * DDGI Visibility Tests wip * DDGI Volumetric Fog https://files.facepunch.com/sampavlovic/1b2911b1/sbox-dev_UCziuQjdTQ.mp4 * Fix ddgi depth integration, iterate * Simplify this and correct octahedral coordinates seams * Iterate * Probe is 8x8, do normalization directly, cleanup * Bias probe position, visibility adjustments, make eveyrthing smoother * Unify integration in SampleProbeData, still need to clean it further * Unify integrate passes * Add view bias and use border as per papers, fixes most distortion when using visibility at the same time https://files.facepunch.com/sampavlovic/1b0411b1/sbox-dev_laDCpwFxk5.png * Cleanup and fixes for border, cleanup sampling code too * Proper compositing for DDGI for maps that have baked lighting already, could still have more thought to avoid uncessesary branching * DDGI System, allow for multiple volumes in scene, cleanup https://files.facepunch.com/sampavlovic/1b0711b1/sbox-dev_xcJUeit2s4.png https://files.facepunch.com/sampavlovic/1b0711b1/sbox-dev_c59O7Bea6p.png * Rebase fixes, the way to do this sucks * Caching tests, Texture.GetPixels3D seems a bit messed * ddgi.texturecache texturegenerator, much simpler, caches texture nicely and doesnt lead residues on ram after uploaded * Add LPVDebugGrid on managed, make DDGIVolume use it, dont save cache texture on disable, works way faster than gizmos * Update volume only if it's enabled * DDGI on AmbientLight.hlsl * Simplify and fixes * ExtendToSceneBounds, rebake envmaps when bake finished, normalbias * RENDER_DEFAULT_STATE_RASTERIZER probably shouldnt remove override of rasterizer state * Cleanup * [Pick] Fix TextureCompiler not compiling 3D textures properly, make Texture.GetBitmap work with 3D textures * Add NoPrepassCulling, avoids "rays" from probes that are inside geometry from leaking light https://files.facepunch.com/sampavlovic/1b1611b1/sbox-dev_bQfsZlWwop.png * Final adjustments and cleanupj, name this Indirect Light Volume * Indirect Light Volume prefab * Remove log infos, adjust sliders * Whoops * format * Rebase fix * Re-apply the currently tracked cull mode so the override state binds immediately, makes sure that SetLayerNoCull works as intended * Enqueue probes that affect geometry first, this gives quicker iteration results https://files.facepunch.com/sampavlovic/1b1911b1/Screen_Recording_2026-01-19_at_16.16.36.mov * float16 guards for ddgi_integrate, avoid NaNs * Texture.Save supports volume textures * DDGIVolume saves using the super nice Texture.Save api instead of texutre generator * Do the same color punchy look thing we do for envmap probes in ddgi probes https://files.facepunch.com/sampavlovic/1b1911b1/ezgif-13a1dd53fc7688fe.gif * Don't save ddgi async, just do it directly * DDGI editor icon https://files.facepunch.com/sampavlovic/1b2011b1/F1I0KaZt5j.png * Shaders * Format * Add EditorSystem.Camera * Move texture creation to DDGIProbeUpdaterCubemapper, build probes in order from the camera, use async instead of an update * Dont multiply DDGI diffuse by AO, that's done on the shadingmodel, this gives accurate multibounce as well * Update probes sequentially again, makes sure results are consistent, if we do near camera again, should do it with same logic to keep probes that affect geometry first too * Move NoPrepassCulling to RenderToCubeTexture, can't figure out why behaviour is different between these but solves light leak issue * Fix overriding array not working for depth textures, make this clearer * Overriden rasterizer state actually overrides when doing SetCullMode * Rework border logic, should be seamless now * Experiment with shadow sharpness being soft, with borders being fine the variance shadow map stuff from DDGI paper looks correct https://files.facepunch.com/sampavlovic/1b2211b1/sbox-dev_UNTiRmJ7Fw.png * Make Depth Sharpness a Property instead * Delete copy_border shader, do everything within the same shader with groupshared memory, actually sample borders correctly, this reduces octahedral border aliasing to a minimum https://files.facepunch.com/sampavlovic/1b2311b1/sbox-dev_FqPPpRZ6MD.png https://files.facepunch.com/sampavlovic/1b2311b1/Source2Viewer_TiqGxdYWwX.png * Distance calculations use unbiased probe-space position so when we move ddgi transform it doesnt fuck visibility up * Make DDGI Debug Grid use gizmo pooling so it follows gizmo visibility rules (hidden when gizmos disabled, not in cubemaps) * DDGI Relocation proto, Moves probes out of geometry to unfuck artifacts https://files.facepunch.com/sampavlovic/1b2311b1/ezgif-1afaed4e1c2ac9a5.gif https://files.facepunch.com/sampavlovic/1b2311b1/ezgif-11a3e64fd2952590.gif * DDGI less contrasty * Parallelize relocation * More resilient tracing tests & give option to deactivate if probe is fully inside of geometry instead of relocating those fully occluded * Simplify LPVDebugGrid, remove all the fucking mess from it * Simplify DDGIVolume, hide all the bullshit * VTexWriter allows to save as uncompressed, make Relocation texture uncompressed since we want alpha to be flags * Add Graphics.FlushGPU Forces the GPU to flush all pending commands and wait for completion. Useful when you need to ensure GPU work is finished before proceeding. Can be called outside of a render block. * DDGIVolume uses Graphics.FlushGPU instead of dumb Task.Await, density goes up to 10, Debug Grid updates if we change probes * Format * Doubt we are going to use flags, just store alpha as active state directly, makes it more resilient to eventual compression * Sprite was calculating offset incorrectly and causing ambient lighting to be fucked, fog was fucked too https://files.facepunch.com/sampavlovic/1b2611b1/sbox-dev_i3h4RcWncI.png * DDGI should really be under Light not Misc * Keep LPVDebugGrid render bounds infinite, SceneCusotmObject shouldnt change it from there * Move RelocationTexture to same Generated behaviour so we dont override the property it while we are rendering, make probes default visible * Remove shitty hack from scenecamera and make DDGIVolumeUpdater take scene renderattributes, makes DDGI bounces retrofeed from itself Should fix terrain rendering being fucked in DDGI too Will see to make this more generic https://files.facepunch.com/sampavlovic/1b2611b1/sbox-dev_uzXYN0Qzw6.png * Make Energy Loss an attribute for DDGI, I prefer a more contrasty look but there are scenes where you'd want more accurate energy conservation, first picture is an example where energy loss contrast makes it look worse https://files.facepunch.com/sampavlovic/1b2611b1/sbox-dev_kdTH1qhEwR.png https://files.facepunch.com/sampavlovic/1b2611b1/sbox-dev_gMoRxorzV0.png * Progress system can be toasts * Clean up progress system, always available now via Application.Editor. * Added Scene/Bake DDGI Volumes * Changed DDGIVolume to IndirectLightVolume * Refinement steps for probe relocation * Kill existing bake if disabled or ticking bake again * EnergyLoss is Contrast and increase max density, keep default contrast to the value I'm happy with * Don't call it the implementation name to the user * formet * Build shaders * Bind dummy DDGI_Volumes buffer as default on high level --------- Co-authored-by: Garry Newman <garrynewman@users.noreply.github.com>
188 lines
6.4 KiB
Modula-2
188 lines
6.4 KiB
Modula-2
|
|
#include "rendersystem/sheet.h"
|
|
|
|
native struct TextureCreationConfig_t is NativeEngine.TextureCreationConfig_t;
|
|
native struct CTextureDesc is NativeEngine.CTextureDesc;
|
|
native enum RenderDeviceAPI_t is NativeEngine.RenderDeviceAPI_t;
|
|
native pointer SwapChainHandle_t;
|
|
native pointer RenderBufferHandle_t is NativeEngine.RenderBufferHandle_t;
|
|
native pointer RenderInputLayout_t is NativeEngine.RenderInputLayout_t;
|
|
native struct BufferDesc_t is NativeEngine.BufferDesc;
|
|
native enum RenderBufferType_t is NativeEngine.RenderBufferType;
|
|
native enum RenderBufferFlags_t is NativeEngine.RenderBufferFlags;
|
|
native enum DeviceSpecificInfo_t is NativeEngine.DeviceSpecificInfo_t;
|
|
native struct VulkanDeviceSpecificTexture_t is NativeEngine.VulkanDeviceSpecificTexture_t;
|
|
native struct RenderDeviceInfo_t;
|
|
native pointer SamplerStateHandle_t;
|
|
native struct CSamplerStateDesc is NativeEngine.CSamplerStateDesc;
|
|
|
|
native accessor g_pRenderDevice
|
|
{
|
|
SamplerStateHandle_t FindOrCreateSamplerState(CSamplerStateDesc samplerDesc );
|
|
int GetSamplerIndex( SamplerStateHandle_t samplerState );
|
|
|
|
RenderDeviceInfo_t GetSwapChainInfo( SwapChainHandle_t swapChain );
|
|
ITexture FindOrCreateFileTexture( string pFileName, RenderSystemAssetFileLoadMode nLoadMode );
|
|
ITexture FindOrCreateTexture2( string pResourceName, bool bIsAnonymous, TextureCreationConfig_t pDescriptor, void* data, int dataSize );
|
|
void ClearTexture( ITexture hTexture, Color color );
|
|
void AsyncSetTextureData2( ITexture hTexture, void* pData, int nDataSize, Rect3D rect );
|
|
|
|
ITexture GetSwapChainTexture( SwapChainHandle_t swapChain, SwapChainBuffer bufferType );
|
|
bool GetGPUFrameTimeMS( SwapChainHandle_t swapChain, out float pGPUFrameTimeMSOut, out uint pFrameNumberOut );
|
|
|
|
asref cast CTextureDesc GetTextureDesc( ITexture hTexture );
|
|
asref cast CTextureDesc GetOnDiskTextureDesc( ITexture hTexture );
|
|
|
|
RenderMultisampleType GetTextureMultisampleType( ITexture hTexture );
|
|
|
|
IRenderContext CreateRenderContext( uint flags );
|
|
void ReleaseRenderContext( IRenderContext context );
|
|
|
|
bool ReadTexturePixels( ITexture hTexture, ref Rect_t pSrcRect, int nSrcSlice, int nSrcMip, ref Rect_t pDstRect, void* pData, ImageFormat dstFormat, int nDstStride );
|
|
|
|
void DestroySwapChain( SwapChainHandle_t hSwapChain );
|
|
|
|
bool Present( SwapChainHandle_t chain );
|
|
void Flush();
|
|
void ForceFlushGPU( SwapChainHandle_t hSwapChain );
|
|
bool CanRenderToSwapChain( SwapChainHandle_t chain );
|
|
|
|
bool IsUsing32BitDepthBuffer();
|
|
|
|
inline Vector2 GetBackbufferDimensions( SwapChainHandle_t chain )
|
|
{
|
|
int nBBWidth, nBBHeight;
|
|
g_pRenderDevice->GetBackBufferDimensions( chain, &nBBWidth, &nBBHeight );
|
|
return Vector2D( (float)nBBWidth, (float)nBBHeight );
|
|
}
|
|
|
|
RenderShaderHandle_t CompileAndCreateShader( RenderShaderType nType, string pProgram, uint nBufLen, string pShaderVersion, string pDebugName );
|
|
|
|
int GetTextureLastUsed( ITexture hTexture );
|
|
|
|
void UnThrottleTextureStreamingForNFrames( uint nNumberOfFramesForUnthrottledTextureLoading );
|
|
int GetNumTextureLoadsInFlight();
|
|
void SetForcePreloadStreamingData( bool bForcePreloadStreamingData );
|
|
|
|
RenderDeviceAPI_t GetRenderDeviceAPI();
|
|
|
|
void MarkTextureUsed( ITexture texture, int nRequiredMipSize );
|
|
|
|
bool IsTextureRenderTarget( ITexture texture );
|
|
|
|
bool IsRayTracingSupported();
|
|
|
|
inline RenderBufferHandle_t CreateGPUBuffer( RenderBufferType_t nType, BufferDesc_t desc, RenderBufferFlags_t usage, string pDebugName )
|
|
{
|
|
desc.m_pDebugName = pDebugName;
|
|
return g_pRenderDevice->CreateGPUBuffer( nType, desc, usage );
|
|
}
|
|
|
|
void DestroyGPUBuffer( RenderBufferHandle_t hGPUBuffer );
|
|
bool ReadBuffer( RenderBufferHandle_t hBuffer, uint nOffsetInBytes, void* pBuf, uint nBytesToRead );
|
|
|
|
IntPtr GetDeviceSpecificInfo( DeviceSpecificInfo_t info );
|
|
IntPtr GetGraphicsAPISpecificTextureHandle( ITexture hTexture );
|
|
|
|
IntPtr GetDeviceSpecificTexture( ITexture hTexture );
|
|
|
|
int GetTextureViewIndex( ITexture hTexture, CastTo[RenderColorSpace_t] byte colorSpace, RenderTextureDimension_t dim );
|
|
|
|
inline void GetTextureResidencyInfo( CUtlVectorTexture pTextures, CUtlVectorString pNames )
|
|
{
|
|
TextureResidencyStats_t textureResidencyStats;
|
|
CUtlVector<TextureResidencyInfo_t> rawTextures;
|
|
|
|
g_pRenderDevice->GetTextureResidencyInfo( rawTextures, textureResidencyStats );
|
|
|
|
pTextures->EnsureCapacity( rawTextures.Count() );
|
|
pNames->EnsureCapacity( rawTextures.Count() );
|
|
|
|
for ( const TextureResidencyInfo_t &info : rawTextures )
|
|
{
|
|
if ( info.m_hTexture.IsLoaded() == false ) continue;
|
|
|
|
CPathBufferString texName;
|
|
info.m_hTexture.GetResourceName( &texName );
|
|
|
|
pTextures->AddToTail( info.m_hTexture );
|
|
pNames->AddToTail( texName );
|
|
}
|
|
}
|
|
|
|
inline Vector4 GetSheetInfo( ITexture texture )
|
|
{
|
|
Vector4D vec(0, 0, 0, 0 );
|
|
|
|
Vector2D vSheetSequenceDataUVCoords;
|
|
HRenderTexture hSequenceDataTexture;
|
|
int nSequenceCount;
|
|
if ( g_pRenderDevice->GetSheetSequenceTextureData( texture, &hSequenceDataTexture, &vSheetSequenceDataUVCoords, &nSequenceCount ) )
|
|
{
|
|
vec[0] = vSheetSequenceDataUVCoords.y;
|
|
const CTextureDesc *pTexHeader = g_pRenderDevice->GetTextureDesc( hSequenceDataTexture );
|
|
if ( pTexHeader )
|
|
{
|
|
vec[1] = pTexHeader->m_nWidth;
|
|
vec[2] = 1.0f / pTexHeader->m_nHeight;
|
|
vec[3] = (float)nSequenceCount;
|
|
}
|
|
}
|
|
|
|
return vec;
|
|
}
|
|
|
|
inline int GetSequenceCount( ITexture texture )
|
|
{
|
|
const Sheet_t *pSheet = g_pRenderDevice->GetTextureSheet( texture );
|
|
if ( pSheet == nullptr ) return 0;
|
|
return pSheet->m_Sequences.Count();
|
|
}
|
|
|
|
inline SheetSequence_t GetSequence( ITexture texture, int index )
|
|
{
|
|
const Sheet_t *pSheet = g_pRenderDevice->GetTextureSheet( texture );
|
|
if ( pSheet == nullptr ) return 0;
|
|
return &pSheet->m_Sequences[index];
|
|
}
|
|
}
|
|
|
|
native static class ImageLoader as NativeEngine.ImageLoader
|
|
{
|
|
int GetMemRequired( int width, int height, int depth, ImageFormat imageFormat, bool mipmap );
|
|
int GetMemRequired( int width, int height, int depth, int mipmaps, ImageFormat imageFormat );
|
|
|
|
bool ConvertImageFormat( CastTo[uint8*] void* src, ImageFormat srcImageFormat, CastTo[uint8*] void* dst, ImageFormat dstImageFormat, int width, int height, int srcStride, int dstStride );
|
|
}
|
|
|
|
native class SheetSequence_t
|
|
{
|
|
uint m_nId;
|
|
bool m_bClamp;
|
|
bool m_bAlphaCrop;
|
|
bool m_bNoColor;
|
|
bool m_bNoAlpha;
|
|
float m_flTotalTime;
|
|
|
|
inline int FrameCount()
|
|
{
|
|
return self->m_Frames.Count();
|
|
}
|
|
}
|
|
|
|
native class SheetSequenceFrame_t
|
|
{
|
|
float m_flDisplayTime;
|
|
|
|
inline int ImageCount()
|
|
{
|
|
return self->m_Images.Count();
|
|
}
|
|
|
|
inline SheetFrameImage_t GetImage( int i )
|
|
{
|
|
return self->m_Images[i];
|
|
}
|
|
}
|
|
|
|
native struct SheetFrameImage_t; |