From abe580071480e1d2dc38b11a3a2c3870611c42c5 Mon Sep 17 00:00:00 2001 From: Nealsbo Date: Tue, 10 May 2022 02:19:09 +0300 Subject: [PATCH 1/9] Add new renderer folders based, opengl backend and r1 frontend --- .../xrRenderGLR1/Blender_Recorder_GL.cpp | 87 ++ src/Layers/xrRenderGLR1/CommonTypes.h | 66 ++ src/Layers/xrRenderGLR1/glBufferUtils.cpp | 587 ++++++++++ .../xrRenderGLR1/glDetailManager_VS.cpp | 227 ++++ src/Layers/xrRenderGLR1/glHW.cpp | 293 +++++ src/Layers/xrRenderGLR1/glHW.h | 69 ++ src/Layers/xrRenderGLR1/glHWCaps.cpp | 71 ++ src/Layers/xrRenderGLR1/glR_Backend_Runtime.h | 457 ++++++++ .../glResourceManager_Resources.cpp | 212 ++++ .../glResourceManager_Scripting.cpp | 554 +++++++++ src/Layers/xrRenderGLR1/glSH_RT.cpp | 121 ++ src/Layers/xrRenderGLR1/glSH_Texture.cpp | 362 ++++++ src/Layers/xrRenderGLR1/glState.cpp | 274 +++++ src/Layers/xrRenderGLR1/glState.h | 52 + src/Layers/xrRenderGLR1/glStateUtils.cpp | 205 ++++ src/Layers/xrRenderGLR1/glStateUtils.h | 17 + src/Layers/xrRenderGLR1/glTextureUtils.cpp | 112 ++ src/Layers/xrRenderGLR1/glTextureUtils.h | 10 + src/Layers/xrRenderGLR1/glr_constants_cache.h | 175 +++ src/Layers/xrRenderPC_GLR1/CMakeLists.txt | 361 ++++++ src/Layers/xrRenderPC_GLR1/FStaticRender.cpp | 805 +++++++++++++ src/Layers/xrRenderPC_GLR1/FStaticRender.h | 269 +++++ .../FStaticRender_Blenders.cpp | 47 + .../xrRenderPC_GLR1/FStaticRender_Loader.cpp | 447 ++++++++ .../FStaticRender_RenderTarget.cpp | 414 +++++++ .../FStaticRender_RenderTarget.h | 107 ++ .../xrRenderPC_GLR1/FStaticRender_Shaders.cpp | 1005 +++++++++++++++++ .../xrRenderPC_GLR1/FStaticRender_Types.h | 20 + src/Layers/xrRenderPC_GLR1/GlowManager.cpp | 315 ++++++ src/Layers/xrRenderPC_GLR1/GlowManager.h | 78 ++ src/Layers/xrRenderPC_GLR1/LightPPA.cpp | 342 ++++++ src/Layers/xrRenderPC_GLR1/LightPPA.h | 51 + src/Layers/xrRenderPC_GLR1/LightProjector.cpp | 389 +++++++ src/Layers/xrRenderPC_GLR1/LightProjector.h | 65 ++ src/Layers/xrRenderPC_GLR1/LightShadows.cpp | 645 +++++++++++ src/Layers/xrRenderPC_GLR1/LightShadows.h | 91 ++ src/Layers/xrRenderPC_GLR1/glTexture.cpp | 244 ++++ src/Layers/xrRenderPC_GLR1/glr_constants.cpp | 173 +++ src/Layers/xrRenderPC_GLR1/rgl_test_hw.cpp | 65 ++ src/Layers/xrRenderPC_GLR1/stdafx.cpp | 8 + src/Layers/xrRenderPC_GLR1/stdafx.h | 66 ++ src/Layers/xrRenderPC_GLR1/xrRender_GLR1.cpp | 65 ++ .../xrRenderPC_GLR1/xrRender_GLR1.vcxproj | 375 ++++++ .../xrRender_GLR1.vcxproj.filters | 996 ++++++++++++++++ 44 files changed, 11394 insertions(+) create mode 100755 src/Layers/xrRenderGLR1/Blender_Recorder_GL.cpp create mode 100755 src/Layers/xrRenderGLR1/CommonTypes.h create mode 100755 src/Layers/xrRenderGLR1/glBufferUtils.cpp create mode 100755 src/Layers/xrRenderGLR1/glDetailManager_VS.cpp create mode 100755 src/Layers/xrRenderGLR1/glHW.cpp create mode 100755 src/Layers/xrRenderGLR1/glHW.h create mode 100755 src/Layers/xrRenderGLR1/glHWCaps.cpp create mode 100755 src/Layers/xrRenderGLR1/glR_Backend_Runtime.h create mode 100755 src/Layers/xrRenderGLR1/glResourceManager_Resources.cpp create mode 100755 src/Layers/xrRenderGLR1/glResourceManager_Scripting.cpp create mode 100755 src/Layers/xrRenderGLR1/glSH_RT.cpp create mode 100755 src/Layers/xrRenderGLR1/glSH_Texture.cpp create mode 100755 src/Layers/xrRenderGLR1/glState.cpp create mode 100755 src/Layers/xrRenderGLR1/glState.h create mode 100755 src/Layers/xrRenderGLR1/glStateUtils.cpp create mode 100755 src/Layers/xrRenderGLR1/glStateUtils.h create mode 100755 src/Layers/xrRenderGLR1/glTextureUtils.cpp create mode 100755 src/Layers/xrRenderGLR1/glTextureUtils.h create mode 100755 src/Layers/xrRenderGLR1/glr_constants_cache.h create mode 100755 src/Layers/xrRenderPC_GLR1/CMakeLists.txt create mode 100755 src/Layers/xrRenderPC_GLR1/FStaticRender.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/FStaticRender.h create mode 100755 src/Layers/xrRenderPC_GLR1/FStaticRender_Blenders.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/FStaticRender_Loader.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/FStaticRender_RenderTarget.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/FStaticRender_RenderTarget.h create mode 100755 src/Layers/xrRenderPC_GLR1/FStaticRender_Shaders.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/FStaticRender_Types.h create mode 100755 src/Layers/xrRenderPC_GLR1/GlowManager.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/GlowManager.h create mode 100755 src/Layers/xrRenderPC_GLR1/LightPPA.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/LightPPA.h create mode 100755 src/Layers/xrRenderPC_GLR1/LightProjector.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/LightProjector.h create mode 100755 src/Layers/xrRenderPC_GLR1/LightShadows.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/LightShadows.h create mode 100755 src/Layers/xrRenderPC_GLR1/glTexture.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/glr_constants.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/rgl_test_hw.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/stdafx.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/stdafx.h create mode 100755 src/Layers/xrRenderPC_GLR1/xrRender_GLR1.cpp create mode 100755 src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj create mode 100755 src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj.filters diff --git a/src/Layers/xrRenderGLR1/Blender_Recorder_GL.cpp b/src/Layers/xrRenderGLR1/Blender_Recorder_GL.cpp new file mode 100755 index 00000000000..b91f9b86f8e --- /dev/null +++ b/src/Layers/xrRenderGLR1/Blender_Recorder_GL.cpp @@ -0,0 +1,87 @@ +#include "stdafx.h" +#pragma hdrstop + +#include "Layers/xrRender/ResourceManager.h" +#include "Layers/xrRender/Blender_Recorder.h" +#include "Layers/xrRender/Blender.h" +#include "Layers/xrRender/tss.h" + +void fix_texture_name(pstr fn); + +void CBlender_Compile::r_Stencil(BOOL Enable, u32 Func, u32 Mask, u32 WriteMask, u32 Fail, u32 Pass, u32 ZFail) +{ + RS.SetRS(D3DRS_STENCILENABLE, BC(Enable)); + if (!Enable) return; + RS.SetRS(D3DRS_STENCILFUNC, Func); + RS.SetRS(D3DRS_STENCILMASK, Mask); + RS.SetRS(D3DRS_STENCILWRITEMASK, WriteMask); + RS.SetRS(D3DRS_STENCILFAIL, Fail); + RS.SetRS(D3DRS_STENCILPASS, Pass); + RS.SetRS(D3DRS_STENCILZFAIL, ZFail); +} + +void CBlender_Compile::r_StencilRef(u32 Ref) +{ + RS.SetRS(D3DRS_STENCILREF, Ref); +} + +void CBlender_Compile::r_CullMode(D3DCULL Mode) +{ + RS.SetRS(D3DRS_CULLMODE, (u32)Mode); +} + +void CBlender_Compile::i_Comparison(u32 s, u32 func) +{ + RS.SetSAMP(s, XRDX10SAMP_COMPARISONFILTER, TRUE); + RS.SetSAMP(s, XRDX10SAMP_COMPARISONFUNC, func); +} + +void CBlender_Compile::r_Sampler_cmp(LPCSTR name, LPCSTR texture, bool b_ps1x_ProjectiveDivide) +{ + u32 s = r_Sampler(name, texture, b_ps1x_ProjectiveDivide, D3DTADDRESS_CLAMP, D3DTEXF_LINEAR, D3DTEXF_NONE, + D3DTEXF_LINEAR); + if (u32(-1) != s) + { + RS.SetSAMP(s, XRDX10SAMP_COMPARISONFILTER, TRUE); + RS.SetSAMP(s, XRDX10SAMP_COMPARISONFUNC, (u32)D3D_COMPARISON_LESS_EQUAL); + } +} + +void CBlender_Compile::r_Pass(LPCSTR _vs, LPCSTR _gs, LPCSTR _ps, bool bFog, BOOL bZtest, BOOL bZwrite, BOOL bABlend, + D3DBLEND abSRC, D3DBLEND abDST, BOOL aTest, u32 aRef) +{ + R_ASSERT2(_ps, "Probably you are using wrong r_Pass"); + RS.Invalidate(); + ctable.clear(); + passTextures.clear(); + passMatrices.clear(); + passConstants.clear(); + dwStage = 0; + + // Setup FF-units (Z-buffer, blender) + PassSET_ZB(bZtest, bZwrite); + PassSET_Blend(bABlend, abSRC, abDST, aTest, aRef); + PassSET_LightFog(FALSE, bFog); + + // Create shaders + SPS* ps = RImplementation.Resources->_CreatePS(_ps); + SVS* vs = RImplementation.Resources->_CreateVS(_vs); + SGS* gs = RImplementation.Resources->_CreateGS(_gs); + dest.ps = ps; + dest.vs = vs; + dest.gs = gs; +#ifdef USE_DX11 + dest.hs = RImplementation.Resources->_CreateHS("null"); + dest.ds = RImplementation.Resources->_CreateDS("null"); +#endif + ctable.merge(&ps->constants); + ctable.merge(&vs->constants); + ctable.merge(&gs->constants); + + // Last Stage - disable + if (0 == xr_stricmp(_ps, "null")) + { + RS.SetTSS(0, D3DTSS_COLOROP, D3DTOP_DISABLE); + RS.SetTSS(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); + } +} diff --git a/src/Layers/xrRenderGLR1/CommonTypes.h b/src/Layers/xrRenderGLR1/CommonTypes.h new file mode 100755 index 00000000000..cea493f65a2 --- /dev/null +++ b/src/Layers/xrRenderGLR1/CommonTypes.h @@ -0,0 +1,66 @@ +#pragma once + +// TODO: Get rid of D3D types. +#if defined(XR_PLATFORM_WINDOWS) +#include +#endif + +class glState; + +typedef enum D3D_CLEAR_FLAG { + D3D_CLEAR_DEPTH = 0x1L, + D3D_CLEAR_STENCIL = 0x2L +} D3D_CLEAR_FLAG; + +typedef enum D3D_COMPARISON_FUNC { + D3D_COMPARISON_NEVER = GL_NEVER, + D3D_COMPARISON_LESS = GL_LESS, + D3D_COMPARISON_EQUAL = GL_EQUAL, + D3D_COMPARISON_LESS_EQUAL = GL_LEQUAL, + D3D_COMPARISON_GREATER = GL_GREATER, + D3D_COMPARISON_NOT_EQUAL = GL_NOTEQUAL, + D3D_COMPARISON_GREATER_EQUAL = GL_GEQUAL, + D3D_COMPARISON_ALWAYS = GL_ALWAYS +} D3D_COMPARISON_FUNC; + +struct XR_GL_VIEWPORT +{ + GLint TopLeftX, TopLeftY; + GLsizei Width, Height; + GLclampf MinDepth, MaxDepth; +}; + +struct D3D_VIEWPORT : XR_GL_VIEWPORT +{ + using XR_GL_VIEWPORT::XR_GL_VIEWPORT; + + // Needed to suppress warnings + template + D3D_VIEWPORT(TopLeftCoords x, TopLeftCoords y, Dimensions w, Dimensions h, float minZ, float maxZ) + : XR_GL_VIEWPORT{ + static_cast(x), static_cast(y), + static_cast(w), static_cast(h), + static_cast(minZ), static_cast(maxZ), + } + {} +}; + +using D3D_QUERY = enum XR_GL_QUERY +{ + D3D_QUERY_EVENT, + D3D_QUERY_OCCLUSION +}; + +using ID3DState = glState; + +#define DX10_ONLY(expr) do {} while (0) + +using unused_t = int[0]; + +using IndexBufferHandle = GLuint; +using VertexBufferHandle = GLuint; +using ConstantBufferHandle = GLuint; +using HostBufferHandle = void*; + +using VertexElement = D3DVERTEXELEMENT9; +using InputElementDesc = unused_t; diff --git a/src/Layers/xrRenderGLR1/glBufferUtils.cpp b/src/Layers/xrRenderGLR1/glBufferUtils.cpp new file mode 100755 index 00000000000..f5fc6e4412d --- /dev/null +++ b/src/Layers/xrRenderGLR1/glBufferUtils.cpp @@ -0,0 +1,587 @@ +#include "stdafx.h" +#include "Layers/xrRender/BufferUtils.h" + +enum +{ + LOCKFLAGS_FLUSH = GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_INVALIDATE_BUFFER_BIT, + LOCKFLAGS_APPEND = GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT, // TODO: Implement buffer object appending using glBufferSubData +}; + +static HRESULT CreateBuffer(GLuint* pBuffer, const void* pData, u32 dataSize, bool bDynamic, bool bIndexBuffer) +{ + const GLenum usage = bDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; + const GLenum target = bIndexBuffer ? GL_ELEMENT_ARRAY_BUFFER : GL_ARRAY_BUFFER; + + glGenBuffers(1, pBuffer); + glBindBuffer(target, *pBuffer); + CHK_GL(glBufferData(target, dataSize, pData, usage)); + return S_OK; +} + +static inline HRESULT CreateVertexBuffer(VertexBufferHandle* pBuffer, const void* pData, u32 dataSize, bool bDynamic) +{ + return CreateBuffer(pBuffer, pData, dataSize, bDynamic, false); +} + +static inline HRESULT CreateIndexBuffer(IndexBufferHandle* pBuffer, const void* pData, u32 dataSize, bool bDynamic) +{ + return CreateBuffer(static_cast(pBuffer), pData, dataSize, bDynamic, true); +} + +const GLsizei VertexSizeList[] = +{ + 1, // D3DDECLTYPE_FLOAT1 + 2, // D3DDECLTYPE_FLOAT2 + 3, // D3DDECLTYPE_FLOAT3 + 4, // D3DDECLTYPE_FLOAT4 + 4, // D3DDECLTYPE_D3DCOLOR + 4, // D3DDECLTYPE_UBYTE4 + 2, // D3DDECLTYPE_SHORT2 + 4, // D3DDECLTYPE_SHORT4 + 4, // D3DDECLTYPE_UBYTE4N + 2, // D3DDECLTYPE_SHORT2N + 4, // D3DDECLTYPE_SHORT4N + 2, // D3DDECLTYPE_USHORT2N + 4, // D3DDECLTYPE_USHORT4N + 1, // D3DDECLTYPE_UDEC3 + 1, // D3DDECLTYPE_DEC3N + 2, // D3DDECLTYPE_FLOAT16_2 + 4 // D3DDECLTYPE_FLOAT16_4 +}; + +const GLenum VertexTypeList[] = +{ + GL_FLOAT, // D3DDECLTYPE_FLOAT1 + GL_FLOAT, // D3DDECLTYPE_FLOAT2 + GL_FLOAT, // D3DDECLTYPE_FLOAT3 + GL_FLOAT, // D3DDECLTYPE_FLOAT4 + GL_UNSIGNED_BYTE, // D3DDECLTYPE_D3DCOLOR + GL_UNSIGNED_BYTE, // D3DDECLTYPE_UBYTE4 + GL_SHORT, // D3DDECLTYPE_SHORT2 + GL_SHORT, // D3DDECLTYPE_SHORT4 + GL_UNSIGNED_BYTE, // D3DDECLTYPE_UBYTE4N + GL_SHORT, // D3DDECLTYPE_SHORT2N + GL_SHORT, // D3DDECLTYPE_SHORT4N + GL_UNSIGNED_SHORT, // D3DDECLTYPE_USHORT2N + GL_UNSIGNED_SHORT, // D3DDECLTYPE_USHORT4N + GL_INT_2_10_10_10_REV, // D3DDECLTYPE_UDEC3 + GL_INT_2_10_10_10_REV, // D3DDECLTYPE_DEC3N + GL_HALF_FLOAT, // D3DDECLTYPE_FLOAT16_2 + GL_HALF_FLOAT // D3DDECLTYPE_FLOAT16_4 +}; + +const GLboolean VertexNormalizedList[] = +{ + GL_FALSE, // D3DDECLTYPE_FLOAT1 + GL_FALSE, // D3DDECLTYPE_FLOAT2 + GL_FALSE, // D3DDECLTYPE_FLOAT3 + GL_FALSE, // D3DDECLTYPE_FLOAT4 + GL_TRUE, // D3DDECLTYPE_D3DCOLOR + GL_FALSE, // D3DDECLTYPE_UBYTE4 + GL_FALSE, // D3DDECLTYPE_SHORT2 + GL_FALSE, // D3DDECLTYPE_SHORT4 + GL_TRUE, // D3DDECLTYPE_UBYTE4N + GL_TRUE, // D3DDECLTYPE_SHORT2N + GL_TRUE, // D3DDECLTYPE_SHORT4N + GL_TRUE, // D3DDECLTYPE_USHORT2N + GL_TRUE, // D3DDECLTYPE_USHORT4N + GL_FALSE, // D3DDECLTYPE_UDEC3 + GL_TRUE, // D3DDECLTYPE_DEC3N + GL_FALSE, // D3DDECLTYPE_FLOAT16_2 + GL_FALSE // D3DDECLTYPE_FLOAT16_4 +}; + +const GLsizei VertexTypeSizeList[] = +{ + sizeof(GLfloat), // D3DDECLTYPE_FLOAT1 + sizeof(GLfloat), // D3DDECLTYPE_FLOAT2 + sizeof(GLfloat), // D3DDECLTYPE_FLOAT3 + sizeof(GLfloat), // D3DDECLTYPE_FLOAT4 + sizeof(GLubyte), // D3DDECLTYPE_D3DCOLOR + sizeof(GLubyte), // D3DDECLTYPE_UBYTE4 + sizeof(GLshort), // D3DDECLTYPE_SHORT2 + sizeof(GLshort), // D3DDECLTYPE_SHORT4 + sizeof(GLubyte), // D3DDECLTYPE_UBYTE4N + sizeof(GLshort), // D3DDECLTYPE_SHORT2N + sizeof(GLshort), // D3DDECLTYPE_SHORT4N + sizeof(GLushort), // D3DDECLTYPE_USHORT2N + sizeof(GLushort), // D3DDECLTYPE_USHORT4N + sizeof(GLuint), // D3DDECLTYPE_UDEC3 + sizeof(GLint), // D3DDECLTYPE_DEC3N + sizeof(GLhalf), // D3DDECLTYPE_FLOAT16_2 + sizeof(GLhalf) // D3DDECLTYPE_FLOAT16_4 +}; + +const GLuint VertexUsageList[] = +{ + 3, // D3DDECLUSAGE_POSITION + ~0u, // D3DDECLUSAGE_BLENDWEIGHT + ~0u, // D3DDECLUSAGE_BLENDINDICES + 5, // D3DDECLUSAGE_NORMAL + ~0u, // D3DDECLUSAGE_PSIZE + 8, // D3DDECLUSAGE_TEXCOORD + 4, // D3DDECLUSAGE_TANGENT + 6, // D3DDECLUSAGE_BINORMAL + ~0u, // D3DDECLUSAGE_TESSFACTOR + ~0u, // D3DDECLUSAGE_POSITIONT + 0, // D3DDECLUSAGE_COLOR + 7, // D3DDECLUSAGE_FOG + ~0u, // D3DDECLUSAGE_DEPTH + ~0u, // D3DDECLUSAGE_SAMPLE +}; + +u32 GetDeclVertexSize(const VertexElement* decl, u32 Stream) +{ + GLsizei size = 0; + for (int i = 0; i < MAXD3DDECLLENGTH; ++i) + { + const D3DVERTEXELEMENT9& desc = decl[i]; + + if (desc.Stream == 0xFF) + break; + + size += VertexSizeList[desc.Type] * VertexTypeSizeList[desc.Type]; + } + return size; +} + +void ConvertVertexDeclaration(const VertexElement* dxdecl, SDeclaration* decl) +{ + RCache.set_Format(decl); + + // XXX: tamlin: use 'stride', or drop it. + GLsizei stride = GetDeclVertexSize(dxdecl, 0); + for (int i = 0; i < MAXD3DDECLLENGTH; ++i) + { + const D3DVERTEXELEMENT9& desc = dxdecl[i]; + + if (desc.Stream == 0xFF) + break; + + GLuint location = VertexUsageList[desc.Usage]; + GLint size = VertexSizeList[desc.Type]; + GLenum type = VertexTypeList[desc.Type]; + GLboolean normalized = VertexNormalizedList[desc.Type]; + + if (location < 0) + continue; // Unsupported + + location += desc.UsageIndex; + CHK_GL(glVertexAttribFormat(location, size, type, normalized, desc.Offset)); + CHK_GL(glVertexAttribBinding(location, desc.Stream)); + CHK_GL(glEnableVertexAttribArray(location)); + } +} + +u32 GetFVFVertexSize(u32 FVF) +{ + GLsizei offset = 0; + + // Position attribute + if (FVF & D3DFVF_XYZRHW) + offset += sizeof(Fvector4); + else if (FVF & D3DFVF_XYZ) + offset += sizeof(Fvector); + + // Diffuse color attribute + if (FVF & D3DFVF_DIFFUSE) + offset += sizeof(u32); + + // Specular color attribute + if (FVF & D3DFVF_SPECULAR) + offset += sizeof(u32); + + // Texture coordinates + for (u32 i = 0; i < (FVF & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT; i++) + { + u32 size = 2; + if (FVF & D3DFVF_TEXCOORDSIZE1(i)) + size = 1; + if (FVF & D3DFVF_TEXCOORDSIZE3(i)) + size = 3; + if (FVF & D3DFVF_TEXCOORDSIZE4(i)) + size = 4; + + offset += size * sizeof(float); + } + + return offset; +} + +void ConvertVertexDeclaration(u32 FVF, SDeclaration* decl) +{ + RCache.set_Format(decl); + + GLsizei stride = GetFVFVertexSize(FVF); + u32 offset = 0; + + // Position attribute + if (FVF & D3DFVF_XYZRHW) + { + GLuint attrib = VertexUsageList[D3DDECLUSAGE_POSITION]; + CHK_GL(glVertexAttribFormat(attrib, 4, GL_FLOAT, GL_FALSE, offset)); + CHK_GL(glVertexAttribBinding(attrib, 0)); + CHK_GL(glEnableVertexAttribArray(attrib)); + offset += sizeof(Fvector4); + } + else if (FVF & D3DFVF_XYZ) + { + GLuint attrib = VertexUsageList[D3DDECLUSAGE_POSITION]; + CHK_GL(glVertexAttribFormat(attrib, 3, GL_FLOAT, GL_FALSE, offset)); + CHK_GL(glVertexAttribBinding(attrib, 0)); + CHK_GL(glEnableVertexAttribArray(attrib)); + offset += sizeof(Fvector); + } + + // Diffuse color attribute + if (FVF & D3DFVF_DIFFUSE) + { + GLuint attrib = VertexUsageList[D3DDECLUSAGE_COLOR]; + CHK_GL(glVertexAttribFormat(attrib, 4, GL_UNSIGNED_BYTE, GL_TRUE, offset)); + CHK_GL(glVertexAttribBinding(attrib, 0)); + CHK_GL(glEnableVertexAttribArray(attrib)); + offset += sizeof(u32); + } + + // Specular color attribute + if (FVF & D3DFVF_SPECULAR) + { + GLuint attrib = VertexUsageList[D3DDECLUSAGE_COLOR] + 1; + CHK_GL(glVertexAttribFormat(attrib, 4, GL_UNSIGNED_BYTE, GL_TRUE, offset)); + CHK_GL(glVertexAttribBinding(attrib, 0)); + CHK_GL(glEnableVertexAttribArray(attrib)); + offset += sizeof(u32); + } + + // Texture coordinates + for (u32 i = 0; i < (FVF & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT; i++) + { + GLuint attrib = VertexUsageList[D3DDECLUSAGE_TEXCOORD] + i; + + u32 size = 2; + if (FVF & D3DFVF_TEXCOORDSIZE1(i)) + size = 1; + if (FVF & D3DFVF_TEXCOORDSIZE3(i)) + size = 3; + if (FVF & D3DFVF_TEXCOORDSIZE4(i)) + size = 4; + + CHK_GL(glVertexAttribFormat(attrib, size, GL_FLOAT, GL_FALSE, offset)); + CHK_GL(glVertexAttribBinding(attrib, 0)); + CHK_GL(glEnableVertexAttribArray(attrib)); + offset += size * sizeof(float); + } + + VERIFY(stride == offset); +} + +u32 GetDeclLength(const D3DVERTEXELEMENT9* decl) +{ + const D3DVERTEXELEMENT9* element; + + for (element = decl; element->Stream != 0xff; ++element); + + return element - decl; +} + +//----------------------------------------------------------------------------- +VertexStagingBuffer::VertexStagingBuffer() + : m_DeviceBuffer{ 0 } + , m_HostBuffer{ nullptr } +{ +} + +VertexStagingBuffer::~VertexStagingBuffer() +{ + Destroy(); +} + +void VertexStagingBuffer::Create(size_t size, bool allowReadBack /*= false*/) +{ + m_Size = size; + m_AllowReadBack = allowReadBack; + + m_HostBuffer = xr_alloc(size); + AddRef(); +} + +bool VertexStagingBuffer::IsValid() const +{ + return !!m_DeviceBuffer; +} + +void* VertexStagingBuffer::Map( + size_t offset /*= 0*/, + size_t size /*= 0*/, + bool read /*= false*/) +{ + VERIFY2(m_HostBuffer, "Buffer wasn't created or already discarded"); + VERIFY2(!read || m_AllowReadBack, "Can't read from write only buffer"); + VERIFY2((size + offset) <= m_Size, "Map region is too large"); + + return static_cast(m_HostBuffer) + offset; +} + +void VertexStagingBuffer::Unmap(bool doFlush /*= false*/) +{ + if (!doFlush) + { + /* Do nothing*/ + return; + } + + VERIFY2(!m_DeviceBuffer, "Attempting to upload buffer twice"); + VERIFY(m_HostBuffer && m_Size); + + // Upload data to the device + CreateVertexBuffer(&m_DeviceBuffer, m_HostBuffer, m_Size, false); + + if (!m_AllowReadBack) + { + // Cache buffer isn't required anymore. Free host memory + DiscardHostBuffer(); + } +} + +VertexBufferHandle VertexStagingBuffer::GetBufferHandle() const +{ + return m_DeviceBuffer; +} + +void VertexStagingBuffer::Destroy() +{ + DiscardHostBuffer(); + m_Size = 0; + + if (m_DeviceBuffer) + { + glDeleteBuffers(1, &m_DeviceBuffer); + m_DeviceBuffer = 0; + } +} + +void VertexStagingBuffer::DiscardHostBuffer() +{ + if (m_HostBuffer) + xr_free(m_HostBuffer); +} + +size_t VertexStagingBuffer::GetSystemMemoryUsage() const +{ + return m_HostBuffer ? m_Size : 0; +} + +size_t VertexStagingBuffer::GetVideoMemoryUsage() const +{ + if (!m_DeviceBuffer) + return 0; + + GLint bufferSize; + glBindBuffer(GL_ARRAY_BUFFER, m_DeviceBuffer); + CHK_GL(glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &bufferSize)); + return bufferSize; +} + +//----------------------------------------------------------------------------- +IndexStagingBuffer::IndexStagingBuffer() + : m_DeviceBuffer{ 0 } + , m_HostBuffer{ nullptr } +{ +} + +IndexStagingBuffer::~IndexStagingBuffer() +{ + Destroy(); +} + +void IndexStagingBuffer::Create(size_t size, bool allowReadBack /*= false*/, bool /*managed = true*/) +{ + m_Size = size; + m_AllowReadBack = allowReadBack; + + m_HostBuffer = xr_alloc(size); + AddRef(); +} + +bool IndexStagingBuffer::IsValid() const +{ + return !!m_DeviceBuffer; +} + +void* IndexStagingBuffer::Map( + size_t offset /*= 0*/, + size_t size /*= 0*/, + bool read /*= false*/) +{ + VERIFY2(m_HostBuffer, "Buffer wasn't created or already discarded"); + VERIFY2(!read || m_AllowReadBack, "Can't read from write only buffer"); + VERIFY2((size + offset) <= m_Size, "Map region is too large"); + + return static_cast(m_HostBuffer) + offset; +} + +void IndexStagingBuffer::Unmap(bool doFlush /*= false*/) +{ + if (!doFlush) + { + /* Do nothing*/ + return; + } + + VERIFY2(!m_DeviceBuffer, "Attempting to upload buffer twice"); + VERIFY(m_HostBuffer && m_Size); + + // Upload data to the device + CreateIndexBuffer(&m_DeviceBuffer, m_HostBuffer, m_Size, false); + + if (!m_AllowReadBack) + { + // Cache buffer isn't required anymore. Free host memory + DiscardHostBuffer(); + } +} + +IndexBufferHandle IndexStagingBuffer::GetBufferHandle() const +{ + return m_DeviceBuffer; +} + +void IndexStagingBuffer::Destroy() +{ + DiscardHostBuffer(); + m_Size = 0; + + if (m_DeviceBuffer) + { + glDeleteBuffers(1, &m_DeviceBuffer); + m_DeviceBuffer = 0; + } +} + +void IndexStagingBuffer::DiscardHostBuffer() +{ + if (m_HostBuffer) + xr_free(m_HostBuffer); +} + +size_t IndexStagingBuffer::GetSystemMemoryUsage() const +{ + return m_HostBuffer ? m_Size : 0; +} + +size_t IndexStagingBuffer::GetVideoMemoryUsage() const +{ + if (!m_DeviceBuffer) + return 0; + + GLint bufferSize; + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_DeviceBuffer); + CHK_GL(glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &bufferSize)); + return bufferSize; +} + +//----------------------------------------------------------------------------- +VertexStreamBuffer::VertexStreamBuffer() + : m_DeviceBuffer(0) +{ +} + +VertexStreamBuffer::~VertexStreamBuffer() +{ + Destroy(); +} + +void VertexStreamBuffer::Create(size_t size) +{ + CreateVertexBuffer(&m_DeviceBuffer, nullptr, size, true); + AddRef(); +} + +void VertexStreamBuffer::Destroy() +{ + if (m_DeviceBuffer == 0) + return; + + glDeleteBuffers(1, &m_DeviceBuffer); +} + +void* VertexStreamBuffer::Map(size_t offset, size_t size, bool flush /*= false*/) +{ + VERIFY(m_DeviceBuffer); + glBindBuffer(GL_ARRAY_BUFFER, m_DeviceBuffer); + + void *pData = nullptr; + const auto flags = flush ? LOCKFLAGS_FLUSH : LOCKFLAGS_APPEND; + CHK_GL(pData = (void*)glMapBufferRange( + GL_ARRAY_BUFFER, + offset, + size, + flags)); + + return pData; +} + +void VertexStreamBuffer::Unmap() +{ + VERIFY(m_DeviceBuffer); + glBindBuffer(GL_ARRAY_BUFFER, m_DeviceBuffer); + CHK_GL(glUnmapBuffer(GL_ARRAY_BUFFER)); +} + +bool VertexStreamBuffer::IsValid() const +{ + return !!m_DeviceBuffer; +} + +//----------------------------------------------------------------------------- +IndexStreamBuffer::IndexStreamBuffer() + : m_DeviceBuffer(0) +{ +} + +IndexStreamBuffer::~IndexStreamBuffer() +{ + Destroy(); +} + +void IndexStreamBuffer::Create(size_t size) +{ + CreateIndexBuffer(&m_DeviceBuffer, nullptr, size, true); + AddRef(); +} + +void IndexStreamBuffer::Destroy() +{ + if (m_DeviceBuffer == 0) + return; + + glDeleteBuffers(1, &m_DeviceBuffer); +} + +void* IndexStreamBuffer::Map(size_t offset, size_t size, bool flush /*= false*/) +{ + VERIFY(m_DeviceBuffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_DeviceBuffer); + + void *pData = nullptr; + const auto flags = flush ? LOCKFLAGS_FLUSH : LOCKFLAGS_APPEND; + CHK_GL(pData = (void*)glMapBufferRange( + GL_ELEMENT_ARRAY_BUFFER, + offset, + size, + flags)); + + return pData; +} + +void IndexStreamBuffer::Unmap() +{ + VERIFY(m_DeviceBuffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_DeviceBuffer); + CHK_GL(glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER)); +} + +bool IndexStreamBuffer::IsValid() const +{ + return !!m_DeviceBuffer; +} diff --git a/src/Layers/xrRenderGLR1/glDetailManager_VS.cpp b/src/Layers/xrRenderGLR1/glDetailManager_VS.cpp new file mode 100755 index 00000000000..bacf5be23e0 --- /dev/null +++ b/src/Layers/xrRenderGLR1/glDetailManager_VS.cpp @@ -0,0 +1,227 @@ +#include "stdafx.h" +#include "Layers/xrRender/DetailManager.h" +#include "xrEngine/IGame_Persistent.h" +#include "xrEngine/Environment.h" +#include "Layers/xrRender/BufferUtils.h" + +const int quant = 16384; +const int c_hdr = 10; +const int c_size = 4; + +#pragma pack(push,1) +struct vertHW +{ + float x, y, z; + short u, v, t, mid; +}; +#pragma pack(pop) + +short QC(float v); +//{ +// int t=iFloor(v*float(quant)); clamp(t,-32768,32767); +// return short(t&0xffff); +//} + +void CDetailManager::hw_Load_Shaders() +{ + // Create shader to access constant storage + ref_shader S; + S.create("details" DELIMITER "set"); + R_constant_table& T0 = *S->E[0]->passes[0]->constants; + R_constant_table& T1 = *S->E[1]->passes[0]->constants; + hwc_consts = T0.get("consts"); + hwc_wave = T0.get("wave"); + hwc_wind = T0.get("dir2D"); + hwc_array = T0.get("array"); + hwc_s_consts = T1.get("consts"); + hwc_s_xform = T1.get("xform"); + hwc_s_array = T1.get("array"); +} + +void CDetailManager::hw_Render() +{ + // Render-prepare + // Update timer + // Can't use Device.fTimeDelta since it is smoothed! Don't know why, but smoothed value looks more choppy! + float fDelta = Device.fTimeGlobal - m_global_time_old; + if (fDelta < 0 || fDelta > 1) + fDelta = 0.03f; + m_global_time_old = Device.fTimeGlobal; + + m_time_rot_1 += PI_MUL_2 * fDelta / swing_current.rot1; + m_time_rot_2 += PI_MUL_2 * fDelta / swing_current.rot2; + m_time_pos += fDelta * swing_current.speed; + + //float tm_rot1 = (PI_MUL_2*Device.fTimeGlobal/swing_current.rot1); + //float tm_rot2 = (PI_MUL_2*Device.fTimeGlobal/swing_current.rot2); + float tm_rot1 = m_time_rot_1; + float tm_rot2 = m_time_rot_2; + + Fvector4 dir1, dir2; + dir1.set(_sin(tm_rot1), 0, _cos(tm_rot1), 0).normalize().mul(swing_current.amp1); + dir2.set(_sin(tm_rot2), 0, _cos(tm_rot2), 0).normalize().mul(swing_current.amp2); + + // Setup geometry and DMA + RCache.set_Geometry(hw_Geom); + + // Wave0 + float scale = 1.f / float(quant); + Fvector4 wave; + Fvector4 consts; + consts.set(scale, scale, ps_r__Detail_l_aniso, ps_r__Detail_l_ambient); + //wave.set (1.f/5.f, 1.f/7.f, 1.f/3.f, Device.fTimeGlobal*swing_current.speed); + wave.set(1.f / 5.f, 1.f / 7.f, 1.f / 3.f, m_time_pos); + //RCache.set_c (&*hwc_consts, scale, scale, ps_r__Detail_l_aniso, ps_r__Detail_l_ambient); // consts + //RCache.set_c (&*hwc_wave, wave.div(PI_MUL_2)); // wave + //RCache.set_c (&*hwc_wind, dir1); // wind-dir + //hw_Render_dump (&*hwc_array, 1, 0, c_hdr ); + hw_Render_dump(consts, wave.div(PI_MUL_2), dir1, 1, 0); + + // Wave1 + //wave.set (1.f/3.f, 1.f/7.f, 1.f/5.f, Device.fTimeGlobal*swing_current.speed); + wave.set(1.f / 3.f, 1.f / 7.f, 1.f / 5.f, m_time_pos); + //RCache.set_c (&*hwc_wave, wave.div(PI_MUL_2)); // wave + //RCache.set_c (&*hwc_wind, dir2); // wind-dir + //hw_Render_dump (&*hwc_array, 2, 0, c_hdr ); + hw_Render_dump(consts, wave.div(PI_MUL_2), dir2, 2, 0); + + // Still + consts.set(scale, scale, scale, 1.f); + //RCache.set_c (&*hwc_s_consts,scale, scale, scale, 1.f); + //RCache.set_c (&*hwc_s_xform, Device.mFullTransform); + //hw_Render_dump (&*hwc_s_array, 0, 1, c_hdr ); + hw_Render_dump(consts, wave.div(PI_MUL_2), dir2, 0, 1); +} + +void CDetailManager::hw_Render_dump(const Fvector4& consts, const Fvector4& wave, const Fvector4& wind, u32 var_id, + u32 lod_id) +{ + static shared_str strConsts("consts"); + static shared_str strWave("wave"); + static shared_str strDir2D("dir2D"); + static shared_str strArray("array"); + static shared_str strXForm("xform"); + + RImplementation.BasicStats.DetailCount = 0; + + // Matrices and offsets + u32 vOffset = 0; + u32 iOffset = 0; + + vis_list& list = m_visibles [var_id]; + + CEnvDescriptor& desc = *g_pGamePersistent->Environment().CurrentEnv; + Fvector c_sun, c_ambient, c_hemi; + c_sun.set(desc.sun_color.x, desc.sun_color.y, desc.sun_color.z); + c_sun.mul(.5f); + c_ambient.set(desc.ambient.x, desc.ambient.y, desc.ambient.z); + c_hemi.set(desc.hemi_color.x, desc.hemi_color.y, desc.hemi_color.z); + + // Iterate + for (u32 O = 0; O < objects.size(); O++) + { + CDetail& Object = *objects [O]; + xr_vector& vis = list [O]; + if (!vis.empty()) + { + for (u32 iPass = 0; iPass < Object.shader->E[lod_id]->passes.size(); ++iPass) + { + // Setup matrices + colors (and flush it as necessary) + //RCache.set_Element (Object.shader->E[lod_id]); + RCache.set_Element(Object.shader->E[lod_id], iPass); + RImplementation.apply_lmaterial(); + + // This could be cached in the corresponding consatant buffer + // as it is done for DX9 + RCache.set_c(strConsts, consts); + RCache.set_c(strWave, wave); + RCache.set_c(strDir2D, wind); + RCache.set_c(strXForm, Device.mFullTransform); + + ref_constant constArray = RCache.get_c(strArray); + VERIFY(constArray); + + //u32 c_base = x_array->vs.index; + //Fvector4* c_storage = RCache.get_ConstantCache_Vertex().get_array_f().access(c_base); + // TODO: OGL: Implement a constants buffer. + /*Fvector4* c_storage=0; + // Map constants to memory directly + { + void* pVData; + RCache.get_ConstantDirect( strArray, + hw_BatchSize*sizeof(Fvector4)*4, + &pVData, 0, 0); + c_storage = (Fvector4*) pVData; + } + VERIFY(c_storage);*/ + + u32 dwBatch = 0; + + xr_vector::iterator _vI = vis.begin(); + xr_vector::iterator _vE = vis.end(); + for (; _vI != _vE; ++_vI) + { + SlotItemVec* items = *_vI; + auto _iI = items->begin(); + auto _iE = items->end(); + for (; _iI != _iE; ++_iI) + { + SlotItem& Instance = **_iI; + u32 base = dwBatch * 4; + + // Build matrix ( 3x4 matrix, last row - color ) + float scale = Instance.scale_calculated; + Fmatrix& M = Instance.mRotY; + RCache.set_ca(&*constArray, base + 0, M._11 * scale, M._21 * scale, M._31 * scale, M._41); + RCache.set_ca(&*constArray, base + 1, M._12 * scale, M._22 * scale, M._32 * scale, M._42); + RCache.set_ca(&*constArray, base + 2, M._13 * scale, M._23 * scale, M._33 * scale, M._43); + + // Build color + // R2 only needs hemisphere + float h = Instance.c_hemi; + float s = Instance.c_sun; + RCache.set_ca(&*constArray, base + 3, s, s, s, h); + dwBatch ++; + if (dwBatch == hw_BatchSize) + { + // flush + RImplementation.BasicStats.DetailCount += dwBatch; + u32 dwCNT_verts = dwBatch * Object.number_vertices; + u32 dwCNT_prims = dwBatch * Object.number_indices / 3; + //RCache.get_ConstantCache_Vertex().b_dirty = TRUE; + //RCache.get_ConstantCache_Vertex().get_array_f().dirty (c_base,c_base+dwBatch*4); + RCache.Render(D3DPT_TRIANGLELIST, vOffset, 0, dwCNT_verts, iOffset, dwCNT_prims); + RCache.stat.r.s_details.add(dwCNT_verts); + + // restart + dwBatch = 0; + + // Remap constants to memory directly (just in case anything goes wrong) + /*{ + void* pVData; + RCache.get_ConstantDirect( strArray, + hw_BatchSize*sizeof(Fvector4)*4, + &pVData, 0, 0); + c_storage = (Fvector4*) pVData; + } + VERIFY(c_storage);*/ + } + } + } + // flush if nessecary + if (dwBatch) + { + RImplementation.BasicStats.DetailCount += dwBatch; + u32 dwCNT_verts = dwBatch * Object.number_vertices; + u32 dwCNT_prims = dwBatch * Object.number_indices / 3; + //RCache.get_ConstantCache_Vertex().b_dirty = TRUE; + //RCache.get_ConstantCache_Vertex().get_array_f().dirty (c_base,c_base+dwBatch*4); + RCache.Render(D3DPT_TRIANGLELIST, vOffset, 0, dwCNT_verts, iOffset, dwCNT_prims); + RCache.stat.r.s_details.add(dwCNT_verts); + } + } + } + vOffset += hw_BatchSize * Object.number_vertices; + iOffset += hw_BatchSize * Object.number_indices; + } +} diff --git a/src/Layers/xrRenderGLR1/glHW.cpp b/src/Layers/xrRenderGLR1/glHW.cpp new file mode 100755 index 00000000000..1dd6b7cd1b2 --- /dev/null +++ b/src/Layers/xrRenderGLR1/glHW.cpp @@ -0,0 +1,293 @@ +// glHW.cpp: implementation of the DX10 specialisation of CHW. +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#pragma hdrstop + +#include "glHW.h" +#include "xrEngine/XR_IOConsole.h" + +CHW HW; + +void CALLBACK OnDebugCallback(GLenum /*source*/, GLenum /*type*/, GLuint id, GLenum severity, GLsizei /*length*/, + const GLchar* message, const void* /*userParam*/) +{ + if (severity != GL_DEBUG_SEVERITY_NOTIFICATION) + Log(message, id); +} + +void UpdateVSync() +{ + if (psDeviceFlags.test(rsVSync)) + { + // Try adaptive vsync first + if (SDL_GL_SetSwapInterval(-1) == -1) + SDL_GL_SetSwapInterval(1); + } + else + { + SDL_GL_SetSwapInterval(0); + } +} + +CHW::CHW() +{ + if (!ThisInstanceIsGlobal()) + return; + + Device.seqAppActivate.Add(this); + Device.seqAppDeactivate.Add(this); +} + +CHW::~CHW() +{ + if (!ThisInstanceIsGlobal()) + return; + + Device.seqAppActivate.Remove(this); + Device.seqAppDeactivate.Remove(this); +} + +void CHW::OnAppActivate() +{ + if (m_window) + { + SDL_RestoreWindow(m_window); + } +} + +void CHW::OnAppDeactivate() +{ + if (m_window) + { + if (psDeviceMode.WindowStyle == rsFullscreen || psDeviceMode.WindowStyle == rsFullscreenBorderless) + SDL_MinimizeWindow(m_window); + } +} + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// +void CHW::CreateDevice(SDL_Window* hWnd) +{ + m_window = hWnd; + + R_ASSERT(m_window); + + // Choose the closest pixel format + SDL_DisplayMode mode; + SDL_GetWindowDisplayMode(m_window, &mode); + mode.format = SDL_PIXELFORMAT_RGBA8888; + // Apply the pixel format to the device context + SDL_SetWindowDisplayMode(m_window, &mode); + + // Create the context + m_context = SDL_GL_CreateContext(m_window); + if (m_context == nullptr) + { + Msg("Could not create drawing context: %s", SDL_GetError()); + return; + } + + if (MakeContextCurrent(IRender::PrimaryContext) != 0) + { + Msg("Could not make context current. %s", SDL_GetError()); + return; + } + + { + const Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL; + + m_helper_window = SDL_CreateWindow("OpenXRay OpenGL helper window", 0, 0, 1, 1, flags); + R_ASSERT3(m_helper_window, "Cannot create helper window for OpenGL", SDL_GetError()); + + SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); + + // Create helper context + m_helper_context = SDL_GL_CreateContext(m_helper_window); + R_ASSERT3(m_helper_context, "Cannot create OpenGL context", SDL_GetError()); + + // just in case + SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 0); + } + + if (MakeContextCurrent(IRender::PrimaryContext) != 0) + { + Msg("Could not make context current after creating helper context." + " %s", SDL_GetError()); + return; + } + + // Initialize OpenGL Extension Wrangler + if (glewInit() != GLEW_OK) + { + Msg("Could not initialize glew."); + return; + } + + UpdateVSync(); + +#ifdef DEBUG + CHK_GL(glEnable(GL_DEBUG_OUTPUT)); + CHK_GL(glDebugMessageCallback((GLDEBUGPROC)OnDebugCallback, nullptr)); +#endif // DEBUG + + int iMaxVTFUnits, iMaxCTIUnits; + glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &iMaxVTFUnits); + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &iMaxCTIUnits); + + glGetIntegerv(GL_MAJOR_VERSION, &(std::get<0>(OpenGLVersion))); + glGetIntegerv(GL_MINOR_VERSION, &(std::get<1>(OpenGLVersion))); + + AdapterName = reinterpret_cast(glGetString(GL_RENDERER)); + OpenGLVersionString = reinterpret_cast(glGetString(GL_VERSION)); + ShadingVersion = reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION)); + + Msg("* GPU vendor: [%s] device: [%s]", glGetString(GL_VENDOR), AdapterName); + Msg("* GPU OpenGL version: %s", OpenGLVersionString); + Msg("* GPU OpenGL shading language version: %s", ShadingVersion); + Msg("* GPU OpenGL VTF units: [%d] CTI units: [%d]", iMaxVTFUnits, iMaxCTIUnits); + + ShaderBinarySupported = GLEW_ARB_get_program_binary; + ComputeShadersSupported = false; // XXX: Implement compute shaders support + + Caps.fTarget = D3DFMT_A8R8G8B8; + Caps.fDepth = D3DFMT_D24S8; + + // Create render target and depth-stencil views here + UpdateViews(); +} + +void CHW::DestroyDevice() +{ + SDL_GL_MakeCurrent(nullptr, nullptr); + + SDL_GL_DeleteContext(m_context); + m_context = nullptr; + + SDL_GL_DeleteContext(m_helper_context); + m_helper_context = nullptr; +} + +////////////////////////////////////////////////////////////////////// +// Resetting device +////////////////////////////////////////////////////////////////////// +void CHW::Reset() +{ + CHK_GL(glDeleteProgramPipelines(1, &pPP)); + CHK_GL(glDeleteFramebuffers(1, &pFB)); + UpdateViews(); + UpdateVSync(); +} + +void CHW::SetPrimaryAttributes() +{ + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + + if (!strstr(Core.Params, "-no_gl_context")) + { + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + } +} + +IRender::RenderContext CHW::GetCurrentContext() const +{ + const auto context = SDL_GL_GetCurrentContext(); + if (context == m_context) + return IRender::PrimaryContext; + if (context == m_helper_context) + return IRender::HelperContext; + return IRender::NoContext; +} + +int CHW::MakeContextCurrent(IRender::RenderContext context) const +{ + switch (context) + { + case IRender::NoContext: + return SDL_GL_MakeCurrent(nullptr, nullptr); + + case IRender::PrimaryContext: + return SDL_GL_MakeCurrent(m_window, m_context); + + case IRender::HelperContext: + return SDL_GL_MakeCurrent(m_helper_window, m_helper_context); + + default: + NODEFAULT; + } + return -1; +} + +void CHW::UpdateViews() +{ + // Create the program pipeline used for rendering with shaders + glGenProgramPipelines(1, &pPP); + CHK_GL(glBindProgramPipeline(pPP)); + + // Create the default framebuffer + glGenFramebuffers(1, &pFB); + CHK_GL(glBindFramebuffer(GL_FRAMEBUFFER, pFB)); + + BackBufferCount = 1; +} + +void CHW::BeginScene() { } +void CHW::EndScene() { } + +void CHW::Present() +{ +#if 0 // kept for historical reasons + RImplementation.Target->phase_flip(); +#else + glBindFramebuffer(GL_READ_FRAMEBUFFER, pFB); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBlitFramebuffer( + 0, 0, Device.dwWidth, Device.dwHeight, + 0, 0, Device.dwWidth, Device.dwHeight, + GL_COLOR_BUFFER_BIT, GL_NEAREST); +#endif + + SDL_GL_SwapWindow(m_window); + CurrentBackBuffer = (CurrentBackBuffer + 1) % BackBufferCount; +} + +DeviceState CHW::GetDeviceState() const +{ + // TODO: OGL: Implement GetDeviceState + return DeviceState::Normal; +} + +std::pair CHW::GetSurfaceSize() +{ + return + { + psDeviceMode.Width, + psDeviceMode.Height + }; +} + +bool CHW::ThisInstanceIsGlobal() const +{ + return this == &HW; +} + +void CHW::BeginPixEvent(pcstr name) const +{ + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, name); +} + +void CHW::EndPixEvent() const +{ + glPopDebugGroup(); +} diff --git a/src/Layers/xrRenderGLR1/glHW.h b/src/Layers/xrRenderGLR1/glHW.h new file mode 100755 index 00000000000..7f26f2c0439 --- /dev/null +++ b/src/Layers/xrRenderGLR1/glHW.h @@ -0,0 +1,69 @@ +#pragma once + +#include "Layers/xrRender/HWCaps.h" +#include "xrCore/ModuleLookup.hpp" +#include "SDL.h" +#include "SDL_syswm.h" + +class CHW + : public pureAppActivate, + public pureAppDeactivate +{ +public: + CHW(); + ~CHW(); + + void CreateDevice(SDL_Window* sdlWnd); + void DestroyDevice(); + + void Reset(); + + void SetPrimaryAttributes(); + + IRender::RenderContext GetCurrentContext() const; + int MakeContextCurrent(IRender::RenderContext context) const; + + static std::pair GetSurfaceSize(); + DeviceState GetDeviceState() const; + +public: + void BeginScene(); + void EndScene(); + void Present(); + +public: + void OnAppActivate() override; + void OnAppDeactivate() override; + +private: + void UpdateViews(); + bool ThisInstanceIsGlobal() const; + +public: + void BeginPixEvent(pcstr name) const; + void EndPixEvent() const; + +public: + CHWCaps Caps; + + u32 BackBufferCount{}; + u32 CurrentBackBuffer{}; + + GLuint pPP{}; + GLuint pFB{}; + + SDL_Window* m_window{}; + SDL_Window* m_helper_window{}; + + SDL_GLContext m_context{}; + SDL_GLContext m_helper_context{}; + + pcstr AdapterName; + pcstr OpenGLVersionString; + pcstr ShadingVersion; + std::pair OpenGLVersion; + bool ShaderBinarySupported; + bool ComputeShadersSupported; +}; + +extern ECORE_API CHW HW; diff --git a/src/Layers/xrRenderGLR1/glHWCaps.cpp b/src/Layers/xrRenderGLR1/glHWCaps.cpp new file mode 100755 index 00000000000..c0687ef3623 --- /dev/null +++ b/src/Layers/xrRenderGLR1/glHWCaps.cpp @@ -0,0 +1,71 @@ +#include "stdafx.h" +#pragma hdrstop + +#include "Layers/xrRender/HWCaps.h" +#include "glHW.h" + +namespace +{ +u32 GetGpuNum() +{ + return 2; +} +} + +void CHWCaps::Update() +{ + // ***************** GEOMETRY + geometry_major = 4; + geometry_minor = 0; + geometry_profile = "vs_4_0"; + geometry.bSoftware = FALSE; + geometry.bPointSprites = FALSE; + geometry.bNPatches = FALSE; + u32 cnt = 256; + clamp(cnt, 0, 256); + geometry.dwRegisters = cnt; + geometry.dwInstructions = 256; + geometry.dwClipPlanes = _min(6, 15); + geometry.bVTF = + (HW.OpenGLVersion >= std::make_pair(3, 0) || GLEW_ARB_texture_float) + && !strstr(Core.Params, "-novtf"); + + // ***************** PIXEL processing + raster_major = 4; + raster_minor = 0; + raster_profile = "ps_4_0"; + // XXX: review this + raster.dwStages = 15; // Previuos value is 16, but it's out of bounds + raster.bNonPow2 = TRUE; + raster.bCubemap = TRUE; + raster.dwMRT_count = 4; + // raster.b_MRT_mixdepth = FALSE; + raster.b_MRT_mixdepth = TRUE; + raster.dwInstructions = 256; + // TODO: DX10: Find a way to detect cache size + geometry.dwVertexCache = 24; + + // *******1********** Compatibility : vertex shader + if (0 == raster_major) + geometry_major = 0; // Disable VS if no PS + + // + bTableFog = FALSE; // BOOL (caps.RasterCaps&D3DPRASTERCAPS_FOGTABLE); + + // Detect if stencil available + bStencil = TRUE; + + // Scissoring + bScissor = TRUE; + + // Stencil relative caps + soInc = D3DSTENCILOP_INCRSAT; + soDec = D3DSTENCILOP_DECRSAT; + dwMaxStencilValue = (1 << 8) - 1; + + // DEV INFO + + iGPUNum = GetGpuNum(); + + useCombinedSamplers = true; +} diff --git a/src/Layers/xrRenderGLR1/glR_Backend_Runtime.h b/src/Layers/xrRenderGLR1/glR_Backend_Runtime.h new file mode 100755 index 00000000000..501983b7890 --- /dev/null +++ b/src/Layers/xrRenderGLR1/glR_Backend_Runtime.h @@ -0,0 +1,457 @@ +#ifndef glR_Backend_Runtime_included +#define glR_Backend_Runtime_included +#pragma once + +#include "glStateUtils.h" + +IC void CBackend::set_xform(u32 ID, const Fmatrix& M) +{ + stat.xforms++; + // TODO: OGL: Implement CBackend::set_xform + //VERIFY(!"Implement CBackend::set_xform"); +} + +IC GLuint CBackend::get_FB() +{ + return pFB; +} + +IC void CBackend::set_FB(GLuint FB) +{ + if (FB != pFB) + { + PGO(Msg("PGO:set_FB")); + pFB = FB; + CHK_GL(glBindFramebuffer(GL_FRAMEBUFFER, pFB)); + } +} + +IC void CBackend::set_RT(GLuint RT, u32 ID) +{ + if (RT != pRT[ID]) + { + PGO(Msg("PGO:setRT")); + stat.target_rt++; + pRT[ID] = RT; + // TODO: OGL: Implement support for multi-sampled render targets + CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + ID, GL_TEXTURE_2D, RT, 0)); + } +} + +IC void CBackend::set_ZB(GLuint ZB) +{ + if (ZB != pZB) + { + PGO(Msg("PGO:setZB")); + stat.target_zb++; + pZB = ZB; + // TODO: OGL: Implement support for multi-sampled render targets + CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, ZB, 0)); + } +} + +IC void CBackend::ClearRT(GLuint rt, const Fcolor& color) +{ + // TODO: OGL: Implement support for multi-sampled render targets + CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt, 0)); + + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glClearColor(color.r, color.g, color.b, color.a); + + CHK_GL(glClear(GL_COLOR_BUFFER_BIT)); +} + +IC void CBackend::ClearZB(GLuint zb, float depth) +{ + // TODO: OGL: Implement support for multi-sampled render targets + CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, zb, 0)); + + glDepthMask(GL_TRUE); + glClearDepthf(depth); + + CHK_GL(glClear(GL_DEPTH_BUFFER_BIT)); +} + +IC void CBackend::ClearZB(GLuint zb, float depth, u8 stencil) +{ + // TODO: OGL: Implement support for multi-sampled render targets + CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, zb, 0)); + + glDepthMask(GL_TRUE); + glClearDepthf(depth); + + glStencilMask(~0); + glClearStencil(stencil); + + CHK_GL(glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)); +} + +IC bool CBackend::ClearRTRect(GLuint rt, const Fcolor& color, size_t numRects, const Irect* rects) +{ + // TODO: OGL: Implement support for multi-sampled render targets + CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt, 0)); + + CHK_GL(glEnable(GL_SCISSOR_TEST)); + + for (size_t i = 0; i < numRects; ++i, ++rects) + { + // The window space is inverted compared to DX + // so we have to invert our vertical coordinates + const u32 bottom = Device.dwHeight - rects->bottom; + + // The origin of the scissor box is lower-left + CHK_GL(glScissor(rects->left, bottom, rects->width(), rects->height())); + + // Clear the color buffer without affecting the global state + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glClearColor(color.r, color.g, color.b, color.a); + + CHK_GL(glClear(GL_COLOR_BUFFER_BIT)); + } + + CHK_GL(glDisable(GL_SCISSOR_TEST)); + + return true; +} + +IC bool CBackend::ClearZBRect(GLuint zb, float depth, size_t numRects, const Irect* rects) +{ + // TODO: OGL: Implement support for multi-sampled render targets + CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, zb, 0)); + + CHK_GL(glEnable(GL_SCISSOR_TEST)); + + for (size_t i = 0; i < numRects; ++i, ++rects) + { + // The window space is inverted compared to DX + // so we have to invert our vertical coordinates + const u32 bottom = Device.dwHeight - rects->bottom; + + // The origin of the scissor box is lower-left + CHK_GL(glScissor(rects->left, bottom, rects->width(), rects->height())); + + glDepthMask(GL_TRUE); + glClearDepthf(depth); + + CHK_GL(glClear(GL_DEPTH_BUFFER_BIT)); + } + + CHK_GL(glDisable(GL_SCISSOR_TEST)); + + return true; +} + +ICF void CBackend::set_Format(SDeclaration* _decl) +{ + if (decl != _decl) + { + PGO(Msg("PGO:v_format:%x", _decl)); +#ifdef DEBUG + stat.decl++; +#endif + decl = _decl; + CHK_GL(glBindVertexArray(_decl->dcl)); + + // Clear cached index buffer + ib = 0; + } +} + +ICF void CBackend::set_PS(GLuint _ps, LPCSTR _n) +{ + if (ps != _ps) + { +#ifdef RBackend_PGO + string_path name; +#endif + PGO(glGetObjectLabel(GL_PROGRAM, _ps, sizeof(name), nullptr, name)); + PGO(Msg("PGO:Pshader:%d,%s", _ps, _n ? _n : name)); + stat.ps++; + ps = _ps; + CHK_GL(glUseProgramStages(HW.pPP, GL_FRAGMENT_SHADER_BIT, ps)); +#ifdef DEBUG + ps_name = _n; +#endif + } +} + +#ifndef USE_OGLR1 +ICF void CBackend::set_GS(GLuint _gs, LPCSTR _n) +{ + if (gs != _gs) + { +#ifdef RBackend_PGO + string_path name; +#endif + PGO(glGetObjectLabel(GL_PROGRAM, _gs, sizeof(name), nullptr, name)); + PGO(Msg("PGO:Gshader:%d,%s", _gs, _n ? _n : name)); + // TODO: OGL: Get statistics for G Shader change + //stat.gs ++; + gs = _gs; + CHK_GL(glUseProgramStages(HW.pPP, GL_GEOMETRY_SHADER_BIT, gs)); +#ifdef DEBUG + gs_name = _n; +#endif + } +} +#endif + +ICF void CBackend::set_VS(GLuint _vs, LPCSTR _n) +{ + if (vs != _vs) + { +#ifdef RBackend_PGO + string_path name; +#endif + PGO(glGetObjectLabel(GL_PROGRAM, _vs, sizeof(name), nullptr, name)); + PGO(Msg("PGO:Vshader:%d,%s", _vs, _n ? _n : name)); + stat.vs++; + vs = _vs; + CHK_GL(glUseProgramStages(HW.pPP, GL_VERTEX_SHADER_BIT, vs)); +#ifdef DEBUG + vs_name = _n; +#endif + } +} + +ICF void CBackend::set_Vertices(GLuint _vb, u32 _vb_stride) +{ + if (vb != _vb || vb_stride != _vb_stride) + { + PGO(Msg("PGO:VB:%x,%d", _vb, _vb_stride)); +#ifdef DEBUG + stat.vb++; +#endif + vb = _vb; + vb_stride = _vb_stride; + CHK_GL(glBindVertexBuffer(0, vb, 0, vb_stride)); + } +} + +ICF void CBackend::set_Indices(GLuint _ib) +{ + if (ib != _ib) + { + PGO(Msg("PGO:IB:%x", _ib)); +#ifdef DEBUG + stat.ib++; +#endif + ib = _ib; + CHK_GL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib)); + } +} + +IC GLenum TranslateTopology(D3DPRIMITIVETYPE T) +{ + static GLenum translateTable[] = + { + GL_NONE, // None + GL_POINTS, // D3DPT_POINTLIST = 1, + GL_LINES, // D3DPT_LINELIST = 2, + GL_LINE_STRIP, // D3DPT_LINESTRIP = 3, + GL_TRIANGLES, // D3DPT_TRIANGLELIST = 4, + GL_TRIANGLE_STRIP, // D3DPT_TRIANGLESTRIP = 5, + GL_TRIANGLE_FAN, // D3DPT_TRIANGLEFAN = 6, + }; + + VERIFY(T= 0); + + GLenum result = translateTable[T]; + + VERIFY(result != NULL); + + return result; +} + +IC u32 GetIndexCount(D3DPRIMITIVETYPE T, u32 iPrimitiveCount) +{ + switch (T) + { + case D3DPT_POINTLIST: + return iPrimitiveCount; + case D3DPT_LINELIST: + return iPrimitiveCount * 2; + case D3DPT_LINESTRIP: + return iPrimitiveCount + 1; + case D3DPT_TRIANGLELIST: + return iPrimitiveCount * 3; + case D3DPT_TRIANGLESTRIP: + return iPrimitiveCount + 2; + default: NODEFAULT; +#ifdef DEBUG + return 0; +#endif // #ifdef DEBUG + } +} + +ICF void CBackend::Render(D3DPRIMITIVETYPE T, u32 baseV, u32 startV, u32 countV, u32 startI, u32 PC) +{ + GLenum Topology = TranslateTopology(T); + u32 iIndexCount = GetIndexCount(T, PC); + + stat.calls++; + stat.verts += countV; + stat.polys += PC; + constants.flush(); + CHK_GL(glDrawElementsBaseVertex(Topology, iIndexCount, GL_UNSIGNED_SHORT, (void*)(startI * sizeof(GLushort)), baseV)); + PGO(Msg("PGO:DIP:%dv/%df", countV, PC)); +} + +ICF void CBackend::Render(D3DPRIMITIVETYPE T, u32 startV, u32 PC) +{ + GLenum Topology = TranslateTopology(T); + u32 iIndexCount = GetIndexCount(T, PC); + + stat.calls++; + stat.verts += iIndexCount; + stat.polys += PC; + constants.flush(); + CHK_GL(glDrawArrays(Topology, startV, iIndexCount)); + PGO(Msg("PGO:DIP:%dv/%df", iIndexCount, PC)); +} + +IC void CBackend::set_Geometry(SGeometry* _geom) +{ + set_Format(&*_geom->dcl); + + set_Vertices(_geom->vb, _geom->vb_stride); + set_Indices(_geom->ib); +} + +IC void CBackend::set_Scissor(Irect* R) +{ + if (R) + { + CHK_GL(glEnable(GL_SCISSOR_TEST)); + + // The window space is inverted compared to DX, + // so we have to invert our vertical coordinates + u32 bottom = Device.dwHeight - R->bottom; + + // The origin of the scissor box is lower-left + CHK_GL(glScissor(R->left, bottom, R->width(), R->height())); + } + else + { + CHK_GL(glDisable(GL_SCISSOR_TEST)); + } +} + +IC void CBackend::SetViewport(const D3D_VIEWPORT& viewport) const +{ + glViewport(viewport.TopLeftX, viewport.TopLeftY, viewport.Width, viewport.Height); + glDepthRangef(viewport.MinDepth, viewport.MaxDepth); +} + +IC void CBackend::set_Stencil(u32 _enable, u32 _func, u32 _ref, u32 _mask, u32 _writemask, u32 _fail, u32 _pass, + u32 _zfail) +{ + if (_enable) + { + glEnable(GL_STENCIL_TEST); + CHK_GL(glStencilFunc(glStateUtils::ConvertCmpFunction(_func), _ref, _mask)); + CHK_GL(glStencilMask(_writemask)); + CHK_GL(glStencilOp(glStateUtils::ConvertStencilOp(_fail), + glStateUtils::ConvertStencilOp(_zfail), + glStateUtils::ConvertStencilOp(_pass))); + } + else + { + glDisable(GL_STENCIL_TEST); + } +} + +IC void CBackend::set_Z(u32 _enable) +{ + if (z_enable != _enable) + { + z_enable = _enable; + if (_enable) + glEnable(GL_DEPTH_TEST); + else + glDisable(GL_DEPTH_TEST); + } +} + +IC void CBackend::set_ZFunc(u32 _func) +{ + if (z_func != _func) + { + z_func = _func; + CHK_GL(glDepthFunc(glStateUtils::ConvertCmpFunction(_func))); + } +} + +IC void CBackend::set_AlphaRef(u32 _value) +{ + VERIFY(!"Not implemented."); +} + +IC void CBackend::set_ColorWriteEnable(u32 _mask) +{ + if (colorwrite_mask != _mask) + { + colorwrite_mask = _mask; + CHK_GL(glColorMask( + (_mask & D3DCOLORWRITEENABLE_RED) ? GL_TRUE : GL_FALSE, + (_mask & D3DCOLORWRITEENABLE_GREEN) ? GL_TRUE : GL_FALSE, + (_mask & D3DCOLORWRITEENABLE_BLUE) ? GL_TRUE : GL_FALSE, + (_mask & D3DCOLORWRITEENABLE_ALPHA) ? GL_TRUE : GL_FALSE)); + } +} + +ICF void CBackend::set_CullMode(u32 _mode) +{ + if (cull_mode != _mode) + { + cull_mode = _mode; + if (_mode == D3DCULL_NONE) + { + glDisable(GL_CULL_FACE); + } + else + { + glEnable(GL_CULL_FACE); + CHK_GL(glCullFace(glStateUtils::ConvertCullMode(_mode))); + } + } +} + +ICF void CBackend::set_FillMode(u32 _mode) +{ + if (fill_mode != _mode) + { + fill_mode = _mode; + glPolygonMode(GL_FRONT_AND_BACK, glStateUtils::ConvertFillMode(_mode)); + } +} + +ICF void CBackend::set_VS(ref_vs& _vs) +{ + set_VS(_vs->sh, _vs->cName.c_str()); +} + +IC void CBackend::set_Constants(R_constant_table* C) +{ + // caching + if (ctable == C) return; + ctable = C; + xforms.unmap(); + hemi.unmap(); + tree.unmap(); + if (nullptr == C) return; + + PGO(Msg("PGO:c-table")); + + // process constant-loaders + R_constant_table::c_table::iterator it = C->table.begin(); + R_constant_table::c_table::iterator end = C->table.end(); + for (; it != end; ++it) + { + R_constant* Cs = &**it; + if (Cs->handler) Cs->handler->setup(Cs); + } +} + +#endif // glR_Backend_Runtime_included diff --git a/src/Layers/xrRenderGLR1/glResourceManager_Resources.cpp b/src/Layers/xrRenderGLR1/glResourceManager_Resources.cpp new file mode 100755 index 00000000000..1b455e0ad8b --- /dev/null +++ b/src/Layers/xrRenderGLR1/glResourceManager_Resources.cpp @@ -0,0 +1,212 @@ +#include "stdafx.h" +#pragma hdrstop + +#include "../xrRender/ResourceManager.h" +#include "../xrRender/tss.h" +#include "../xrRender/Blender.h" +#include "../xrRender/Blender_Recorder.h" +#include "Layers/xrRender/BufferUtils.h" +#include "Layers/xrRender/ShaderResourceTraits.h" + +//-------------------------------------------------------------------------------------------------------------- +SPass* CResourceManager::_CreatePass(const SPass& proto) +{ + for (SPass* pass : v_passes) + if (pass->equal(proto)) + return pass; + + SPass* P = v_passes.emplace_back(xr_new()); + P->dwFlags |= xr_resource_flagged::RF_REGISTERED; + P->state = proto.state; + P->ps = proto.ps; + P->vs = proto.vs; + //P->gs = proto.gs; + P->constants = proto.constants; + P->T = proto.T; +#ifdef _EDITOR + P->M = proto.M; +#endif + P->C = proto.C; + + return P; +} + +//-------------------------------------------------------------------------------------------------------------- +static BOOL dcl_equal(D3DVERTEXELEMENT9* a, D3DVERTEXELEMENT9* b) +{ + // check sizes + u32 a_size = GetDeclLength(a); + u32 b_size = GetDeclLength(b); + if (a_size != b_size) return FALSE; + return 0 == memcmp(a, b, a_size * sizeof(D3DVERTEXELEMENT9)); +} + +SDeclaration* CResourceManager::_CreateDecl(u32 FVF) +{ + // Search equal code + for (SDeclaration* D : v_declarations) + { + if (D->dcl_code.empty() && D->FVF == FVF) + return D; + } + + SDeclaration* D = v_declarations.emplace_back(xr_new()); + glGenVertexArrays(1, &D->dcl); + + D->FVF = FVF; + ConvertVertexDeclaration(FVF, D); + D->dwFlags |= xr_resource_flagged::RF_REGISTERED; + + return D; +} + +SDeclaration* CResourceManager::_CreateDecl(D3DVERTEXELEMENT9* dcl) +{ + // Search equal code + for (SDeclaration* D : v_declarations) + { + if (!D->dcl_code.empty() && dcl_equal(dcl, &D->dcl_code.front())) + return D; + } + + SDeclaration* D = v_declarations.emplace_back(xr_new()); + glGenVertexArrays(1, &D->dcl); + + D->FVF = 0; + u32 dcl_size = GetDeclLength(dcl) + 1; + D->dcl_code.assign(dcl, dcl + dcl_size); + ConvertVertexDeclaration(dcl, D); + D->dwFlags |= xr_resource_flagged::RF_REGISTERED; + + return D; +} + +//-------------------------------------------------------------------------------------------------------------- +SVS* CResourceManager::_CreateVS(cpcstr shader, u32 flags /*= 0*/) +{ + string_path name; + xr_strcpy(name, shader); + switch (GEnv.Render->m_skinning) + { + case 0: + xr_strcat(name, "_0"); + break; + case 1: + xr_strcat(name, "_1"); + break; + case 2: + xr_strcat(name, "_2"); + break; + case 3: + xr_strcat(name, "_3"); + break; + case 4: + xr_strcat(name, "_4"); + break; + } + + return CreateShader(name, shader, flags); +} + +void CResourceManager::_DeleteVS(const SVS* vs) { DestroyShader(vs); } + +//-------------------------------------------------------------------------------------------------------------- +SPS* CResourceManager::_CreatePS(LPCSTR _name) +{ + string_path name; + xr_strcpy(name, _name); + switch (GEnv.Render->m_MSAASample) + { + case 0: + xr_strcat(name, "_0"); + break; + case 1: + xr_strcat(name, "_1"); + break; + case 2: + xr_strcat(name, "_2"); + break; + case 3: + xr_strcat(name, "_3"); + break; + case 4: + xr_strcat(name, "_4"); + break; + case 5: + xr_strcat(name, "_5"); + break; + case 6: + xr_strcat(name, "_6"); + break; + case 7: + xr_strcat(name, "_7"); + break; + } + + return CreateShader(name, _name); +} + +void CResourceManager::_DeletePS(const SPS* ps) { DestroyShader(ps); } + +//-------------------------------------------------------------------------------------------------------------- +/* +SGS* CResourceManager::_CreateGS(LPCSTR Name) { return CreateShader(Name); } +void CResourceManager::_DeleteGS(const SGS* gs) { DestroyShader(gs); } + +SHS* CResourceManager::_CreateHS(LPCSTR Name) { return CreateShader(Name); } +void CResourceManager::_DeleteHS(const SHS* HS) { DestroyShader(HS); } + +SDS* CResourceManager::_CreateDS(LPCSTR Name) { return CreateShader(Name); } +void CResourceManager::_DeleteDS(const SDS* DS) { DestroyShader(DS); } + +SCS* CResourceManager::_CreateCS(LPCSTR Name) { return CreateShader(Name); } +void CResourceManager::_DeleteCS(const SCS* CS) { DestroyShader(CS); } +*/ +//-------------------------------------------------------------------------------------------------------------- +SGeometry* CResourceManager::CreateGeom(VertexElement* decl, GLuint vb, GLuint ib) +{ + R_ASSERT(decl && vb); + + SDeclaration* dcl = _CreateDecl(decl); + u32 vb_stride = GetDeclVertexSize(decl, 0); + + // ***** first pass - search already loaded shader + for (SGeometry* geom : v_geoms) + { + SGeometry& G = *geom; + if (G.dcl == dcl && G.vb == vb && G.ib == ib && G.vb_stride == vb_stride) return geom; + } + + SGeometry* Geom = v_geoms.emplace_back(xr_new()); + Geom->dwFlags |= xr_resource_flagged::RF_REGISTERED; + Geom->dcl = dcl; + Geom->vb = vb; + Geom->vb_stride = vb_stride; + Geom->ib = ib; + + return Geom; +} + +SGeometry* CResourceManager::CreateGeom(u32 FVF, GLuint vb, GLuint ib) +{ + R_ASSERT(FVF && vb); + + SDeclaration* dcl = _CreateDecl(FVF); + u32 vb_stride = GetFVFVertexSize(FVF); + + // ***** first pass - search already loaded shader + for (SGeometry* geom : v_geoms) + { + SGeometry& G = *geom; + if (G.dcl == dcl && G.vb == vb && G.ib == ib && G.vb_stride == vb_stride) return geom; + } + + SGeometry* Geom = v_geoms.emplace_back(xr_new()); + Geom->dwFlags |= xr_resource_flagged::RF_REGISTERED; + Geom->dcl = dcl; + Geom->vb = vb; + Geom->vb_stride = vb_stride; + Geom->ib = ib; + + return Geom; +} diff --git a/src/Layers/xrRenderGLR1/glResourceManager_Scripting.cpp b/src/Layers/xrRenderGLR1/glResourceManager_Scripting.cpp new file mode 100755 index 00000000000..d25802307c5 --- /dev/null +++ b/src/Layers/xrRenderGLR1/glResourceManager_Scripting.cpp @@ -0,0 +1,554 @@ +#include "stdafx.h" +#pragma hdrstop + +#include "Layers/xrRender/ResourceManager.h" +#include "Layers/xrRender/tss.h" +#include "Layers/xrRender/Blender.h" +#include "Layers/xrRender/Blender_Recorder.h" +// adopt_compiler don't have = operator And it can't have = operator +#include "xrScriptEngine/script_engine.hpp" +#include "luabind/return_reference_to_policy.hpp" +#include "xrCore/Threading/ScopeLock.hpp" + +using namespace luabind; +using namespace policy; + +#ifdef DEBUG +#define MDB Memory.dbg_check() +#else +#define MDB +#endif + +class adopt_dx10options +{ +public: + bool _dx10_msaa_alphatest_atoc() + { + return RImplementation.o.dx10_msaa_alphatest == CRender::MSAA_ATEST_DX10_0_ATOC; + } +}; + +// wrapper +class adopt_sampler +{ + CBlender_Compile* C; + u32 stage; +public: + adopt_sampler(CBlender_Compile* _C, u32 _stage) : C(_C), stage(_stage) { if (u32(-1) == stage) C = nullptr; } + adopt_sampler(const adopt_sampler& _C) : C(_C.C), stage(_C.stage) { if (u32(-1) == stage) C = nullptr; } + + adopt_sampler& _texture(LPCSTR texture) + { + if (C) C->i_Texture(stage, texture); + return *this; + } + + adopt_sampler& _projective(bool _b) + { + if (C) C->i_Projective(stage, _b); + return *this; + } + + adopt_sampler& _clamp() + { + if (C) C->i_Address(stage, D3DTADDRESS_CLAMP); + return *this; + } + + adopt_sampler& _wrap() + { + if (C) C->i_Address(stage, D3DTADDRESS_WRAP); + return *this; + } + + adopt_sampler& _mirror() + { + if (C) C->i_Address(stage, D3DTADDRESS_MIRROR); + return *this; + } + + adopt_sampler& _f_anisotropic() + { + if (C) C->i_Filter(stage, D3DTEXF_ANISOTROPIC, D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC); + return *this; + } + + adopt_sampler& _f_trilinear() + { + if (C) C->i_Filter(stage, D3DTEXF_LINEAR, D3DTEXF_LINEAR, D3DTEXF_LINEAR); + return *this; + } + + adopt_sampler& _f_bilinear() + { + if (C) C->i_Filter(stage, D3DTEXF_LINEAR, D3DTEXF_POINT, D3DTEXF_LINEAR); + return *this; + } + + adopt_sampler& _f_linear() + { + if (C) C->i_Filter(stage, D3DTEXF_LINEAR, D3DTEXF_NONE, D3DTEXF_LINEAR); + return *this; + } + + adopt_sampler& _f_none() + { + if (C) C->i_Filter(stage, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); + return *this; + } + + adopt_sampler& _fmin_none() + { + if (C) C->i_Filter_Min(stage, D3DTEXF_NONE); + return *this; + } + + adopt_sampler& _fmin_point() + { + if (C) C->i_Filter_Min(stage, D3DTEXF_POINT); + return *this; + } + + adopt_sampler& _fmin_linear() + { + if (C) C->i_Filter_Min(stage, D3DTEXF_LINEAR); + return *this; + } + + adopt_sampler& _fmin_aniso() + { + if (C) C->i_Filter_Min(stage, D3DTEXF_ANISOTROPIC); + return *this; + } + + adopt_sampler& _fmip_none() + { + if (C) C->i_Filter_Mip(stage, D3DTEXF_NONE); + return *this; + } + + adopt_sampler& _fmip_point() + { + if (C) C->i_Filter_Mip(stage, D3DTEXF_POINT); + return *this; + } + + adopt_sampler& _fmip_linear() + { + if (C) C->i_Filter_Mip(stage, D3DTEXF_LINEAR); + return *this; + } + + adopt_sampler& _fmag_none() + { + if (C) C->i_Filter_Mag(stage, D3DTEXF_NONE); + return *this; + } + + adopt_sampler& _fmag_point() + { + if (C) C->i_Filter_Mag(stage, D3DTEXF_POINT); + return *this; + } + + adopt_sampler& _fmag_linear() + { + if (C) C->i_Filter_Mag(stage, D3DTEXF_LINEAR); + return *this; + } + + adopt_sampler& _comp_less() + { + if (C) C->i_Comparison(stage, D3D_COMPARISON_LESS_EQUAL); + return *this; + } +}; + +#pragma warning( push ) +#pragma warning( disable : 4512) +// wrapper +class adopt_compiler +{ + CBlender_Compile* C; + bool& m_bFirstPass; + + void TryEndPass() + { + if (!m_bFirstPass) C->r_End(); + m_bFirstPass = false; + } + +public: + adopt_compiler(CBlender_Compile* _C, bool& bFirstPass) : C(_C), m_bFirstPass(bFirstPass) { m_bFirstPass = true; } + adopt_compiler(const adopt_compiler& _C) : C(_C.C), m_bFirstPass(_C.m_bFirstPass) { } + + adopt_compiler& _options(int P, bool S) + { + C->SetParams(P, S); + return *this; + } + + adopt_compiler& _o_emissive(bool E) + { + C->SH->flags.bEmissive = E; + return *this; + } + + adopt_compiler& _o_distort(bool E) + { + C->SH->flags.bDistort = E; + return *this; + } + + adopt_compiler& _o_wmark(bool E) + { + C->SH->flags.bWmark = E; + return *this; + } + + adopt_compiler& _pass(LPCSTR vs, LPCSTR ps) + { + TryEndPass(); + C->r_Pass(vs, ps, true); + return *this; + } + + adopt_compiler& _passgs(LPCSTR vs, LPCSTR gs, LPCSTR ps) + { + TryEndPass(); + C->r_Pass(vs, gs, ps, true); + return *this; + } + + adopt_compiler& _fog(bool _fog) + { + C->PassSET_LightFog(FALSE, _fog); + return *this; + } + + adopt_compiler& _ZB(bool _test, bool _write) + { + C->PassSET_ZB(_test, _write); + return *this; + } + + adopt_compiler& _blend(bool _blend, u32 abSRC, u32 abDST) + { + C->PassSET_ablend_mode(_blend, abSRC, abDST); + return *this; + } + + adopt_compiler& _aref(bool _aref, u32 aref) + { + C->PassSET_ablend_aref(_aref, aref); + return *this; + } + + adopt_sampler _sampler(LPCSTR _name) + { + u32 s = C->r_Sampler(_name, nullptr); + return adopt_sampler(C, s); + } + + //adopt_compiler& _dx10texture (LPCSTR _resname, LPCSTR _texname) { C->r_dx10Texture(_resname, _texname); return *this; } + //adopt_dx10sampler _dx10sampler (LPCSTR _name) { u32 s = C->r_dx10Sampler(_name); return adopt_dx10sampler(C,s); } + + // DX10 specific + adopt_compiler& _dx10color_write_enable(bool cR, bool cG, bool cB, bool cA) + { + C->r_ColorWriteEnable(cR, cG, cB, cA); + return *this; + } + + adopt_compiler& _dx10Stencil(bool Enable, u32 Func, u32 Mask, u32 WriteMask, u32 Fail, u32 Pass, u32 ZFail) + { + C->r_Stencil(Enable, Func, Mask, WriteMask, Fail, Pass, ZFail); + return *this; + } + + adopt_compiler& _dx10StencilRef(u32 Ref) + { + C->r_StencilRef(Ref); + return *this; + } + + adopt_compiler& _dx10ATOC(bool Enable) + { + C->RS.SetRS(XRDX10RS_ALPHATOCOVERAGE, Enable); + return *this; + } + + adopt_compiler& _dx10ZFunc(u32 Func) + { + C->RS.SetRS(D3DRS_ZFUNC, Func); + return *this; + } + + //adopt_dx10texture _dx10texture (LPCSTR _name) { u32 s = C->r_dx10Texture(_name,0); return adopt_dx10sampler(C,s); } + + adopt_dx10options _dx10Options() { return adopt_dx10options(); }; +}; +#pragma warning( pop ) + +class adopt_blend +{ +public: +}; + +class adopt_cmp_func +{ +public: +}; + +class adopt_stencil_op +{ +public: +}; + +// export +void CResourceManager::LS_Load() +{ + // clang-format off + auto exporterFunc = [](lua_State* luaState) + { + module(luaState) + [ + class_("_dx10options") + .def("dx10_msaa_alphatest_atoc", &adopt_dx10options::_dx10_msaa_alphatest_atoc) + //.def("", &adopt_dx10options::_dx10Options ), // returns options-object + , + + class_("_sampler") + .def(constructor()) + .def("texture", &adopt_sampler::_texture, return_reference_to<1>()) + .def("project", &adopt_sampler::_projective, return_reference_to<1>()) + .def("clamp", &adopt_sampler::_clamp, return_reference_to<1>()) + .def("wrap", &adopt_sampler::_wrap, return_reference_to<1>()) + .def("mirror", &adopt_sampler::_mirror, return_reference_to<1>()) + .def("f_anisotropic", &adopt_sampler::_f_anisotropic, return_reference_to<1>()) + .def("f_trilinear", &adopt_sampler::_f_trilinear, return_reference_to<1>()) + .def("f_bilinear", &adopt_sampler::_f_bilinear, return_reference_to<1>()) + .def("f_linear", &adopt_sampler::_f_linear, return_reference_to<1>()) + .def("f_none", &adopt_sampler::_f_none, return_reference_to<1>()) + .def("fmin_none", &adopt_sampler::_fmin_none, return_reference_to<1>()) + .def("fmin_point", &adopt_sampler::_fmin_point, return_reference_to<1>()) + .def("fmin_linear", &adopt_sampler::_fmin_linear, return_reference_to<1>()) + .def("fmin_aniso", &adopt_sampler::_fmin_aniso, return_reference_to<1>()) + .def("fmip_none", &adopt_sampler::_fmip_none, return_reference_to<1>()) + .def("fmip_point", &adopt_sampler::_fmip_point, return_reference_to<1>()) + .def("fmip_linear", &adopt_sampler::_fmip_linear, return_reference_to<1>()) + .def("fmag_none", &adopt_sampler::_fmag_none, return_reference_to<1>()) + .def("fmag_point", &adopt_sampler::_fmag_point, return_reference_to<1>()) + .def("fmag_linear", &adopt_sampler::_fmag_linear, return_reference_to<1>()) + .def("comp_less", &adopt_sampler::_comp_less, return_reference_to<1>()), + + class_("_compiler") + .def(constructor()) + .def("begin", &adopt_compiler::_pass, return_reference_to<1>()) + .def("begin", &adopt_compiler::_passgs, return_reference_to<1>()) + .def("sorting", &adopt_compiler::_options, return_reference_to<1>()) + .def("emissive", &adopt_compiler::_o_emissive, return_reference_to<1>()) + .def("distort", &adopt_compiler::_o_distort, return_reference_to<1>()) + .def("wmark", &adopt_compiler::_o_wmark, return_reference_to<1>()) + .def("fog", &adopt_compiler::_fog, return_reference_to<1>()) + .def("zb", &adopt_compiler::_ZB, return_reference_to<1>()) + .def("blend", &adopt_compiler::_blend, return_reference_to<1>()) + .def("aref", &adopt_compiler::_aref, return_reference_to<1>()) + // For compatibility only + .def("dx10color_write_enable", &adopt_compiler::_dx10color_write_enable, return_reference_to<1>()) + .def("color_write_enable", &adopt_compiler::_dx10color_write_enable, return_reference_to<1>()) + .def("dx10stencil", &adopt_compiler::_dx10Stencil, return_reference_to<1>()) + .def("dx10stencil_ref", &adopt_compiler::_dx10StencilRef, return_reference_to<1>()) + .def("dx10atoc", &adopt_compiler::_dx10ATOC, return_reference_to<1>()) + .def("dx10zfunc", &adopt_compiler::_dx10ZFunc, return_reference_to<1>()) + .def("sampler", &adopt_compiler::_sampler) // returns sampler-object + .def("dx10Options", &adopt_compiler::_dx10Options), // returns options-object + + + class_("blend") + .enum_("blend") + [ + value("zero", int(D3DBLEND_ZERO)), + value("one", int(D3DBLEND_ONE)), + value("srccolor", int(D3DBLEND_SRCCOLOR)), + value("invsrccolor", int(D3DBLEND_INVSRCCOLOR)), + value("srcalpha", int(D3DBLEND_SRCALPHA)), + value("invsrcalpha", int(D3DBLEND_INVSRCALPHA)), + value("destalpha", int(D3DBLEND_DESTALPHA)), + value("invdestalpha", int(D3DBLEND_INVDESTALPHA)), + value("destcolor", int(D3DBLEND_DESTCOLOR)), + value("invdestcolor", int(D3DBLEND_INVDESTCOLOR)), + value("srcalphasat", int(D3DBLEND_SRCALPHASAT)) + ], + + class_("cmp_func") + .enum_("cmp_func") + [ + value("never", int(D3DCMP_NEVER)), + value("less", int(D3DCMP_LESS)), + value("equal", int(D3DCMP_EQUAL)), + value("lessequal", int(D3DCMP_LESSEQUAL)), + value("greater", int(D3DCMP_GREATER)), + value("notequal", int(D3DCMP_NOTEQUAL)), + value("greaterequal", int(D3DCMP_GREATEREQUAL)), + value("always", int(D3DCMP_ALWAYS)) + ], + + class_("stencil_op") + .enum_("stencil_op") + [ + value("keep", int(D3DSTENCILOP_KEEP)), + value("zero", int(D3DSTENCILOP_ZERO)), + value("replace", int(D3DSTENCILOP_REPLACE)), + value("incrsat", int(D3DSTENCILOP_INCRSAT)), + value("decrsat", int(D3DSTENCILOP_DECRSAT)), + value("invert", int(D3DSTENCILOP_INVERT)), + value("incr", int(D3DSTENCILOP_INCR)), + value("decr", int(D3DSTENCILOP_DECR)) + ] + ]; + }; + // clang-format on + + ScriptEngine.init(exporterFunc, false); + // load shaders + const char* shaderPath = RImplementation.getShaderPath(); + xr_vector* folder = FS.file_list_open("$game_shaders$", shaderPath, FS_ListFiles | FS_RootOnly); + R_ASSERT3(folder, "Shader folder not found: ", shaderPath); + for (u32 it = 0; it < folder->size(); it++) + { + string_path namesp, fn; + xr_strcpy(namesp, (*folder)[it]); + if (nullptr == strext(namesp) || 0 != xr_strcmp(strext(namesp), ".s")) continue; + *strext(namesp) = 0; + if (0 == namesp[0]) xr_strcpy(namesp, ScriptEngine.GlobalNamespace); + strconcat(sizeof fn, fn, shaderPath, (*folder)[it]); + FS.update_path(fn, "$game_shaders$", fn); + ScriptEngine.load_file_into_namespace(fn, namesp); + } + FS.file_list_close(folder); +} + +void CResourceManager::LS_Unload() { ScriptEngine.unload(); } + +BOOL CResourceManager::_lua_HasShader(LPCSTR s_shader) +{ + string256 undercorated; + for (int i = 0, l = xr_strlen(s_shader) + 1; i < l; i++) + undercorated[i] = '\\' == s_shader[i] ? '_' : s_shader[i]; + + ScopeLock scope(&ScriptEngineLock); +#ifdef _EDITOR + return ScriptEngine.object(undercorated,"editor",LUA_TFUNCTION); +#else + return ScriptEngine.object(undercorated, "normal",LUA_TFUNCTION) || + ScriptEngine.object(undercorated, "l_special",LUA_TFUNCTION); +#endif +} + +Shader* CResourceManager::_lua_Create(LPCSTR d_shader, LPCSTR s_textures) +{ + CBlender_Compile C; + Shader S; + + // undecorate + string256 undercorated; + for (int i = 0, l = xr_strlen(d_shader) + 1; i < l; i++) + undercorated[i] = '\\' == d_shader[i] ? '_' : d_shader[i]; + LPCSTR s_shader = undercorated; + + // Access to template + C.BT = nullptr; + C.bEditor = false; + C.bDetail = false; + + // Prepare + _ParseList(C.L_textures, s_textures); + C.detail_texture = nullptr; + C.detail_scaler = nullptr; + + ScriptEngineLock.Enter(); + // Compile element (LOD0 - HQ) + if (ScriptEngine.object(s_shader, "normal_hq",LUA_TFUNCTION)) + { + // Analyze possibility to detail this shader + C.iElement = 0; + C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); + + if (C.bDetail) S.E[0] = C._lua_Compile(s_shader, "normal_hq"); + else S.E[0] = C._lua_Compile(s_shader, "normal"); + } + else + { + if (ScriptEngine.object(s_shader, "normal",LUA_TFUNCTION)) + { + C.iElement = 0; + C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); + S.E[0] = C._lua_Compile(s_shader, "normal"); + } + } + + // Compile element (LOD1) + if (ScriptEngine.object(s_shader, "normal",LUA_TFUNCTION)) + { + C.iElement = 1; + C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); + S.E[1] = C._lua_Compile(s_shader, "normal"); + } + + // Compile element + if (ScriptEngine.object(s_shader, "l_point",LUA_TFUNCTION)) + { + C.iElement = 2; + C.bDetail = false; + S.E[2] = C._lua_Compile(s_shader, "l_point"); + } + + // Compile element + if (ScriptEngine.object(s_shader, "l_spot",LUA_TFUNCTION)) + { + C.iElement = 3; + C.bDetail = false; + S.E[3] = C._lua_Compile(s_shader, "l_spot"); + } + + // Compile element + if (ScriptEngine.object(s_shader, "l_special",LUA_TFUNCTION)) + { + C.iElement = 4; + C.bDetail = false; + S.E[4] = C._lua_Compile(s_shader, "l_special"); + } + ScriptEngineLock.Leave(); + + ScopeLock scope(&v_shaders_lock); + // Search equal in shaders array + for (Shader* v_shader : v_shaders) + if (S.equal(v_shader)) + return v_shader; + + // Create _new_ entry + Shader* N = v_shaders.emplace_back(xr_new(S)); + N->dwFlags |= xr_resource_flagged::RF_REGISTERED; + return N; +} + +ShaderElement* CBlender_Compile::_lua_Compile(LPCSTR namesp, LPCSTR name) +{ + ShaderElement E; + SH = &E; + RS.Invalidate(); + + // Compile + LPCSTR t_0 = *L_textures[0] ? *L_textures[0] : "null"; + LPCSTR t_1 = L_textures.size() > 1 ? *L_textures[1] : "null"; + LPCSTR t_d = detail_texture ? detail_texture : "null"; + object shader = RImplementation.Resources->ScriptEngine.name_space(namesp); + functor element = object_cast>(shader[name]); + bool bFirstPass = false; + adopt_compiler ac = adopt_compiler(this, bFirstPass); + element(ac, t_0, t_1, t_d); + r_End(); + ShaderElement* _r = RImplementation.Resources->_CreateElement(std::move(E)); + return _r; +} diff --git a/src/Layers/xrRenderGLR1/glSH_RT.cpp b/src/Layers/xrRenderGLR1/glSH_RT.cpp new file mode 100755 index 00000000000..be92392d77e --- /dev/null +++ b/src/Layers/xrRenderGLR1/glSH_RT.cpp @@ -0,0 +1,121 @@ +#include "stdafx.h" +#pragma hdrstop + +#include "../xrRender/ResourceManager.h" +#include "glTextureUtils.h" + +CRT::CRT() +{ + pRT = 0; + dwWidth = 0; + dwHeight = 0; + fmt = D3DFMT_UNKNOWN; +} + +CRT::~CRT() +{ + destroy(); + + // release external reference + RImplementation.Resources->_DeleteRT(this); +} + +bool CRT::used_as_depth() const +{ + switch (fmt) + { + case D3DFMT_D16: + case D3DFMT_D16_LOCKABLE: + case D3DFMT_D15S1: + case D3DFMT_D24X8: + case D3DFMT_D24S8: + case MAKEFOURCC('D', 'F', '2', '4'): + return true; + default: + return false; + } +} + +void CRT::create(LPCSTR Name, u32 w, u32 h, D3DFORMAT f, u32 SampleCount /*= 1*/, Flags32 /*flags = {}*/) +{ + if (pRT) return; + + R_ASSERT(Name && Name[0] && w && h); + _order = CPU::QPC(); //Device.GetTimerGlobal()->GetElapsed_clk(); + + //HRESULT _hr; + + dwWidth = w; + dwHeight = h; + fmt = f; + sampleCount = SampleCount; + + // Get caps + GLint max_width, max_height; + CHK_GL(glGetIntegerv(GL_MAX_FRAMEBUFFER_WIDTH, &max_width)); + CHK_GL(glGetIntegerv(GL_MAX_FRAMEBUFFER_HEIGHT, &max_height)); + + // Check width-and-height of render target surface + // XXX: While seemingly silly, assert w/h are positive? + if (w > u32(max_width)) return; + if (h > u32(max_height)) return; + + RImplementation.Resources->Evict(); + + target = (SampleCount > 1) ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D; + glGenTextures(1, &pRT); + CHK_GL(glBindTexture(target, pRT)); + if (SampleCount > 1) + CHK_GL(glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, SampleCount, glTextureUtils::ConvertTextureFormat(fmt), w, + h, GL_FALSE)); + else + CHK_GL(glTexStorage2D(GL_TEXTURE_2D, 1, glTextureUtils::ConvertTextureFormat(fmt), w, h)); + + pTexture = RImplementation.Resources->_CreateTexture(Name); + pTexture->surface_set(target, pRT); + + // OpenGL doesn't differentiate between color and depth targets + pZRT = pRT; +} + +void CRT::destroy() +{ + if (pTexture._get()) + { + pTexture->surface_set(target, 0); + pTexture = nullptr; + } + CHK_GL(glDeleteTextures(1, &pRT)); +} + +void CRT::reset_begin() +{ + destroy(); +} + +void CRT::reset_end() +{ + create(*cName, dwWidth, dwHeight, fmt, sampleCount, { dwFlags }); +} + +void CRT::resolve_into(CRT& destination) const +{ + glReadBuffer(GL_COLOR_ATTACHMENT0); + glDrawBuffer(GL_COLOR_ATTACHMENT1); + + constexpr GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; + RCache.set_RT(pRT, 0); + RCache.set_RT(destination.pRT, 1); + + const GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + VERIFY(status == GL_FRAMEBUFFER_COMPLETE); + CHK_GL(glDrawBuffers(std::size(buffers), buffers)); + + CHK_GL(glBlitFramebuffer(0, 0, dwWidth, dwHeight, 0, 0, destination.dwWidth, destination.dwHeight, + GL_COLOR_BUFFER_BIT, GL_NEAREST)); +} + +void resptrcode_crt::create(LPCSTR Name, u32 w, u32 h, D3DFORMAT f, u32 SampleCount /*= 1*/, Flags32 flags /*= {}*/) +{ + _set(RImplementation.Resources->_CreateRT(Name, w, h, f, SampleCount, flags)); +} diff --git a/src/Layers/xrRenderGLR1/glSH_Texture.cpp b/src/Layers/xrRenderGLR1/glSH_Texture.cpp new file mode 100755 index 00000000000..cd9ec41ab64 --- /dev/null +++ b/src/Layers/xrRenderGLR1/glSH_Texture.cpp @@ -0,0 +1,362 @@ +#include "stdafx.h" +#pragma hdrstop + +#include "../xrRender/ResourceManager.h" + +#ifdef XR_PLATFORM_WINDOWS // TODO +#include "xrEngine/tntQAVI.h" +#endif +#include "xrEngine/xrTheora_Surface.h" + +#define PRIORITY_HIGH 12 +#define PRIORITY_NORMAL 8 +#define PRIORITY_LOW 4 + +void resptrcode_texture::create(LPCSTR _name) +{ + _set(RImplementation.Resources->_CreateTexture(_name)); +} + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// +CTexture::CTexture() +{ + pSurface = 0; + pBuffer = 0; + pAVI = nullptr; + pTheora = nullptr; + desc = GL_TEXTURE_2D; + desc_cache = 0; + seqMSPF = 0; + flags.MemoryUsage = 0; + flags.bLoaded = false; + flags.bUser = false; + flags.seqCycles = FALSE; + m_material = 1.0f; + bind = fastdelegate::FastDelegate1(this, &CTexture::apply_load); +} + +CTexture::~CTexture() +{ + Unload(); + // release external reference + RImplementation.Resources->_DeleteTexture(this); +} + +void CTexture::surface_set(GLenum target, GLuint surf) +{ + desc = target; + pSurface = surf; +} + +GLuint CTexture::surface_get() +{ + return pSurface; +} + +void CTexture::PostLoad() +{ + if (pTheora) bind = fastdelegate::FastDelegate1(this, &CTexture::apply_theora); + else if (pAVI) bind = fastdelegate::FastDelegate1(this, &CTexture::apply_avi); + else if (!seqDATA.empty()) bind = fastdelegate::FastDelegate1(this, &CTexture::apply_seq); + else bind = fastdelegate::FastDelegate1(this, &CTexture::apply_normal); +} + +void CTexture::apply_load(u32 dwStage) +{ + CHK_GL(glActiveTexture(GL_TEXTURE0 + dwStage)); + if (!flags.bLoaded) Load(); + else PostLoad(); + bind(dwStage); +}; + +void CTexture::apply_theora(u32 dwStage) +{ + CHK_GL(glActiveTexture(GL_TEXTURE0 + dwStage)); + CHK_GL(glBindTexture(desc, pSurface)); + + if (pTheora->Update(m_play_time != 0xFFFFFFFF ? m_play_time : Device.dwTimeContinual)) + { + u32* pBits; + u32 _w = pTheora->Width(true); + u32 _h = pTheora->Height(true); + + // Clear and map buffer for writing + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pBuffer); + CHK_GL(glBufferData(GL_PIXEL_UNPACK_BUFFER, _w * _h * 4, nullptr, GL_STREAM_DRAW)); // Invalidate buffer + CHK_GL(pBits = (u32*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY)); + + // Write to the buffer and copy it to the texture + int _pos = 0; + pTheora->DecompressFrame(pBits, 0, _pos); + CHK_GL(glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER)); + CHK_GL(glTexSubImage2D(desc, 0, 0, 0, _w, _h, GL_BGRA, GL_UNSIGNED_BYTE, nullptr)); + + // Unmap the buffer to restore normal texture functionality + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + } +}; + +void CTexture::apply_avi(u32 dwStage) +{ + CHK_GL(glActiveTexture(GL_TEXTURE0 + dwStage)); + CHK_GL(glBindTexture(desc, pSurface)); + +#ifdef XR_PLATFORM_WINDOWS // TODO + if (pAVI->NeedUpdate()) + { + // AVI + u8* ptr{}; + pAVI->GetFrame(&ptr); + CHK_GL(glTexSubImage2D(desc, 0, 0, 0, m_width, m_height, + GL_RGBA, GL_UNSIGNED_BYTE, ptr)); + } +#endif +}; + +void CTexture::apply_seq(u32 dwStage) +{ + // SEQ + u32 frame = Device.dwTimeContinual / seqMSPF; //Device.dwTimeGlobal + u32 frame_data = seqDATA.size(); + if (flags.seqCycles) + { + u32 frame_id = frame % (frame_data * 2); + if (frame_id >= frame_data) frame_id = frame_data - 1 - frame_id % frame_data; + pSurface = seqDATA[frame_id]; + } + else + { + u32 frame_id = frame % frame_data; + pSurface = seqDATA[frame_id]; + } + + CHK_GL(glActiveTexture(GL_TEXTURE0 + dwStage)); + CHK_GL(glBindTexture(desc, pSurface)); +}; + +void CTexture::apply_normal(u32 dwStage) +{ + CHK_GL(glActiveTexture(GL_TEXTURE0 + dwStage)); + CHK_GL(glBindTexture(desc, pSurface)); +}; + +void CTexture::Preload() +{ + m_bumpmap = RImplementation.Resources->m_textures_description.GetBumpName(cName); + m_material = RImplementation.Resources->m_textures_description.GetMaterial(cName); +} + +void CTexture::Load() +{ + flags.bLoaded = true; + desc_cache = 0; + if (pSurface) return; + + flags.bUser = false; + flags.MemoryUsage = 0; + if (nullptr == *cName) + return; + if (0 == xr_stricmp(*cName, "$null")) return; + // we need to check only the beginning of the string, + // so let's use strncmp instead of strstr. + if (0 == strncmp(cName.c_str(), "$user$", sizeof("$user$") - 1)) + { + flags.bUser = true; + return; + } + + Preload(); + + bool bCreateView = true; + + // Check for OGM + string_path fn; + if (FS.exist(fn, "$game_textures$", *cName, ".ogm")) + { + // AVI + pTheora = xr_new(); + m_play_time = 0xFFFFFFFF; + + if (!pTheora->Load(fn)) + { + xr_delete(pTheora); + FATAL("Can't open video stream"); + } + else + { + flags.MemoryUsage = pTheora->Width(true) * pTheora->Height(true) * 4; + pTheora->Play(TRUE, Device.dwTimeContinual); + + // Now create texture + GLuint pTexture = 0; + u32 _w = pTheora->Width(false); + u32 _h = pTheora->Height(false); + + glGenBuffers(1, &pBuffer); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pBuffer); + CHK_GL(glBufferData(GL_PIXEL_UNPACK_BUFFER, flags.MemoryUsage, nullptr, GL_STREAM_DRAW)); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + + glGenTextures(1, &pTexture); + glBindTexture(GL_TEXTURE_2D, pTexture); + CHK_GL(glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, _w, _h)); + + pSurface = pTexture; + desc = GL_TEXTURE_2D; + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + { + Msg("Invalid video stream: 0x%x", err); + xr_delete(pTheora); + pSurface = 0; + } + } + } + else if (FS.exist(fn, "$game_textures$", *cName, ".avi")) + { +#ifdef XR_PLATFORM_WINDOWS // TODO + // AVI + pAVI = xr_new(); + + if (!pAVI->Load(fn)) + { + xr_delete(pAVI); + FATAL("Can't open video stream"); + } + else + { + flags.MemoryUsage = pAVI->m_dwWidth * pAVI->m_dwHeight * 4; + + // Create pixel buffer object + glGenBuffers(1, &pBuffer); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pBuffer); + CHK_GL(glBufferData(GL_PIXEL_UNPACK_BUFFER, flags.MemoryUsage, nullptr, GL_STREAM_DRAW)); + + // Now create texture to copy PBO into + GLuint pTexture = 0; + glGenTextures(1, &pTexture); + glBindTexture(GL_TEXTURE_2D, pTexture); + CHK_GL(glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, pAVI->m_dwWidth, pAVI->m_dwHeight)); + + pSurface = pTexture; + desc = GL_TEXTURE_2D; + if (glGetError() != GL_NO_ERROR) + { + FATAL("Invalid video stream"); + xr_delete(pAVI); + pSurface = 0; + } + } +#endif + } + else if (FS.exist(fn, "$game_textures$", *cName, ".seq")) + { + // Sequence + string256 buffer; + IReader* _fs = FS.r_open(fn); + + flags.seqCycles = FALSE; + _fs->r_string(buffer, sizeof buffer); + if (0 == xr_stricmp(buffer, "cycled")) + { + flags.seqCycles = TRUE; + _fs->r_string(buffer, sizeof buffer); + } + u32 fps = atoi(buffer); + seqMSPF = 1000 / fps; + + while (!_fs->eof()) + { + _fs->r_string(buffer, sizeof buffer); + _Trim(buffer); + if (buffer[0]) + { + // Load another texture + u32 mem = 0; + pSurface = RImplementation.texture_load(buffer, mem, desc); + if (pSurface) + { + // pSurface->SetPriority (PRIORITY_LOW); + seqDATA.push_back(pSurface); + flags.MemoryUsage += mem; + } + } + } + pSurface = 0; + FS.r_close(_fs); + } + else + { + // Normal texture + u32 mem = 0; + pSurface = RImplementation.texture_load(*cName, mem, desc); + + // Calc memory usage and preload into vid-mem + if (pSurface) + { + // pSurface->SetPriority (PRIORITY_NORMAL); + flags.MemoryUsage = mem; + } + } + + PostLoad(); +} + +void CTexture::Unload() +{ +#ifdef DEBUG + string_path msg_buff; + sprintf_s(msg_buff, sizeof(msg_buff), "* Unloading texture [%s] pSurface ID=%d", cName.c_str(), pSurface); +#endif // DEBUG + + //. if (flags.bLoaded) Msg ("* Unloaded: %s",cName.c_str()); + + flags.bLoaded = FALSE; + if (!seqDATA.empty()) + { + CHK_GL(glDeleteTextures(seqDATA.size(), seqDATA.data())); + seqDATA.clear(); + pSurface = 0; + } + + CHK_GL(glDeleteTextures(1, &pSurface)); + CHK_GL(glDeleteBuffers(1, &pBuffer)); + + xr_delete(pAVI); + xr_delete(pTheora); + + bind = fastdelegate::FastDelegate1(this, &CTexture::apply_load); +} + +void CTexture::desc_update() +{ + desc_cache = pSurface; + if (pSurface && (GL_TEXTURE_2D == desc || GL_TEXTURE_2D_MULTISAMPLE == desc)) + { + glBindTexture(desc, pSurface); + CHK_GL(glGetTexLevelParameteriv(desc, 0, GL_TEXTURE_WIDTH, &m_width)); + CHK_GL(glGetTexLevelParameteriv(desc, 0, GL_TEXTURE_HEIGHT, &m_height)); + } +} + +void CTexture::video_Play(BOOL looped, u32 _time) +{ + if (pTheora) pTheora->Play(looped, _time != 0xFFFFFFFF ? (m_play_time = _time) : Device.dwTimeContinual); +} + +void CTexture::video_Pause(BOOL state) +{ + if (pTheora) pTheora->Pause(state); +} + +void CTexture::video_Stop() +{ + if (pTheora) pTheora->Stop(); +} + +BOOL CTexture::video_IsPlaying() +{ + return pTheora ? pTheora->IsPlaying() : FALSE; +} diff --git a/src/Layers/xrRenderGLR1/glState.cpp b/src/Layers/xrRenderGLR1/glState.cpp new file mode 100755 index 00000000000..4c6c244777c --- /dev/null +++ b/src/Layers/xrRenderGLR1/glState.cpp @@ -0,0 +1,274 @@ +#include "stdafx.h" +#include "glState.h" + +glState::glState() +{ + // Clear the sampler array + memset(m_samplerArray, 0, CTexture::mtMaxCombinedShaderTextures * sizeof(GLuint)); + + rasterizerCullMode = D3DCULL_CCW; + + m_pDepthStencilState.DepthEnable = TRUE; + m_pDepthStencilState.DepthFunc = D3DCMP_LESSEQUAL; + m_pDepthStencilState.DepthWriteMask = TRUE; + m_pDepthStencilState.StencilEnable = TRUE; + m_pDepthStencilState.StencilFailOp = D3DSTENCILOP_KEEP; + m_pDepthStencilState.StencilDepthFailOp = D3DSTENCILOP_KEEP; + m_pDepthStencilState.StencilPassOp = D3DSTENCILOP_KEEP; + m_pDepthStencilState.StencilFunc = D3DCMP_ALWAYS; + m_pDepthStencilState.StencilMask = 0xFFFFFFFF; + m_pDepthStencilState.StencilWriteMask = 0xFFFFFFFF; + m_pDepthStencilState.StencilRef = 0; + + m_pBlendState.BlendEnable = TRUE; + m_pBlendState.SrcBlend = D3DBLEND_ONE; + m_pBlendState.DestBlend = D3DBLEND_ZERO; + m_pBlendState.SrcBlendAlpha = D3DBLEND_ONE; + m_pBlendState.DestBlendAlpha = D3DBLEND_ZERO; + m_pBlendState.BlendOp = D3DBLENDOP_ADD; + m_pBlendState.BlendOpAlpha = D3DBLENDOP_ADD; + m_pBlendState.ColorMask = 0xF; + + m_uiMipLODBias = FLT_MAX; +} + +glState* glState::Create() +{ + return xr_new(); +} + +// TODO: OGL: Does the render cache provide enough state management? +void glState::Apply() +{ + // TODO: OGL: Use glBindSamplers if ARB_multi_bind is supported. + for (size_t stage = 0; stage < CTexture::mtMaxCombinedShaderTextures; stage++) + { + if (m_samplerArray[stage]) + { + glBindSampler(stage, m_samplerArray[stage]); + + if (!fsimilar(m_uiMipLODBias, ps_r__tf_Mipbias)) + { + CHK_GL(glSamplerParameterf(m_samplerArray[stage], GL_TEXTURE_MIN_LOD, 0.f)); + CHK_GL(glSamplerParameterf(m_samplerArray[stage], GL_TEXTURE_MAX_LOD, FLT_MAX)); + CHK_GL(glSamplerParameterf(m_samplerArray[stage], GL_TEXTURE_LOD_BIAS, ps_r__tf_Mipbias)); + } + } + } + + m_uiMipLODBias = ps_r__tf_Mipbias; + + RCache.set_CullMode(rasterizerCullMode); + RCache.set_Z(m_pDepthStencilState.DepthEnable); + RCache.set_ZFunc(m_pDepthStencilState.DepthFunc); + RCache.set_Stencil( + m_pDepthStencilState.StencilEnable, + m_pDepthStencilState.StencilFunc, + m_pDepthStencilState.StencilRef, + m_pDepthStencilState.StencilMask, + m_pDepthStencilState.StencilWriteMask, + m_pDepthStencilState.StencilFailOp, + m_pDepthStencilState.StencilPassOp, + m_pDepthStencilState.StencilDepthFailOp + ); + + CHK_GL(glDepthMask(m_pDepthStencilState.DepthWriteMask ? GL_TRUE : GL_FALSE)); + + if (m_pBlendState.BlendEnable) + glEnable(GL_BLEND); + else + glDisable(GL_BLEND); + + CHK_GL(glBlendFuncSeparate( + glStateUtils::ConvertBlendArg(m_pBlendState.SrcBlend), + glStateUtils::ConvertBlendArg(m_pBlendState.DestBlend), + glStateUtils::ConvertBlendArg(m_pBlendState.SrcBlendAlpha), + glStateUtils::ConvertBlendArg(m_pBlendState.DestBlendAlpha) + )); + CHK_GL(glBlendEquationSeparate( + glStateUtils::ConvertBlendOp(m_pBlendState.BlendOp), + glStateUtils::ConvertBlendOp(m_pBlendState.BlendOpAlpha) + )); + + RCache.set_ColorWriteEnable(m_pBlendState.ColorMask); +} + +void glState::Release() +{ + // Delete any generated samplers in the array + CHK_GL(glDeleteSamplers(CTexture::mtMaxCombinedShaderTextures, m_samplerArray)); + + // Clear the sampler array + memset(m_samplerArray, 0, CTexture::mtMaxCombinedShaderTextures * sizeof(GLuint)); + + glState* pState = this; + xr_delete(pState); +} + +void glState::UpdateRenderState(u32 name, u32 value) +{ + switch (name) + { + case D3DRS_CULLMODE: + rasterizerCullMode = (D3DCULL)value; + break; + + case D3DRS_ZENABLE: + m_pDepthStencilState.DepthEnable = value ? TRUE : FALSE; + break; + + case D3DRS_ZWRITEENABLE: + m_pDepthStencilState.DepthWriteMask = value ? TRUE : FALSE; + break; + + case D3DRS_ZFUNC: + m_pDepthStencilState.DepthFunc = (D3DCMPFUNC)value; + break; + + case D3DRS_STENCILENABLE: + m_pDepthStencilState.StencilEnable = value ? TRUE : FALSE; + break; + + case D3DRS_STENCILMASK: + m_pDepthStencilState.StencilMask = (u32)value; + break; + + case D3DRS_STENCILWRITEMASK: + m_pDepthStencilState.StencilWriteMask = (u32)value; + break; + + case D3DRS_STENCILFAIL: + m_pDepthStencilState.StencilFailOp = (D3DSTENCILOP)value; + break; + + case D3DRS_STENCILZFAIL: + m_pDepthStencilState.StencilDepthFailOp = (D3DSTENCILOP)value; + break; + + case D3DRS_STENCILPASS: + m_pDepthStencilState.StencilPassOp = (D3DSTENCILOP)value; + break; + + case D3DRS_STENCILFUNC: + m_pDepthStencilState.StencilFunc = (D3DCMPFUNC)value; + break; + + case D3DRS_STENCILREF: + m_pDepthStencilState.StencilRef = value; + break; + + case D3DRS_SRCBLEND: + m_pBlendState.SrcBlend = (D3DBLEND)value; + break; + + case D3DRS_DESTBLEND: + m_pBlendState.DestBlend = (D3DBLEND)value; + break; + + case D3DRS_BLENDOP: + m_pBlendState.BlendOp = (D3DBLENDOP)value; + break; + + case D3DRS_SRCBLENDALPHA: + m_pBlendState.SrcBlendAlpha = (D3DBLEND)value; + break; + + case D3DRS_DESTBLENDALPHA: + m_pBlendState.DestBlendAlpha = (D3DBLEND)value; + break; + + case D3DRS_BLENDOPALPHA: + m_pBlendState.BlendOpAlpha = (D3DBLENDOP)value; + break; + + case D3DRS_ALPHABLENDENABLE: + m_pBlendState.BlendEnable = value ? TRUE : FALSE; + break; + + case D3DRS_COLORWRITEENABLE: + case D3DRS_COLORWRITEENABLE1: + case D3DRS_COLORWRITEENABLE2: + case D3DRS_COLORWRITEENABLE3: + m_pBlendState.ColorMask = (u32)value; + break; + + case D3DRS_LIGHTING: + case D3DRS_FOGENABLE: + case D3DRS_ALPHATESTENABLE: + case D3DRS_ALPHAREF: + // Deprecated + break; + + default: + VERIFY(!"Render state not implemented"); + break; + } +} + +void glState::UpdateSamplerState(u32 stage, u32 name, u32 value) +{ + if (stage < 0 || stage >= CTexture::mtMaxCombinedShaderTextures) + return; + + GLint currentFilter = (GLint)GL_NEAREST; + + if (m_samplerArray[stage] == 0) + glGenSamplers(1, &m_samplerArray[stage]); + else if (name == D3DSAMP_MINFILTER || name == D3DSAMP_MIPFILTER) + glGetSamplerParameteriv(m_samplerArray[stage], GL_TEXTURE_MIN_FILTER, ¤tFilter); + + switch (name) + { + case D3DSAMP_ADDRESSU: /* D3DTEXTUREADDRESS for U coordinate */ + CHK_GL(glSamplerParameteri(m_samplerArray[stage], GL_TEXTURE_WRAP_S, glStateUtils::ConvertTextureAddressMode( + value))); + break; + case D3DSAMP_ADDRESSV: /* D3DTEXTUREADDRESS for V coordinate */ + CHK_GL(glSamplerParameteri(m_samplerArray[stage], GL_TEXTURE_WRAP_T, glStateUtils::ConvertTextureAddressMode( + value))); + break; + case D3DSAMP_ADDRESSW: /* D3DTEXTUREADDRESS for W coordinate */ + CHK_GL(glSamplerParameteri(m_samplerArray[stage], GL_TEXTURE_WRAP_R, glStateUtils::ConvertTextureAddressMode( + value))); + break; + case D3DSAMP_BORDERCOLOR: /* D3DCOLOR */ + { + GLuint color[] = {color_get_R(value), color_get_G(value), color_get_B(value), color_get_A(value)}; + CHK_GL(glSamplerParameterIuiv(m_samplerArray[stage], GL_TEXTURE_BORDER_COLOR, color)); + } + break; + case D3DSAMP_MAGFILTER: /* D3DTEXTUREFILTER filter to use for magnification */ + CHK_GL(glSamplerParameteri(m_samplerArray[stage], GL_TEXTURE_MAG_FILTER, glStateUtils::ConvertTextureFilter( + value))); + break; + case D3DSAMP_MINFILTER: /* D3DTEXTUREFILTER filter to use for minification */ + CHK_GL(glSamplerParameteri(m_samplerArray[stage], GL_TEXTURE_MIN_FILTER, glStateUtils::ConvertTextureFilter( + value, currentFilter))); + break; + case D3DSAMP_MIPFILTER: /* D3DTEXTUREFILTER filter to use between mipmaps during minification */ + CHK_GL(glSamplerParameteri(m_samplerArray[stage], GL_TEXTURE_MIN_FILTER, glStateUtils::ConvertTextureFilter( + value, currentFilter, true))); + break; + case D3DSAMP_MIPMAPLODBIAS: /* float Mipmap LOD bias */ + CHK_GL(glSamplerParameterf(m_samplerArray[stage], GL_TEXTURE_LOD_BIAS, value)); + break; + case D3DSAMP_MAXMIPLEVEL: /* DWORD 0..(n-1) LOD index of largest map to use (0 == largest) */ + CHK_GL(glSamplerParameteri(m_samplerArray[stage], GL_TEXTURE_MAX_LEVEL, value)); + break; + case D3DSAMP_MAXANISOTROPY: /* DWORD maximum anisotropy */ + CHK_GL(glSamplerParameteri(m_samplerArray[stage], GL_TEXTURE_MAX_ANISOTROPY_EXT, value)); + break; + /* + case XRDX10SAMP_COMPARISONFILTER: + CHK_GL(glSamplerParameteri(m_samplerArray[stage], GL_TEXTURE_COMPARE_MODE, value ? (GLint) + GL_COMPARE_REF_TO_TEXTURE : (GLint)GL_NONE)); + break; + case XRDX10SAMP_COMPARISONFUNC: + CHK_GL(glSamplerParameteri(m_samplerArray[stage], GL_TEXTURE_COMPARE_FUNC, value)); + break; + */ + default: + VERIFY(!"Sampler state not implemented"); + break; + } +} diff --git a/src/Layers/xrRenderGLR1/glState.h b/src/Layers/xrRenderGLR1/glState.h new file mode 100755 index 00000000000..f245fbed6aa --- /dev/null +++ b/src/Layers/xrRenderGLR1/glState.h @@ -0,0 +1,52 @@ +#pragma once + +#include "../xrRender/SH_Texture.h" + +typedef struct +{ + BOOL DepthEnable; + BOOL DepthWriteMask; + D3DCMPFUNC DepthFunc; + BOOL StencilEnable; + u32 StencilMask; + u32 StencilWriteMask; + D3DSTENCILOP StencilFailOp; + D3DSTENCILOP StencilDepthFailOp; + D3DSTENCILOP StencilPassOp; + D3DCMPFUNC StencilFunc; + u32 StencilRef; +} D3D_DEPTH_STENCIL_STATE; + +typedef struct +{ + BOOL BlendEnable; + D3DBLEND SrcBlend; + D3DBLEND DestBlend; + D3DBLENDOP BlendOp; + D3DBLEND SrcBlendAlpha; + D3DBLEND DestBlendAlpha; + D3DBLENDOP BlendOpAlpha; + u32 ColorMask; +} D3D_BLEND_STATE; + +class glState +{ +private: + D3DCULL rasterizerCullMode; + D3D_DEPTH_STENCIL_STATE m_pDepthStencilState; + D3D_BLEND_STATE m_pBlendState; + float m_uiMipLODBias; + + GLuint m_samplerArray[CTexture::mtMaxCombinedShaderTextures]; + +public: + glState(); + + static glState* Create(); + + void Apply(); + void Release(); + + void UpdateRenderState(u32 name, u32 value); + void UpdateSamplerState(u32 stage, u32 name, u32 value); +}; diff --git a/src/Layers/xrRenderGLR1/glStateUtils.cpp b/src/Layers/xrRenderGLR1/glStateUtils.cpp new file mode 100755 index 00000000000..88b81c253b6 --- /dev/null +++ b/src/Layers/xrRenderGLR1/glStateUtils.cpp @@ -0,0 +1,205 @@ +#include "stdafx.h" +#include "glStateUtils.h" + +namespace glStateUtils +{ +GLenum ConvertFillMode(u32 Mode) +{ + switch (Mode) + { + case D3DFILL_POINT: + return GL_POINT; + case D3DFILL_WIREFRAME: + return GL_LINE; + case D3DFILL_SOLID: + return GL_FILL; + default: + VERIFY(!"Unexpected fill mode!"); + return GL_FILL; + } +} + +GLenum ConvertCullMode(u32 Mode) +{ + switch (Mode) + { + //case D3DCULL_NONE: + // return ; + case D3DCULL_CW: + return GL_BACK; + case D3DCULL_CCW: + return GL_FRONT; + default: + VERIFY(!"Unexpected cull mode!"); + return GL_FRONT_AND_BACK; + } +} + +GLenum ConvertCmpFunction(u32 Func) +{ + switch (Func) + { + case D3DCMP_NEVER: + return GL_NEVER; + case D3DCMP_LESS: + return GL_LESS; + case D3DCMP_EQUAL: + return GL_EQUAL; + case D3DCMP_LESSEQUAL: + return GL_LEQUAL; + case D3DCMP_GREATER: + return GL_GREATER; + case D3DCMP_NOTEQUAL: + return GL_NOTEQUAL; + case D3DCMP_GREATEREQUAL: + return GL_GEQUAL; + case D3DCMP_ALWAYS: + return GL_ALWAYS; + default: + VERIFY(!"ConvertCmpFunction can't convert argument!"); + return GL_ALWAYS; + } +} + +GLenum ConvertStencilOp(u32 Op) +{ + switch (Op) + { + case D3DSTENCILOP_KEEP: + return GL_KEEP; + case D3DSTENCILOP_ZERO: + return GL_ZERO; + case D3DSTENCILOP_REPLACE: + return GL_REPLACE; + case D3DSTENCILOP_INCRSAT: + return GL_INCR; + case D3DSTENCILOP_DECRSAT: + return GL_DECR; + case D3DSTENCILOP_INVERT: + return GL_INVERT; + case D3DSTENCILOP_INCR: + return GL_INCR_WRAP; + case D3DSTENCILOP_DECR: + return GL_DECR_WRAP; + default: + VERIFY(!"ConvertStencilOp can't convert argument!"); + return GL_KEEP; + } +} + +GLenum ConvertBlendArg(u32 Arg) +{ + switch (Arg) + { + case D3DBLEND_ZERO: + return GL_ZERO; + case D3DBLEND_ONE: + return GL_ONE; + case D3DBLEND_SRCCOLOR: + return GL_SRC_COLOR; + case D3DBLEND_INVSRCCOLOR: + return GL_ONE_MINUS_SRC_COLOR; + case D3DBLEND_SRCALPHA: + return GL_SRC_ALPHA; + case D3DBLEND_INVSRCALPHA: + return GL_ONE_MINUS_SRC_ALPHA; + case D3DBLEND_DESTALPHA: + return GL_DST_ALPHA; + case D3DBLEND_INVDESTALPHA: + return GL_ONE_MINUS_DST_ALPHA; + case D3DBLEND_DESTCOLOR: + return GL_DST_COLOR; + case D3DBLEND_INVDESTCOLOR: + return GL_ONE_MINUS_DST_COLOR; + case D3DBLEND_SRCALPHASAT: + return GL_SRC_ALPHA_SATURATE; + //case D3DBLEND_BOTHSRCALPHA: + // return ; + //case D3DBLEND_BOTHINVSRCALPHA: + // return ; + //case D3DBLEND_BLENDFACTOR: + // return ; + //case D3DBLEND_INVBLENDFACTOR: + // return ; + //case D3DBLEND_SRCCOLOR2: + // return ; + //case D3DBLEND_INVSRCCOLOR2: + // return ; + default: + VERIFY(!"ConvertBlendArg can't convert argument!"); + return GL_ONE; + } +} + +GLenum ConvertBlendOp(u32 Op) +{ + switch (Op) + { + case D3DBLENDOP_ADD: + return GL_FUNC_ADD; + case D3DBLENDOP_SUBTRACT: + return GL_FUNC_SUBTRACT; + case D3DBLENDOP_REVSUBTRACT: + return GL_FUNC_REVERSE_SUBTRACT; + case D3DBLENDOP_MIN: + return GL_MIN; + case D3DBLENDOP_MAX: + return GL_MAX; + default: + VERIFY(!"ConvertBlendOp can't convert argument!"); + return GL_FUNC_ADD; + } +} + +GLint ConvertTextureAddressMode(u32 Mode) +{ + switch (Mode) + { + case D3DTADDRESS_WRAP: + return (GLint)GL_REPEAT; + case D3DTADDRESS_MIRROR: + return (GLint)GL_MIRRORED_REPEAT; + case D3DTADDRESS_CLAMP: + return (GLint)GL_CLAMP_TO_EDGE; + case D3DTADDRESS_BORDER: + return (GLint)GL_CLAMP_TO_BORDER; + //case D3DTADDRESS_MIRRORONCE: + // return ; + default: + VERIFY(!"ConvertTextureAddressMode can't convert argument!"); + return (GLint)GL_CLAMP_TO_EDGE; + } +} + +GLint ConvertTextureFilter(u32 dxFilter, GLint glFilter, bool MipMap) +{ + const u32 FilterLinear = 0x01; + const u32 MipFilterLinear = 0x02; + const u32 MipFilterEnable = 0x100; + + switch (dxFilter) + { + case D3DTEXF_NONE: + if (MipMap) + return glFilter & ~MipFilterLinear & ~MipFilterEnable; + VERIFY(!"D3DTEXF_NONE only supported with D3DSAMP_MIPFILTER"); + return glFilter; + case D3DTEXF_POINT: + { + if (MipMap) + return ((glFilter & ~MipFilterLinear) | MipFilterEnable); + return glFilter & ~FilterLinear; + } + case D3DTEXF_LINEAR: + case D3DTEXF_ANISOTROPIC: + { + if (MipMap) + return glFilter | MipFilterLinear | MipFilterEnable; + return glFilter | FilterLinear; + } + default: + VERIFY(!"ConvertTextureFilter can't convert argument!"); + return glFilter; + } +} +}; diff --git a/src/Layers/xrRenderGLR1/glStateUtils.h b/src/Layers/xrRenderGLR1/glStateUtils.h new file mode 100755 index 00000000000..5da500325a6 --- /dev/null +++ b/src/Layers/xrRenderGLR1/glStateUtils.h @@ -0,0 +1,17 @@ +#pragma once + +#if defined(USE_OGL) || defined(USE_OGLR1) + +namespace glStateUtils +{ +GLenum ConvertFillMode(u32 Mode); +GLenum ConvertCullMode(u32 Mode); +GLenum ConvertCmpFunction(u32 Func); +GLenum ConvertStencilOp(u32 Op); +GLenum ConvertBlendArg(u32 Arg); +GLenum ConvertBlendOp(u32 Op); +GLint ConvertTextureAddressMode(u32 Mode); +GLint ConvertTextureFilter(u32 dxFilter, GLint glFilter = (GLint)GL_NEAREST, bool MipMap = false); +}; + +#endif // USE_OGL diff --git a/src/Layers/xrRenderGLR1/glTextureUtils.cpp b/src/Layers/xrRenderGLR1/glTextureUtils.cpp new file mode 100755 index 00000000000..9b3539ad10a --- /dev/null +++ b/src/Layers/xrRenderGLR1/glTextureUtils.cpp @@ -0,0 +1,112 @@ +#include "stdafx.h" +#include "glTextureUtils.h" + +namespace glTextureUtils +{ +struct TextureFormatPairs +{ + D3DFORMAT m_dx9FMT; + GLenum m_glFMT; +}; + +TextureFormatPairs TextureFormatList[] = +{ + {D3DFMT_UNKNOWN, GL_NONE}, + //D3DFMT_R8G8B8 Not available + {D3DFMT_A8R8G8B8, GL_RGBA8}, // Not available + //D3DFMT_X8R8G8B8 Not available + // TODO: DX10: Remove. Need only for nullrt + //D3DFMT_R5G6B5 Not available + {D3DFMT_R5G6B5, GL_RGBA8}, // Not available + //D3DFMT_X1R5G5B5 Not available + //D3DFMT_A1R5G5B5 Not available + //D3DFMT_A4R4G4B4 Not available + //D3DFMT_R3G3B2 Not available + //D3DFMT_A8 DXGI_FORMAT_A8_UNORM + //D3DFMT_A8R3G3B2 Not available + //D3DFMT_X4R4G4B4 Not available + //D3DFMT_A2B10G10R10 DXGI_FORMAT_R10G10B10A2 + {D3DFMT_A8B8G8R8, GL_RGBA8}, + //D3DFMT_X8B8G8R8 Not available + {D3DFMT_G16R16, GL_RG16}, + //D3DFMT_A2R10G10B10 Not available + {D3DFMT_A16B16G16R16, GL_RGBA16}, + //D3DFMT_A8P8 Not available + //D3DFMT_P8 Not available + {D3DFMT_L8, GL_R8}, // Note: Use .r swizzle in shader to duplicate red to other components to get D3D9 behavior. + //D3DFMT_A8L8 Not available + //D3DFMT_A4L4 Not available + {D3DFMT_V8U8, GL_RG8}, + //D3DFMT_L6V5U5 Not available + //D3DFMT_X8L8V8U8 Not available + {D3DFMT_Q8W8V8U8, GL_RGBA8}, + {D3DFMT_V16U16, GL_RG16}, + //D3DFMT_W11V11U10 Not available + //D3DFMT_A2W10V10U10 Not available + //D3DFMT_UYVY Not available + //D3DFMT_R8G8_B8G8 DXGI_FORMAT_G8R8_G8B8_UNORM (in DX9 the data was scaled up by 255.0f, but this can be handled in shader code). + //D3DFMT_YUY2 Not available + //D3DFMT_G8R8_G8B8 DXGI_FORMAT_R8G8_B8G8_UNORM (in DX9 the data was scaled up by 255.0f, but this can be handled in shader code). + //D3DFMT_DXT1 DXGI_FORMAT_BC1_UNORM & DXGI_FORMAT_BC1_UNORM_SRGB + //D3DFMT_DXT2 DXGI_FORMAT_BC1_UNORM & DXGI_FORMAT_BC1_UNORM_SRGB Note: DXT1 and DXT2 are the same from an API/hardware perspective... only difference was 'premultiplied alpha', which can be tracked by an application and doesn't need a separate format. + //D3DFMT_DXT3 DXGI_FORMAT_BC2_UNORM & DXGI_FORMAT_BC2_UNORM_SRGB + //D3DFMT_DXT4 DXGI_FORMAT_BC2_UNORM & DXGI_FORMAT_BC2_UNORM_SRGB Note: DXT3 and DXT4 are the same from an API/hardware perspective... only difference was 'premultiplied alpha', which can be tracked by an application and doesn't need a separate format. + //D3DFMT_DXT5 DXGI_FORMAT_BC3_UNORM & DXGI_FORMAT_BC3_UNORM_SRGB + //D3DFMT_D16 GL_DEPTH_COMPONENT16 + //D3DFMT_D32 Not available + //D3DFMT_D15S1 Not available + {D3DFMT_D24S8, GL_DEPTH24_STENCIL8}, + {D3DFMT_D24X8, GL_DEPTH24_STENCIL8}, + //D3DFMT_D24X4S4 Not available + //D3DFMT_D16 DXGI_FORMAT_D16_UNORM + //{ D3DFMT_D32F_LOCKABLE, GL_DEPTH_COMPONENT32F }, + //D3DFMT_D24FS8 Not available + //D3DFMT_S1D15 Not available + //D3DFMT_S8D24 GL_DEPTH24_STENCIL8 + //D3DFMT_X8D24 Not available + //D3DFMT_X4S4D24 Not available + //D3DFMT_L16 DXGI_FORMAT_R16_UNORM Note: Use .r swizzle in shader to duplicate red to other components to get D3D9 behavior. + //D3DFMT_INDEX16 DXGI_FORMAT_R16_UINT + //D3DFMT_INDEX32 DXGI_FORMAT_R32_UINT + //D3DFMT_Q16W16V16U16 GL_RGBA16 + //D3DFMT_MULTI2_ARGB8 Not available + //D3DFMT_R16F GL_R16F + {D3DFMT_G16R16F, GL_RG16F}, + {D3DFMT_A16B16G16R16F, GL_RGBA16F}, + {D3DFMT_R32F, GL_R32F}, + {D3DFMT_R16F, GL_R16F}, + //{ D3DFMT_G32R32F, GL_RG32F }, + {D3DFMT_A32B32G32R32F, GL_RGBA32F}, + //D3DFMT_CxV8U8 Not available + //D3DDECLTYPE_FLOAT1 GL_R32F + //D3DDECLTYPE_FLOAT2 GL_RG32F + //D3DDECLTYPE_FLOAT3 GL_RGB32F + //D3DDECLTYPE_FLOAT4 GL_RGBA32F + //D3DDECLTYPED3DCOLOR Not available + //D3DDECLTYPE_UBYTE4 GL_RGBA8 Note: Shader gets UINT values, but if Direct3D 9 style integral floats are needed (0.0f, 1.0f... 255.f), UINT can just be converted to float32 in shader. + //D3DDECLTYPE_SHORT2 GL_RG16 Note: Shader gets SINT values, but if Direct3D 9 style integral floats are needed, SINT can just be converted to float32 in shader. + //D3DDECLTYPE_SHORT4 GL_RGBA16 Note: Shader gets SINT values, but if Direct3D 9 style integral floats are needed, SINT can just be converted to float32 in shader. + //D3DDECLTYPE_UBYTE4N GL_RGBA8 + //D3DDECLTYPE_SHORT2N GL_RG16 + //D3DDECLTYPE_SHORT4N GL_RGBA16 + //D3DDECLTYPE_USHORT2N GL_RG16 + //D3DDECLTYPE_USHORT4N GL_RGBA16 + //D3DDECLTYPE_UDEC3 Not available + //D3DDECLTYPE_DEC3N Not available + //D3DDECLTYPE_FLOAT16_2 GL_RG16 + //D3DDECLTYPE_FLOAT16_4 GL_RGBA16 +}; + +GLenum ConvertTextureFormat(D3DFORMAT dx9FMT) +{ + int arrayLength = sizeof TextureFormatList / sizeof TextureFormatList[0]; + for (int i = 0; i < arrayLength; ++i) + { + if (TextureFormatList[i].m_dx9FMT == dx9FMT) + return TextureFormatList[i].m_glFMT; + } + + VERIFY(!"ConvertTextureFormat didn't find appropriate gl texture format!"); + return GL_NONE; +} +} diff --git a/src/Layers/xrRenderGLR1/glTextureUtils.h b/src/Layers/xrRenderGLR1/glTextureUtils.h new file mode 100755 index 00000000000..2a52d1d1f6a --- /dev/null +++ b/src/Layers/xrRenderGLR1/glTextureUtils.h @@ -0,0 +1,10 @@ +#pragma once + +#if defined(USE_OGL) || defined(USE_OGLR1) + +namespace glTextureUtils +{ +GLenum ConvertTextureFormat(D3DFORMAT dx9FMT); +} + +#endif // USE_OGL diff --git a/src/Layers/xrRenderGLR1/glr_constants_cache.h b/src/Layers/xrRenderGLR1/glr_constants_cache.h new file mode 100755 index 00000000000..f9fe8013389 --- /dev/null +++ b/src/Layers/xrRenderGLR1/glr_constants_cache.h @@ -0,0 +1,175 @@ +#ifndef glr_constants_cacheH +#define glr_constants_cacheH +#pragma once + +class ECORE_API R_constants +{ +private: + // fp, non-array versions + ICF void set(R_constant* C, R_constant_load& L, const Fmatrix& A) + { + VERIFY(RC_float == C->type); + Fvector4 it[4]; + switch (L.cls) + { + case RC_2x4: + it[0].set(A._11, A._21, A._31, A._41); + it[1].set(A._12, A._22, A._32, A._42); + CHK_GL(glProgramUniformMatrix4x2fv(L.program, L.location, 1, GL_TRUE, (float*)&it)); + break; + case RC_3x4: + it[0].set(A._11, A._21, A._31, A._41); + it[1].set(A._12, A._22, A._32, A._42); + it[2].set(A._13, A._23, A._33, A._43); + CHK_GL(glProgramUniformMatrix4x3fv(L.program, L.location, 1, GL_TRUE, (float*)&it)); + break; + case RC_4x4: + it[0].set(A._11, A._21, A._31, A._41); + it[1].set(A._12, A._22, A._32, A._42); + it[2].set(A._13, A._23, A._33, A._43); + it[3].set(A._14, A._24, A._34, A._44); + CHK_GL(glProgramUniformMatrix4fv(L.program, L.location, 1, GL_TRUE, (float*)&it)); + break; + default: +#ifdef DEBUG + xrDebug::Fatal(DEBUG_INFO, "Invalid constant run-time-type for '%s'", *C->name); +#else + NODEFAULT; +#endif + } + } + + ICF void set(R_constant* C, R_constant_load& L, const Fvector4& A) + { + VERIFY(RC_float == C->type); + switch (L.cls) + { + case RC_1x2: + CHK_GL(glProgramUniform2fv(L.program, L.location, 1, (float*)&A)); + break; + case RC_1x3: + CHK_GL(glProgramUniform3fv(L.program, L.location, 1, (float*)&A)); + break; + case RC_1x4: + CHK_GL(glProgramUniform4fv(L.program, L.location, 1, (float*)&A)); + break; + default: +#ifdef DEBUG + xrDebug::Fatal(DEBUG_INFO, "Invalid constant run-time-type for '%s'", *C->name); +#else + NODEFAULT; +#endif + } + } + + ICF void set(R_constant* C, R_constant_load& L, float x, float y, float z, float w) + { + VERIFY(RC_float == C->type); + switch (L.cls) + { + case RC_1x2: + CHK_GL(glProgramUniform2f(L.program, L.location, x, y)); + break; + case RC_1x3: + CHK_GL(glProgramUniform3f(L.program, L.location, x, y, z)); + break; + case RC_1x4: + CHK_GL(glProgramUniform4f(L.program, L.location, x, y, z, w)); + break; + default: +#ifdef DEBUG + xrDebug::Fatal(DEBUG_INFO, "Invalid constant run-time-type for '%s'", *C->name); +#else + NODEFAULT; +#endif + } + } + + // scalars, non-array versions + ICF void set(R_constant* C, R_constant_load& L, float A) + { + VERIFY(RC_float == C->type); + VERIFY(RC_1x1 == L.cls); + CHK_GL(glProgramUniform1f(L.program, L.location, A)); + } + + ICF void set(R_constant* C, R_constant_load& L, int A) + { + VERIFY(RC_int == C->type); + VERIFY(RC_1x1 == L.cls); + CHK_GL(glProgramUniform1i(L.program, L.location, A)); + } + +public: + // fp, non-array versions + ICF void set(R_constant* C, const Fmatrix& A) + { + if (C->destination & RC_dest_pixel) { set(C, C->ps, A); } + if (C->destination & RC_dest_vertex) { set(C, C->vs, A); } + //if (C->destination & RC_dest_geometry) { set(C, C->gs, A); } + } + + ICF void set(R_constant* C, const Fvector4& A) + { + if (C->destination & RC_dest_pixel) { set(C, C->ps, A); } + if (C->destination & RC_dest_vertex) { set(C, C->vs, A); } + //if (C->destination & RC_dest_geometry) { set(C, C->gs, A); } + } + + ICF void set(R_constant* C, float x, float y, float z, float w) + { + if (C->destination & RC_dest_pixel) { set(C, C->ps, x, y, z, w); } + if (C->destination & RC_dest_vertex) { set(C, C->vs, x, y, z, w); } + //if (C->destination & RC_dest_geometry) { set(C, C->gs, x, y, z, w); } + } + + // scalars, non-array versions + ICF void set(R_constant* C, float A) + { + if (C->destination & RC_dest_pixel) { set(C, C->ps, A); } + if (C->destination & RC_dest_vertex) { set(C, C->vs, A); } + //if (C->destination & RC_dest_geometry) { set(C, C->gs, A); } + } + + ICF void set(R_constant* C, int A) + { + if (C->destination & RC_dest_pixel) { set(C, C->ps, A); } + if (C->destination & RC_dest_vertex) { set(C, C->vs, A); } + //if (C->destination & RC_dest_geometry) { set(C, C->gs, A); } + } + + // fp, array versions + ICF void seta(R_constant* C, u32 e, const Fmatrix& A) + { + R_constant_load L; + if (C->destination & RC_dest_pixel) { L = C->ps; } + if (C->destination & RC_dest_vertex) { L = C->vs; } + //if (C->destination & RC_dest_geometry) { L = C->gs; } + L.location += e; + set(C, L, A); + } + + ICF void seta(R_constant* C, u32 e, const Fvector4& A) + { + R_constant_load L; + if (C->destination & RC_dest_pixel) { L = C->ps; } + if (C->destination & RC_dest_vertex) { L = C->vs; } + //if (C->destination & RC_dest_geometry) { L = C->gs; } + L.location += e; + set(C, L, A); + } + + ICF void seta(R_constant* C, u32 e, float x, float y, float z, float w) + { + R_constant_load L; + if (C->destination & RC_dest_pixel) { L = C->ps; } + if (C->destination & RC_dest_vertex) { L = C->vs; } + //if (C->destination & RC_dest_geometry) { L = C->gs; } + L.location += e; + set(C, L, x, y, z, w); + } + + // TODO: OGL: Implement constant caching through UBOs + ICF void flush() { } +}; +#endif // glr_constants_cacheH diff --git a/src/Layers/xrRenderPC_GLR1/CMakeLists.txt b/src/Layers/xrRenderPC_GLR1/CMakeLists.txt new file mode 100755 index 00000000000..eaf9a458455 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/CMakeLists.txt @@ -0,0 +1,361 @@ +project(xrRender_GLR1) + +set(SRC_FILES + "FStaticRender_Blenders.cpp" + "FStaticRender.cpp" + ##"FStaticRender_DetectSector.cpp" + "FStaticRender.h" + "FStaticRender_Loader.cpp" + "FStaticRender_RenderTarget.cpp" + "FStaticRender_RenderTarget.h" + "FStaticRender_Shaders.cpp" + "FStaticRender_Types.h" + "glTexture.cpp" + "GlowManager.cpp" + "GlowManager.h" + "LightPPA.cpp" + "LightPPA.h" + "LightProjector.cpp" + "LightProjector.h" + "LightShadows.cpp" + "LightShadows.h" + "rgl_test_hw.cpp" + "stdafx.cpp" + "stdafx.h" + "xrRender_GLR1.cpp" + "../../Include/xrRender/animation_blend.h" + "../../Include/xrRender/animation_motion.h" + "../../Include/xrRender/ConsoleRender.h" + "../../Include/xrRender/DebugRender.h" + "../../Include/xrRender/DebugShader.h" + "../../Include/xrRender/DrawUtils.h" + "../../Include/xrRender/EnvironmentRender.h" + "../../Include/xrRender/FactoryPtr.h" + "../../Include/xrRender/FontRender.h" + "../../Include/xrRender/Kinematics.h" + "../../Include/xrRender/KinematicsAnimated.h" + "../../Include/xrRender/LensFlareRender.h" + "../../Include/xrRender/ObjectSpaceRender.h" + "../../Include/xrRender/ParticleCustom.h" + "../../Include/xrRender/RainRender.h" + "../../Include/xrRender/RenderDetailModel.h" + "../../Include/xrRender/RenderFactory.h" + "../../Include/xrRender/RenderVisual.h" + "../../Include/xrRender/StatGraphRender.h" + "../../Include/xrRender/ThunderboltDescRender.h" + "../../Include/xrRender/ThunderboltRender.h" + "../../Include/xrRender/UIRender.h" + "../../Include/xrRender/UISequenceVideoItem.h" + "../../Include/xrRender/UIShader.h" + "../../Include/xrRender/WallMarkArray.h" + "../xrRender/Animation.h" + "../xrRender/AnimationKeyCalculate.h" + "../xrRender/Blender.h" + "../xrRender/Blender_CLSID.h" + "../xrRender/Blender_Recorder.h" + "../xrRender/blenders/Blender_BmmD.h" + "../xrRender/blenders/Blender_detail_still.h" + "../xrRender/blenders/Blender_Editor_Selection.h" + "../xrRender/blenders/Blender_Editor_Wire.h" + "../xrRender/blenders/Blender_Lm(EbB).h" + "../xrRender/blenders/Blender_Model_EbB.h" + "../xrRender/blenders/Blender_Particle.h" + "../xrRender/blenders/Blender_Screen_SET.h" + "../xrRender/blenders/Blender_tree.h" + "../xrRender/BufferUtils.h" + "../xrRender/ColorMapManager.h" + "../xrRender/D3DUtils.h" + "../xrRender/Debug/dxPixEventWrapper.h" + "../xrRender/DetailFormat.h" + "../xrRender/DetailManager.h" + "../xrRender/DetailModel.h" + "../xrRender/du_box.h" + "../xrRender/du_cone.h" + "../xrRender/du_cylinder.h" + "../xrRender/du_sphere.h" + "../xrRender/du_sphere_part.h" + "../xrRender/dxConsoleRender.h" + "../xrRender/dxDebugRender.h" + "../xrRender/dxEnvironmentRender.h" + "../xrRender/dxFontRender.h" + "../xrRender/dxLensFlareRender.h" + "../xrRender/dxObjectSpaceRender.h" + "../xrRender/dxParticleCustom.h" + "../xrRender/dxRainRender.h" + "../xrRender/dxRenderFactory.h" + "../xrRender/dxStatGraphRender.h" + "../xrRender/dxThunderboltDescRender.h" + "../xrRender/dxThunderboltRender.h" + "../xrRender/dxUIRender.h" + "../xrRender/dxUISequenceVideoItem.h" + "../xrRender/dxUIShader.h" + "../xrRender/dxWallMarkArray.h" + "../xrRender/ETextureParams.h" + "../xrRender/FBasicVisual.h" + "../xrRender/FHierrarhyVisual.h" + "../xrRender/FLOD.h" + "../xrRender/FProgressive.h" + "../xrRender/FSkinned.h" + "../xrRender/FSkinnedTypes.h" + "../xrRender/FTreeVisual.h" + "../xrRender/FVF.h" + "../xrRender/FVisual.h" + "../xrRender/HOM.h" + "../xrRender/HWCaps.h" + "../xrRender/IRenderDetailModel.h" + "../xrRender/KinematicAnimatedDefs.h" + "../xrRender/KinematicsAddBoneTransform.hpp" + "../xrRender/light.h" + "../xrRender/LightTrack.h" + "../xrRender/Light_DB.h" + "../xrRender/Light_Package.h" + "../xrRender/ModelPool.h" + "../xrRender/NvTriStrip.h" + "../xrRender/NvTriStripObjects.h" + "../xrRender/occRasterizer.h" + "../xrRender/ParticleEffect.h" + "../xrRender/ParticleEffectDef.h" + "../xrRender/ParticleGroup.h" + "../xrRender/PSLibrary.h" + "../xrRender/ResourceManager.h" + "../xrRender/R_Backend.h" + "../xrRender/R_Backend_hemi.h" + "../xrRender/R_Backend_Runtime.h" + "../xrRender/R_Backend_tree.h" + "../xrRender/R_Backend_xform.h" + "../xrRender/r_constants.h" + "../xrRender/r_constants_cache.h" + "../xrRender/R_DStreams.h" + "../xrRender/D3DXRenderBase.h" + "../xrRender/r__dsgraph_structure.h" + "../xrRender/r__dsgraph_types.h" + "../xrRender/r__sector.h" + "../xrRender/Shader.h" + "../xrRender/ShaderResourceTraits.h" + "../xrRender/SH_Atomic.h" + "../xrRender/SH_Constant.h" + "../xrRender/SH_Matrix.h" + "../xrRender/SH_RT.h" + "../xrRender/SH_Texture.h" + "../xrRender/SkeletonAnimated.h" + "../xrRender/SkeletonCustom.h" + "../xrRender/SkeletonX.h" + "../xrRender/SkeletonXVertRender.h" + #"../xrRender/stats_manager.h" + "../xrRender/TextureDescrManager.h" + "../xrRender/tss.h" + "../xrRender/tss_def.h" + "../xrRender/VertexCache.h" + "../xrRender/WallmarksEngine.h" + "../xrRender/xrRender_console.h" + "../xrRender/xrStripify.h" + #"../xrRender/xr_effgamma.h" + "../xrRender/blenders/BlenderDefault.h" + "../xrRender/blenders/Blender_Blur.h" + "../xrRender/blenders/Blender_default_aref.h" + #"../xrRender/blenders/Blender_LaEmB.h" + "../xrRender/blenders/Blender_Model.h" + "../xrRender/blenders/Blender_Screen_GRAY.h" + "../xrRender/blenders/Blender_Shadow_World.h" + "../xrRender/blenders/Blender_Vertex.h" + "../xrRender/blenders/Blender_Vertex_aref.h" + + #"../xrRenderGLR1/Blender_Recorder_GL.cpp" + "../xrRenderGLR1/CommonTypes.h" + "../xrRenderGLR1/glBufferUtils.cpp" + "../xrRenderGLR1/glDetailManager_VS.cpp" + "../xrRenderGLR1/glHWCaps.cpp" + "../xrRenderGLR1/glHW.cpp" + "../xrRenderGLR1/glHW.h" + "../xrRenderGLR1/glR_Backend_Runtime.h" + "../xrRenderGLR1/glr_constants_cache.h" + "../xrRenderGLR1/glSH_RT.cpp" + "../xrRenderGLR1/glSH_Texture.cpp" + "../xrRenderGLR1/glState.cpp" + "../xrRenderGLR1/glState.h" + "../xrRenderGLR1/glStateUtils.cpp" + "../xrRenderGLR1/glStateUtils.h" + "../xrRenderGLR1/glTextureUtils.cpp" + "../xrRenderGLR1/glTextureUtils.h" + "../xrRenderGLR1/glResourceManager_Resources.cpp" + #"../xrRenderGLR1/glResourceManager_Scripting.cpp" + + #"../xrRenderGLR1/BufferUtils.cpp" + #"../xrRenderGLR1/dx9HW.cpp" + #"../xrRenderGLR1/dx9HWCaps.cpp" + #"../xrRenderGLR1/dx9ResourceManager_Resources.cpp" + #"../xrRenderGLR1/dx9r_constants_cache.cpp" + #"../xrRenderGLR1/dx9SH_RT.cpp" + #"../xrRenderGLR1/CommonTypes.h" + #"../xrRenderGLR1/dx9HW.h" + #"../xrRenderGLR1/dx9R_Backend_Runtime.h" + #"../xrRenderGLR1/dx9r_constants_cache.h" + + "../xrRender/Animation.cpp" + "../xrRender/Blender.cpp" + "../xrRender/Blender_Recorder.cpp" + "../xrRender/blenders/Blender_BmmD.cpp" + "../xrRender/blenders/Blender_detail_still.cpp" + "../xrRender/blenders/Blender_Editor_Selection.cpp" + "../xrRender/blenders/Blender_Editor_Wire.cpp" + "../xrRender/blenders/Blender_Lm(EbB).cpp" + "../xrRender/blenders/Blender_Model_EbB.cpp" + "../xrRender/blenders/Blender_Particle.cpp" + "../xrRender/Blender_Recorder_R2.cpp" + "../xrRender/Blender_Recorder_StandartBinding.cpp" + "../xrRender/blenders/Blender_Screen_SET.cpp" + "../xrRender/blenders/Blender_tree.cpp" + "../xrRender/ColorMapManager.cpp" + "../xrRender/D3DUtils.cpp" + "../xrRender/D3DXRenderBase.cpp" + "../xrRender/DetailManager.cpp" + "../xrRender/DetailManager_CACHE.cpp" + "../xrRender/DetailManager_Decompress.cpp" + "../xrRender/DetailManager_VS.cpp" + "../xrRender/DetailModel.cpp" + "../xrRender/du_box.cpp" + "../xrRender/du_cone.cpp" + "../xrRender/du_cylinder.cpp" + "../xrRender/du_sphere.cpp" + "../xrRender/du_sphere_part.cpp" + "../xrRender/dxConsoleRender.cpp" + "../xrRender/dxDebugRender.cpp" + "../xrRender/dxEnvironmentRender.cpp" + "../xrRender/dxFontRender.cpp" + "../xrRender/dxLensFlareRender.cpp" + "../xrRender/dxObjectSpaceRender.cpp" + "../xrRender/dxParticleCustom.cpp" + "../xrRender/dxRainRender.cpp" + "../xrRender/dxRenderFactory.cpp" + "../xrRender/dxStatGraphRender.cpp" + "../xrRender/dxThunderboltDescRender.cpp" + "../xrRender/dxThunderboltRender.cpp" + "../xrRender/dxUIRender.cpp" + "../xrRender/dxUISequenceVideoItem.cpp" + "../xrRender/dxUIShader.cpp" + "../xrRender/dxWallMarkArray.cpp" + "../xrRender/ETextureParams.cpp" + "../xrRender/FBasicVisual.cpp" + "../xrRender/FHierrarhyVisual.cpp" + "../xrRender/FLOD.cpp" + "../xrRender/FProgressive.cpp" + "../xrRender/FSkinned.cpp" + "../xrRender/FTreeVisual.cpp" + "../xrRender/FVisual.cpp" + "../xrRender/HOM.cpp" + "../xrRender/light.cpp" + "../xrRender/LightTrack.cpp" + "../xrRender/Light_DB.cpp" + "../xrRender/Light_Package.cpp" + "../xrRender/ModelPool.cpp" + "../xrRender/NvTriStrip.cpp" + "../xrRender/NvTriStripObjects.cpp" + "../xrRender/occRasterizer.cpp" + "../xrRender/occRasterizer_core.cpp" + "../xrRender/ParticleEffect.cpp" + "../xrRender/ParticleEffectDef.cpp" + "../xrRender/ParticleGroup.cpp" + "../xrRender/PSLibrary.cpp" + "../xrRender/ResourceManager.cpp" + "../xrRender/ResourceManager_Loader.cpp" + "../xrRender/ResourceManager_Reset.cpp" + "../xrRender/ResourceManager_Resources.cpp" + "../xrRender/ResourceManager_Scripting.cpp" + "../xrRender/R_Backend.cpp" + "../xrRender/R_Backend_DBG.cpp" + "../xrRender/R_Backend_hemi.cpp" + "../xrRender/R_Backend_Runtime.cpp" + "../xrRender/R_Backend_tree.cpp" + "../xrRender/R_Backend_xform.cpp" + "../xrRender/r_constants.cpp" + "../xrRender/R_DStreams.cpp" + "../xrRender/r__dsgraph_build.cpp" + "../xrRender/r__dsgraph_render.cpp" + "../xrRender/r__dsgraph_render_lods.cpp" + "../xrRender/r__screenshot.cpp" + "../xrRender/r__sector.cpp" + "../xrRender/r__sector_detect.cpp" + "../xrRender/r__sector_traversal.cpp" + "../xrRenderPC_GLR1/glr_constants.cpp" + "../xrRender/Shader.cpp" + "../xrRender/SH_Atomic.cpp" + "../xrRender/SH_Constant.cpp" + "../xrRender/SH_Matrix.cpp" + #"../xrRender/SH_Texture.cpp" + "../xrRender/SkeletonAnimated.cpp" + "../xrRender/SkeletonCustom.cpp" + "../xrRender/SkeletonRigid.cpp" + "../xrRender/SkeletonX.cpp" + #"../xrRender/stats_manager.cpp" + #"../xrRender/Texture.cpp" + "../xrRender/TextureDescrManager.cpp" + "../xrRender/tss_def.cpp" + "../xrRender/VertexCache.cpp" + "../xrRender/WallmarksEngine.cpp" + "../xrRender/xrRender_console.cpp" + "../xrRender/xrStripify.cpp" + #"../xrRender/xr_effgamma.cpp" + "../xrRender/blenders/BlenderDefault.cpp" + "../xrRender/blenders/Blender_Blur.cpp" + "../xrRender/blenders/Blender_default_aref.cpp" + #"../xrRender/blenders/Blender_LaEmB.cpp" + "../xrRender/blenders/Blender_Model.cpp" + "../xrRender/blenders/Blender_Screen_GRAY.cpp" + "../xrRender/blenders/Blender_Shadow_World.cpp" + "../xrRender/blenders/Blender_Vertex.cpp" + "../xrRender/blenders/Blender_Vertex_aref.cpp" +) + +group_sources(SRC_FILES) + +add_library(${PROJECT_NAME} SHARED ${SRC_FILES}) + +target_include_directories(${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/src/Layers/xrRender + ${CMAKE_SOURCE_DIR}/src/Include/xrRender + ${CMAKE_SOURCE_DIR}/Externals/luabind + ${CMAKE_SOURCE_DIR}/Externals/gli + ${CMAKE_SOURCE_DIR}/Externals/gli/external/glm + ${CMAKE_SOURCE_DIR}/sdk/include + ${SDL_INCLUDE_DIRS} + ${FREEIMAGE_INCLUDE_PATH} + ${FREEIMAGEPLUS_INCLUDE_PATH} +) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + xrCore + xrLuabind + xrCDB + xrEngine + xrParticles + xrScriptEngine + xrAPI + GL + GLEW + ${SDL_LIBRARIES} +) + +target_compile_definitions(${PROJECT_NAME} + PRIVATE + -DXRRENDER_GLR1_EXPORTS + -DUSE_OGLR1 + -DNO_XR_VDECLARATOR +) + +set_target_properties(${PROJECT_NAME} PROPERTIES + PREFIX "" +) + +target_precompile_headers(${PROJECT_NAME} + PRIVATE + "stdafx.h" +) + +install(TARGETS ${PROJECT_NAME} LIBRARY + DESTINATION ${CMAKE_INSTALL_LIBDIR} + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +) diff --git a/src/Layers/xrRenderPC_GLR1/FStaticRender.cpp b/src/Layers/xrRenderPC_GLR1/FStaticRender.cpp new file mode 100755 index 00000000000..a1fa1867fb8 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/FStaticRender.cpp @@ -0,0 +1,805 @@ +#include "stdafx.h" + +#include "xrCore/Threading/TaskManager.hpp" + +#include "FStaticRender.h" + +#include "xrEngine/xr_object.h" +#include "xrEngine/CustomHUD.h" +#include "xrEngine/IGame_Persistent.h" +#include "xrEngine/Environment.h" +#include "xrEngine/GameFont.h" +#include "xrEngine/PerformanceAlert.hpp" + +#include "Layers/xrRender/FBasicVisual.h" +#include "Layers/xrRender/SkeletonCustom.h" +#include "Layers/xrRender/LightTrack.h" +#include "Layers/xrRender/dxWallMarkArray.h" +#include "Layers/xrRender/dxUIShader.h" +#include "Layers/xrRender/ShaderResourceTraits.h" + +CRender RImplementation; + +////////////////////////////////////////////////////////////////////////// +ShaderElement* CRender::rimp_select_sh_dynamic(dxRender_Visual* pVisual, float /*cdist_sq*/) +{ + switch (phase) + { + case PHASE_NORMAL: + return (RImplementation.L_Projector->shadowing() ? + pVisual->shader->E[SE_R1_NORMAL_HQ] : pVisual->shader->E[SE_R1_NORMAL_LQ])._get(); + case PHASE_POINT: return pVisual->shader->E[SE_R1_LPOINT]._get(); + case PHASE_SPOT: return pVisual->shader->E[SE_R1_LSPOT]._get(); + default: NODEFAULT; + } +#ifdef DEBUG + return nullptr; +#endif +} +////////////////////////////////////////////////////////////////////////// +ShaderElement* CRender::rimp_select_sh_static(dxRender_Visual* pVisual, float cdist_sq) +{ + switch (phase) + { + case PHASE_NORMAL: + return (((_sqrt(cdist_sq) - pVisual->vis.sphere.R) < 44) ? pVisual->shader->E[SE_R1_NORMAL_HQ] : + pVisual->shader->E[SE_R1_NORMAL_LQ]) + ._get(); + case PHASE_POINT: return pVisual->shader->E[SE_R1_LPOINT]._get(); + case PHASE_SPOT: return pVisual->shader->E[SE_R1_LSPOT]._get(); + default: NODEFAULT; + } +#ifdef DEBUG + return nullptr; +#endif +} + +////////////////////////////////////////////////////////////////////////// +void CRender::create() +{ + L_Shadows = nullptr; + L_Projector = nullptr; + + Device.seqFrame.Add(this, REG_PRIORITY_HIGH + 0x12345678); + + // c-setup + Resources->RegisterConstantSetup("L_dynamic_pos", &r1_dlight_binder_PR); + Resources->RegisterConstantSetup("L_dynamic_color", &r1_dlight_binder_color); + Resources->RegisterConstantSetup("L_dynamic_xform", &r1_dlight_binder_xform); + + // distortion + u32 v_dev = CAP_VERSION(HW.Caps.raster_major, HW.Caps.raster_minor); + u32 v_need = CAP_VERSION(1, 4); + if (v_dev >= v_need) + o.distortion = TRUE; + else + o.distortion = FALSE; + if (strstr(Core.Params, "-nodistort")) + o.distortion = FALSE; + Msg("* distortion: %s, dev(%d),need(%d)", o.distortion ? "used" : "unavailable", v_dev, v_need); + + // Color mapping + if (v_dev >= v_need) + o.color_mapping = TRUE; + else + o.color_mapping = FALSE; + if (strstr(Core.Params, "-nocolormap")) + o.color_mapping = FALSE; + Msg("* color_mapping: %s, dev(%d),need(%d)", o.color_mapping ? "used" : "unavailable", v_dev, v_need); + + m_skinning = -1; + + // disasm + o.disasm = (strstr(Core.Params, "-disasm")) ? TRUE : FALSE; + o.forceskinw = (strstr(Core.Params, "-skinw")) ? TRUE : FALSE; + o.no_detail_textures = !ps_r2_ls_flags.test(R1FLAG_DETAIL_TEXTURES); + c_ldynamic_props = "L_dynamic_props"; + + o.no_ram_textures = (strstr(Core.Params, "-noramtex")) ? TRUE : ps_r__common_flags.test(RFLAG_NO_RAM_TEXTURES); + if (o.no_ram_textures) + Msg("* Managed textures disabled"); + + m_bMakeAsyncSS = false; + + Target = xr_new(); // Main target + + Models = xr_new(); + L_Dynamic = xr_new(); + PSLibrary.OnCreate(); + //. HWOCC.occq_create (occq_size); + + PortalTraverser.initialize(); +} + +void CRender::destroy() +{ + m_bMakeAsyncSS = false; + ::PortalTraverser.destroy(); + //. HWOCC.occq_destroy (); + PSLibrary.OnDestroy(); + + xr_delete(L_Dynamic); + xr_delete(Models); + + //*** Components + xr_delete(Target); + Device.seqFrame.Remove(this); + r_dsgraph_destroy(); +} + +void CRender::reset_begin() +{ + //AVO: let's reload details while changed details options on vid_restart + if (b_loaded && (dm_current_size != dm_size || ps_r__Detail_density != ps_current_detail_density)) + { + Details->Unload(); + xr_delete(Details); + } + xr_delete(Target); + //HWOCC.occq_destroy(); +} + +void CRender::reset_end() +{ + //. HWOCC.occq_create (occq_size); + Target = xr_new(); + if (L_Projector) + L_Projector->invalidate(); + + // let's reload details while changed details options on vid_restart + if (b_loaded && (dm_current_size != dm_size || ps_r__Detail_density != ps_current_detail_density)) + { + Details = xr_new(); + Details->Load(); + } + + // Set this flag true to skip the first render frame, + // that some data is not ready in the first frame (for example device camera position) + m_bFirstFrameAfterReset = true; +} + +void CRender::BeforeFrame() +{ + if (IGame_Persistent::MainMenuActiveOrLevelNotExist()) + return; + + ProcessHOMTask = &TaskScheduler->AddTask("MT-HOM", { &HOM, &CHOM::MT_RENDER }); +} + +void CRender::OnFrame() +{ + Models->DeleteQueue(); + if (IGame_Persistent::MainMenuActiveOrLevelNotExist()) + return; + if (ps_r2_ls_flags.test(R2FLAG_EXP_MT_CALC)) + { + // MT-details (@front) + Device.seqParallel.insert( + Device.seqParallel.begin(), fastdelegate::FastDelegate0<>(Details, &CDetailManager::MT_CALC)); + } +} + +// Перед началом рендера мира --#SM+#-- +void CRender::BeforeWorldRender() {} + +// После рендера мира и пост-эффектов --#SM+#-- +void CRender::AfterWorldRender() {} + +#ifdef USE_OGLR1 +void CRender::ObtainRequiredWindowFlags(u32& windowFlags) +{ + windowFlags |= SDL_WINDOW_OPENGL; + HW.SetPrimaryAttributes(); +} + +IRender::RenderContext CRender::GetCurrentContext() const +{ + return HW.GetCurrentContext(); +} + +void CRender::MakeContextCurrent(RenderContext context) +{ + R_ASSERT3(HW.MakeContextCurrent(context) == 0, + "Failed to switch OpenGL context", SDL_GetError()); +} +#endif + +// Implementation +IRender_ObjectSpecific* CRender::ros_create(IRenderable* parent) { return xr_new(); } +void CRender::ros_destroy(IRender_ObjectSpecific*& p) { xr_delete(p); } +IRenderVisual* CRender::model_Create(LPCSTR name, IReader* data) { return Models->Create(name, data); } +IRenderVisual* CRender::model_CreateChild(LPCSTR name, IReader* data) { return Models->CreateChild(name, data); } +IRenderVisual* CRender::model_Duplicate(IRenderVisual* V) { return Models->Instance_Duplicate((dxRender_Visual*)V); } +void CRender::model_Delete(IRenderVisual*& V, bool bDiscard) +{ + dxRender_Visual* pVisual = (dxRender_Visual*)V; + Models->Delete(pVisual, bDiscard); + V = nullptr; +} +IRender_DetailModel* CRender::model_CreateDM(IReader* F) +{ + CDetail* D = xr_new(); + D->Load(F); + return D; +} +void CRender::model_Delete(IRender_DetailModel*& F) +{ + if (F) + { + CDetail* D = (CDetail*)F; + D->Unload(); + xr_delete(D); + F = nullptr; + } +} +IRenderVisual* CRender::model_CreatePE(LPCSTR name) +{ + PS::CPEDef* SE = PSLibrary.FindPED(name); + R_ASSERT3(SE, "Particle effect doesn't exist", name); + return Models->CreatePE(SE); +} +IRenderVisual* CRender::model_CreateParticles(LPCSTR name) +{ + PS::CPEDef* SE = PSLibrary.FindPED(name); + if (SE) + return Models->CreatePE(SE); + else + { + PS::CPGDef* SG = PSLibrary.FindPGD(name); + R_ASSERT3(SG, "Particle effect or group doesn't exist", name); + return Models->CreatePG(SG); + } +} +void CRender::models_Prefetch() { Models->Prefetch(); } +void CRender::models_Clear(bool b_complete) { Models->ClearPool(b_complete); } +ref_shader CRender::getShader(int id) +{ + VERIFY(id < int(Shaders.size())); + return Shaders[id]; +} +IRender_Portal* CRender::getPortal(int id) +{ + VERIFY(id < int(Portals.size())); + return Portals[id]; +} +IRender_Sector* CRender::getSector(int id) +{ + VERIFY(id < int(Sectors.size())); + return Sectors[id]; +} +IRender_Sector* CRender::getSectorActive() { return pLastSector; } +IRenderVisual* CRender::getVisual(int id) +{ + VERIFY(id < int(Visuals.size())); + return Visuals[id]; +} +VertexElement* CRender::getVB_Format(int id, bool alternative) +{ + if (alternative) + { + VERIFY(id < int(xDC.size())); + return xDC[id].begin(); + } + else + { + VERIFY(id < int(nDC.size())); + return nDC[id].begin(); + } +} +VertexStagingBuffer* CRender::getVB(int id, bool alternative) +{ + if (alternative) + { + VERIFY(id < int(xVB.size())); + return &xVB[id]; + } + else + { + VERIFY(id < int(nVB.size())); + return &nVB[id]; + } +} +IndexStagingBuffer* CRender::getIB(int id, bool alternative) +{ + if (alternative) + { + VERIFY(id < int(xIB.size())); + return &xIB[id]; + } + else + { + VERIFY(id < int(nIB.size())); + return &nIB[id]; + } +} +FSlideWindowItem* CRender::getSWI(int id) +{ + VERIFY(id < int(SWIs.size())); + return &SWIs[id]; +} +IRender_Target* CRender::getTarget() { return Target; } +IRender_Light* CRender::light_create() { return Lights.Create(); } +IRender_Glow* CRender::glow_create() { return xr_new(); } +void CRender::flush() { r_dsgraph_render_graph(0); } +bool CRender::occ_visible(vis_data& P) { return HOM.visible(P); } +bool CRender::occ_visible(sPoly& P) { return HOM.visible(P); } +bool CRender::occ_visible(Fbox& P) { return HOM.visible(P); } +void CRender::add_Visual(IRenderable* root, IRenderVisual* V, Fmatrix& m) +{ + set_Object(root); + add_leafs_Dynamic(root, (dxRender_Visual*)V, m); +} +void CRender::add_Geometry(IRenderVisual* V, const CFrustum& view) +{ + add_Static((dxRender_Visual*)V, view, view.getMask()); +} +void CRender::add_StaticWallmark(ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* verts) +{ + if (T->suppress_wm) + return; + VERIFY2(_valid(P) && _valid(s) && T && verts && (s > EPS_L), "Invalid static wallmark params"); + Wallmarks->AddStaticWallmark(T, verts, P, &*S, s); +} + +void CRender::add_StaticWallmark(IWallMarkArray* pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V) +{ + dxWallMarkArray* pWMA = (dxWallMarkArray*)pArray; + ref_shader* pShader = pWMA->dxGenerateWallmark(); + if (pShader) + add_StaticWallmark(*pShader, P, s, T, V); +} + +void CRender::add_StaticWallmark(const wm_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V) +{ + dxUIShader* pShader = (dxUIShader*)&*S; + add_StaticWallmark(pShader->hShader, P, s, T, V); +} + +void CRender::clear_static_wallmarks() { Wallmarks->clear(); } +void CRender::add_SkeletonWallmark(intrusive_ptr wm) { Wallmarks->AddSkeletonWallmark(wm); } +void CRender::add_SkeletonWallmark( + const Fmatrix* xf, CKinematics* obj, ref_shader& sh, const Fvector& start, const Fvector& dir, float size) +{ + Wallmarks->AddSkeletonWallmark(xf, obj, sh, start, dir, size); +} +void CRender::add_SkeletonWallmark( + const Fmatrix* xf, IKinematics* obj, IWallMarkArray* pArray, const Fvector& start, const Fvector& dir, float size) +{ + dxWallMarkArray* pWMA = (dxWallMarkArray*)pArray; + ref_shader* pShader = pWMA->dxGenerateWallmark(); + if (pShader) + add_SkeletonWallmark(xf, (CKinematics*)obj, *pShader, start, dir, size); +} +void CRender::add_Occluder(Fbox2& bb_screenspace) { HOM.occlude(bb_screenspace); } + +#include "xrEngine/PS_instance.h" +void CRender::set_Object(IRenderable* O) +{ + if (O) + { + VERIFY(dynamic_cast(O) || dynamic_cast(O)); + if (O->GetRenderData().pROS) + { + VERIFY(dynamic_cast(O->GetRenderData().pROS)); + } + } + if (PHASE_NORMAL == phase) + { + if (L_Shadows) + L_Shadows->set_object(O); + + if (L_Projector) + L_Projector->set_object(O); + } + else + { + if (L_Shadows) + L_Shadows->set_object(nullptr); + + if (L_Projector) + L_Projector->set_object(nullptr); + } +} +void CRender::apply_object(IRenderable* O) +{ + if (nullptr == O) + return; + if (O->renderable_ROS()) + { + CROS_impl& LT = *((CROS_impl*)O->GetRenderData().pROS); + VERIFY(dynamic_cast(O) || dynamic_cast(O)); + VERIFY(dynamic_cast(O->GetRenderData().pROS)); + float o_hemi = 0.5f * LT.get_hemi(); + float o_sun = 0.5f * LT.get_sun(); + RCache.set_c(c_ldynamic_props, o_sun, o_sun, o_sun, o_hemi); + // shadowing + if ((LT.shadow_recv_frame == Device.dwFrame) && O->renderable_ShadowReceive()) + RImplementation.L_Projector->setup(LT.shadow_recv_slot); + } +} + +// Misc +float g_fSCREEN; +static BOOL gm_Nearer = 0; + +IC void gm_SetNearer(BOOL bNearer) +{ + if (bNearer != gm_Nearer) + { + gm_Nearer = bNearer; + if (gm_Nearer) + RImplementation.rmNear(); + else + RImplementation.rmNormal(); + } +} + +void CRender::rmNear() +{ + IRender_Target* T = getTarget(); + RCache.SetViewport({ 0, 0, T->get_width(), T->get_height(), 0, 0.02f }); +} + +void CRender::rmFar() +{ + IRender_Target* T = getTarget(); + RCache.SetViewport({ 0, 0, T->get_width(), T->get_height(), 0.99999f, 1.f }); +} + +void CRender::rmNormal() +{ + IRender_Target* T = getTarget(); + RCache.SetViewport({ 0, 0, T->get_width(), T->get_height(), 0, 1.f }); +} + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// +CRender::CRender() : m_bFirstFrameAfterReset(false), Sectors_xrc("render") {} +CRender::~CRender() {} +extern float r_ssaDISCARD; +extern float r_ssaDONTSORT; +extern float r_ssaLOD_A, r_ssaLOD_B; +extern float r_ssaGLOD_start, r_ssaGLOD_end; +extern float r_ssaHZBvsTEX; + +ICF bool pred_sp_sort(ISpatial* _1, ISpatial* _2) +{ + float d1 = _1->GetSpatialData().sphere.P.distance_to_sqr(Device.vCameraPosition); + float d2 = _2->GetSpatialData().sphere.P.distance_to_sqr(Device.vCameraPosition); + return d1 < d2; +} + +void CRender::Calculate() +{ +#ifdef _GPA_ENABLED + TAL_SCOPED_TASK_NAMED("CRender::Calculate()"); +#endif // _GPA_ENABLED + + BasicStats.Culling.Begin(); + + // Transfer to global space to avoid deep pointer access + IRender_Target* T = getTarget(); + float fov_factor = _sqr(90.f / Device.fFOV); + g_fSCREEN = float(T->get_width() * T->get_height()) * fov_factor * (EPS_S + ps_r__LOD); + r_ssaDISCARD = _sqr(ps_r__ssaDISCARD) / g_fSCREEN; + r_ssaDONTSORT = _sqr(ps_r__ssaDONTSORT / 3) / g_fSCREEN; + r_ssaLOD_A = _sqr(ps_r1_ssaLOD_A / 3) / g_fSCREEN; + r_ssaLOD_B = _sqr(ps_r1_ssaLOD_B / 3) / g_fSCREEN; + r_ssaGLOD_start = _sqr(ps_r__GLOD_ssa_start / 3) / g_fSCREEN; + r_ssaGLOD_end = _sqr(ps_r__GLOD_ssa_end / 3) / g_fSCREEN; + r_ssaHZBvsTEX = _sqr(ps_r__ssaHZBvsTEX / 3) / g_fSCREEN; + + // Frustum + ViewBase.CreateFromMatrix(Device.mFullTransform, FRUSTUM_P_LRTB | FRUSTUM_P_FAR); + + gm_SetNearer(FALSE); + phase = PHASE_NORMAL; + + // Detect camera-sector + if (!vLastCameraPos.similar(Device.vCameraPosition, EPS_S)) + { + CSector* pSector = (CSector*)detectSector(Device.vCameraPosition); + if (pSector && (pSector != pLastSector)) + g_pGamePersistent->OnSectorChanged(translateSector(pSector)); + + if (nullptr == pSector) + pSector = pLastSector; + pLastSector = pSector; + vLastCameraPos.set(Device.vCameraPosition); + } + + // Check if camera is too near to some portal - if so force DualRender + if (rmPortals) + { + Fvector box_radius; + box_radius.set(EPS_L * 2, EPS_L * 2, EPS_L * 2); + Sectors_xrc.box_options(CDB::OPT_FULL_TEST); + Sectors_xrc.box_query(rmPortals, Device.vCameraPosition, box_radius); + for (int K = 0; K < Sectors_xrc.r_count(); K++) + { + CPortal* pPortal = (CPortal*)Portals[rmPortals->get_tris()[Sectors_xrc.r_begin()[K].id].dummy]; + pPortal->bDualRender = TRUE; + } + } + + // + Lights.Update(); + + // Main process + marker++; + set_Object(nullptr); + TaskScheduler->Wait(*ProcessHOMTask); + if (pLastSector) + { + // Traverse sector/portal structure + PortalTraverser.traverse(pLastSector, ViewBase, Device.vCameraPosition, Device.mFullTransform, + CPortalTraverser::VQ_HOM + CPortalTraverser::VQ_SSA + CPortalTraverser::VQ_FADE); + + // Determine visibility for static geometry hierarchy + if (psDeviceFlags.test(rsDrawStatic)) + { + for (u32 s_it = 0; s_it < PortalTraverser.r_sectors.size(); s_it++) + { + CSector* sector = (CSector*)PortalTraverser.r_sectors[s_it]; + dxRender_Visual* root = sector->root(); + for (u32 v_it = 0; v_it < sector->r_frustums.size(); v_it++) + { + add_Geometry(root, sector->r_frustums[v_it]); + } + } + } + + // Traverse object database + if (psDeviceFlags.test(rsDrawDynamic)) + { + g_SpatialSpace->q_frustum( + lstRenderables, ISpatial_DB::O_ORDERED, STYPE_RENDERABLE + STYPE_LIGHTSOURCE, ViewBase); + + // Exact sorting order (front-to-back) + std::sort(lstRenderables.begin(), lstRenderables.end(), pred_sp_sort); + + if (ps_r__common_flags.test(RFLAG_ACTOR_SHADOW)) // Actor Shadow (Sun + Light) + g_hud->Render_First(); // R1 shadows + + g_hud->Render_Last(); + + // Determine visibility for dynamic part of scene + u32 uID_LTRACK = 0xffffffff; + if (phase == PHASE_NORMAL) + { + uLastLTRACK++; + if (lstRenderables.size()) + uID_LTRACK = uLastLTRACK % lstRenderables.size(); + + // update light-vis for current entity / actor + IGameObject* O = g_pGameLevel->CurrentViewEntity(); + if (O) + { + CROS_impl* R = (CROS_impl*)O->ROS(); + if (R) + R->update(O); + } + } + for (u32 o_it = 0; o_it < lstRenderables.size(); o_it++) + { + ISpatial* spatial = lstRenderables[o_it]; + spatial->spatial_updatesector(); + CSector* sector = (CSector*)spatial->GetSpatialData().sector; + if (nullptr == sector) + continue; // disassociated from S/P structure + + // Filter only not light spatial + if (PortalTraverser.i_marker != sector->r_marker && (spatial->GetSpatialData().type & STYPE_RENDERABLE)) + continue; // inactive (untouched) sector + + if (spatial->GetSpatialData().type & STYPE_RENDERABLE) + { + for (u32 v_it = 0; v_it < sector->r_frustums.size(); v_it++) + { + const CFrustum& view = sector->r_frustums[v_it]; + + if (!view.testSphere_dirty(spatial->GetSpatialData().sphere.P, + spatial->GetSpatialData().sphere.R) /*&& (spatial->spatial.type & STYPE_RENDERABLE)*/) + continue; + // renderable + IRenderable* renderable = spatial->dcast_Renderable(); + if (nullptr == renderable) + { + // It may be an glow + CGlow* glow = dynamic_cast(spatial); + VERIFY(glow); +#ifdef DEBUG + BasicStats.Glows.Begin(); +#endif + L_Glows->add(glow); +#ifdef DEBUG + BasicStats.Glows.End(); +#endif + } + else + { + // Occlusiond + vis_data& v_orig = renderable->GetRenderData().visual->getVisData(); + vis_data v_copy = v_orig; + v_copy.box.xform(renderable->GetRenderData().xform); + BOOL bVisible = HOM.visible(v_copy); + v_orig.accept_frame = v_copy.accept_frame; + v_orig.marker = v_copy.marker; + v_orig.hom_frame = v_copy.hom_frame; + v_orig.hom_tested = v_copy.hom_tested; + if (!bVisible) + break; // exit loop on frustums + + // update light-vis for selected entity + if (o_it == uID_LTRACK && renderable->renderable_ROS()) + { + // track lighting environment + CROS_impl* T = (CROS_impl*)renderable->renderable_ROS(); + T->update(renderable); + } + + // Rendering + renderable->renderable_Render(renderable); + } + break; // exit loop on frustums + } + } + else + { + if (ViewBase.testSphere_dirty( + spatial->GetSpatialData().sphere.P, spatial->GetSpatialData().sphere.R)) + { + VERIFY(spatial->GetSpatialData().type & STYPE_LIGHTSOURCE); + // lightsource + light* L = (light*)spatial->dcast_Light(); + VERIFY(L); + if (L->spatial.sector) + { + vis_data& vis = L->get_homdata(); + if (HOM.visible(vis)) + Lights.add_light(L); + } + } + } + } + } + + // Calculate miscellaneous stuff + BasicStats.ShadowsCalc.Begin(); + L_Shadows->calculate(); + BasicStats.ShadowsCalc.End(); + BasicStats.Projectors.Begin(); + L_Projector->calculate(); + BasicStats.Projectors.End(); + } + + // End calc + BasicStats.Culling.End(); +} + +extern u32 g_r; +void CRender::Render() +{ +#ifdef _GPA_ENABLED + TAL_SCOPED_TASK_NAMED("CRender::Render()"); +#endif // _GPA_ENABLED + + if (m_bFirstFrameAfterReset) + { + m_bFirstFrameAfterReset = false; + return; + } + + g_r = 1; + BasicStats.Primitives.Begin(); + // Begin + Target->Begin(); + o.vis_intersect = FALSE; + phase = PHASE_NORMAL; + r_dsgraph_render_hud(); // hud + r_dsgraph_render_graph(0); // normal level + if (Details) + Details->Render(); // grass / details + r_dsgraph_render_lods(true, false); // lods - FB + + g_pGamePersistent->Environment().RenderSky(); // sky / sun + g_pGamePersistent->Environment().RenderClouds(); // clouds + + r_pmask(true, false); // disable priority "1" + o.vis_intersect = TRUE; + HOM.Disable(); + L_Dynamic->render(0); // additional light sources + if (Wallmarks) + { + g_r = 0; + Wallmarks->Render(); // wallmarks has priority as normal geometry + } + HOM.Enable(); + o.vis_intersect = FALSE; + phase = PHASE_NORMAL; + r_pmask(true, true); // enable priority "0" and "1" + BasicStats.ShadowsRender.Begin(); + if (L_Shadows) + L_Shadows->render(); // ... and shadows + BasicStats.ShadowsRender.End(); + r_dsgraph_render_lods(false, true); // lods - FB + r_dsgraph_render_graph(1); // normal level, secondary priority + L_Dynamic->render(1); // additional light sources, secondary priority + PortalTraverser.fade_render(); // faded-portals + r_dsgraph_render_sorted(); // strict-sorted geoms + BasicStats.Glows.Begin(); + if (L_Glows) + L_Glows->Render(); // glows + BasicStats.Glows.End(); + g_pGamePersistent->Environment().RenderFlares(); // lens-flares + g_pGamePersistent->Environment().RenderLast(); // rain/thunder-bolts + +#ifdef DEBUG + for (int _priority = 0; _priority < 2; ++_priority) + { + for (u32 iPass = 0; iPass < SHADER_PASSES_MAX; ++iPass) + { + R_ASSERT(mapNormalPasses[_priority][iPass].size() == 0); + R_ASSERT(mapMatrixPasses[_priority][iPass].size() == 0); + } + } + +#endif + // Postprocess, if necessary + Target->End(); + if (L_Projector) + L_Projector->finalize(); + + // HUD + BasicStats.Primitives.End(); +} + +void CRender::ApplyBlur4(FVF::TL4uv* pv, u32 w, u32 h, float k) +{ + float _w = float(w); + float _h = float(h); + float kw = (1.f / _w) * k; + float kh = (1.f / _h) * k; + Fvector2 p0, p1; + p0.set(.5f / _w, .5f / _h); + p1.set((_w + .5f) / _w, (_h + .5f) / _h); + u32 _c = 0xffffffff; + + // Fill vertex buffer + pv->p.set(EPS, float(_h + EPS), EPS, 1.f); + pv->color = _c; + pv->uv[0].set(p0.x - kw, p1.y - kh); + pv->uv[1].set(p0.x + kw, p1.y + kh); + pv->uv[2].set(p0.x + kw, p1.y - kh); + pv->uv[3].set(p0.x - kw, p1.y + kh); + pv++; + pv->p.set(EPS, EPS, EPS, 1.f); + pv->color = _c; + pv->uv[0].set(p0.x - kw, p0.y - kh); + pv->uv[1].set(p0.x + kw, p0.y + kh); + pv->uv[2].set(p0.x + kw, p0.y - kh); + pv->uv[3].set(p0.x - kw, p0.y + kh); + pv++; + pv->p.set(float(_w + EPS), float(_h + EPS), EPS, 1.f); + pv->color = _c; + pv->uv[0].set(p1.x - kw, p1.y - kh); + pv->uv[1].set(p1.x + kw, p1.y + kh); + pv->uv[2].set(p1.x + kw, p1.y - kh); + pv->uv[3].set(p1.x - kw, p1.y + kh); + pv++; + pv->p.set(float(_w + EPS), EPS, EPS, 1.f); + pv->color = _c; + pv->uv[0].set(p1.x - kw, p0.y - kh); + pv->uv[1].set(p1.x + kw, p0.y + kh); + pv->uv[2].set(p1.x + kw, p0.y - kh); + pv->uv[3].set(p1.x - kw, p0.y + kh); + pv++; +} + +void CRender::DumpStatistics(IGameFont& font, IPerformanceAlert* alert) +{ + D3DXRenderBase::DumpStatistics(font, alert); + HOM.DumpStatistics(font, alert); + Sectors_xrc.DumpStatistics(font, alert); +} diff --git a/src/Layers/xrRenderPC_GLR1/FStaticRender.h b/src/Layers/xrRenderPC_GLR1/FStaticRender.h new file mode 100755 index 00000000000..b467cbdbfef --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/FStaticRender.h @@ -0,0 +1,269 @@ +#pragma once +#include "Layers/xrRender/D3DXRenderBase.h" +#include "Layers/xrRender/PSLibrary.h" +#include "Layers/xrRender/HOM.h" +#include "Layers/xrRender/DetailManager.h" +#include "GlowManager.h" +#include "Layers/xrRender/WallmarksEngine.h" +#include "FStaticRender_RenderTarget.h" +#include "Layers/xrRender/ModelPool.h" +#include "LightShadows.h" +#include "LightProjector.h" +#include "LightPPA.h" +#include "Layers/xrRender/Light_DB.h" +#include "xrCore/FMesh.hpp" + +class dxRender_Visual; + +class CRender : public D3DXRenderBase +{ +public: + enum + { + PHASE_NORMAL, + PHASE_POINT, + PHASE_SPOT + }; + + struct _options + { + u32 vis_intersect : 1; // config + u32 distortion : 1; // run-time modified + u32 color_mapping : 1; // true if SM 1.4 and higher + u32 disasm : 1; // config + u32 forceskinw : 1; // config + u32 no_detail_textures : 1; // config + u32 no_ram_textures : 1; // don't keep textures in RAM + } o; + +public: + // Sector detection and visibility + CSector* pLastSector; + Fvector vLastCameraPos; + u32 uLastLTRACK; + xr_vector Portals; + xr_vector Sectors; + xrXRC Sectors_xrc; + CDB::MODEL* rmPortals; + Task* ProcessHOMTask; + CHOM HOM; + + // Global containers + xr_vector SWIs; + xr_vector Shaders; + typedef svector VertexDeclarator; + xr_vector nDC, xDC; + xr_vector nVB, xVB; + xr_vector nIB, xIB; + xr_vector Visuals; + CPSLibrary PSLibrary; + CLight_DB Lights; + CLightR_Manager* L_Dynamic; + CLightShadows* L_Shadows; + CLightProjector* L_Projector; + CGlowManager* L_Glows; + CWallmarksEngine* Wallmarks; + CDetailManager* Details; + CModelPool* Models; + CRenderTarget* Target; // Render-target + + // R1-specific global constants + Fmatrix r1_dlight_tcgen; + light* r1_dlight_light; + float r1_dlight_scale; + cl_light_PR r1_dlight_binder_PR; + cl_light_C r1_dlight_binder_color; + cl_light_XFORM r1_dlight_binder_xform; + shared_str c_ldynamic_props; + bool m_bMakeAsyncSS; + bool m_bFirstFrameAfterReset; // Determines weather the frame is the first after resetting device. + +private: + // Loading / Unloading + void LoadBuffers(CStreamReader* fs, bool alternative = false); + void LoadVisuals(IReader* fs); + void LoadLights(IReader* fs); + void LoadSectors(IReader* fs); + void LoadSWIs(CStreamReader* fs); + +public: + ShaderElement* rimp_select_sh_static(dxRender_Visual* pVisual, float cdist_sq); + ShaderElement* rimp_select_sh_dynamic(dxRender_Visual* pVisual, float cdist_sq); + VertexElement* getVB_Format(int id, bool alternative = false); + VertexStagingBuffer* getVB(int id, bool alternative = false); + IndexStagingBuffer* getIB(int id, bool alternative = false); + FSlideWindowItem* getSWI(int id); + IRender_Portal* getPortal(int id); + IRender_Sector* getSectorActive(); + IRenderVisual* model_CreatePE(LPCSTR name); + + void ApplyBlur4(FVF::TL4uv* dest, u32 w, u32 h, float k); + void apply_object(IRenderable* O) ;//{ + /* + if (!O || !O->renderable_ROS()) + return; + + CROS_impl& LT = *(CROS_impl*)O->renderable_ROS(); + LT.update_smooth(O); + o_hemi = 0.75f * LT.get_hemi(); + //o_hemi = 0.5f*LT.get_hemi () ; + o_sun = 0.75f * LT.get_sun(); + CopyMemory(o_hemi_cube, LT.get_hemi_cube(), CROS_impl::NUM_FACES*sizeof(float)); + */ + //} + void apply_lmaterial(){} //{ + /* + R_constant* C = RCache.get_c(c_sbase)._get(); // get sampler + if (!C) + return; + VERIFY (RC_dest_sampler == C->destination); + VERIFY (RC_sampler == C->type); + CTexture* T = RCache.get_ActiveTexture(u32(C->samp.index)); + VERIFY (T); + float mtl = T->m_material; +#ifdef DEBUG + if (ps_r2_ls_flags.test(R2FLAG_GLOBALMATERIAL)) + mtl=ps_r2_gmaterial; +#endif + RCache.hemi.set_material(o_hemi, o_sun, 0, (mtl + .5f) / 4.f); + RCache.hemi.set_pos_faces(o_hemi_cube[CROS_impl::CUBE_FACE_POS_X], + o_hemi_cube[CROS_impl::CUBE_FACE_POS_Y], + o_hemi_cube[CROS_impl::CUBE_FACE_POS_Z]); + RCache.hemi.set_neg_faces(o_hemi_cube[CROS_impl::CUBE_FACE_NEG_X], + o_hemi_cube[CROS_impl::CUBE_FACE_NEG_Y], + o_hemi_cube[CROS_impl::CUBE_FACE_NEG_Z]); + */ + //}; + +public: + // feature level + virtual GenerationLevel GetGeneration() const override { return IRender::GENERATION_R1; } + virtual BackendAPI GetBackendAPI() const override { return IRender::BackendAPI::OpenGL; } + + virtual u32 get_dx_level() override { return 0x00090000; } + virtual bool is_sun_static() override { return true; } + + // Loading / Unloading + virtual void create() override; + virtual void destroy() override; + virtual void reset_begin() override; + virtual void reset_end() override; + virtual void level_Load(IReader* fs) override; + virtual void level_Unload() override; + + //virtual GLuint* texture_load(LPCSTR fname, u32& msize); + GLuint texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc); + virtual HRESULT shader_compile( + pcstr name, + IReader* fs, + pcstr pFunctionName, + pcstr pTarget, + u32 Flags, + void*& result) override; + + // Information + virtual void DumpStatistics(class IGameFont& font, class IPerformanceAlert* alert) override; + virtual LPCSTR getShaderPath() override { return "glr1" DELIMITER ""; } + virtual ref_shader getShader(int id); + virtual IRender_Sector* getSector(int id) override; + virtual IRenderVisual* getVisual(int id) override; + virtual IRender_Sector* detectSector(const Fvector& P) override; + IRender_Sector* detectSector(const Fvector& P, Fvector& D); + int translateSector(IRender_Sector* pSector); + virtual IRender_Target* getTarget() override; + + // Main + virtual void flush() override; + void set_Object(IRenderable* O); + virtual void add_Occluder(Fbox2& bb_screenspace) override; // mask screen region as oclluded + void add_Visual(IRenderable* root, IRenderVisual* V, Fmatrix& m) override; // add visual leaf (no culling performed at all) + void add_Geometry(IRenderVisual* V, const CFrustum& view) override; // add visual(s) (all culling performed) + + // wallmarks + virtual void add_StaticWallmark(ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V); + virtual void add_StaticWallmark( + IWallMarkArray* pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V) override; + virtual void add_StaticWallmark(const wm_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V) override; + virtual void clear_static_wallmarks() override; + virtual void add_SkeletonWallmark(intrusive_ptr wm); + virtual void add_SkeletonWallmark( + const Fmatrix* xf, CKinematics* obj, ref_shader& sh, const Fvector& start, const Fvector& dir, float size); + virtual void add_SkeletonWallmark(const Fmatrix* xf, IKinematics* obj, IWallMarkArray* pArray, const Fvector& start, + const Fvector& dir, float size) override; + + // + virtual IBlender* blender_create(CLASS_ID cls); + virtual void blender_destroy(IBlender*&); + + // + virtual IRender_ObjectSpecific* ros_create(IRenderable* parent) override; + virtual void ros_destroy(IRender_ObjectSpecific*&) override; + + // Particle library + virtual CPSLibrary* ps_library() { return &PSLibrary; } + // Lighting + virtual IRender_Light* light_create() override; + virtual IRender_Glow* glow_create() override; + + // Models + virtual IRenderVisual* model_CreateParticles(LPCSTR name) override; + virtual IRender_DetailModel* model_CreateDM(IReader* F); + virtual IRenderVisual* model_Create(LPCSTR name, IReader* data = nullptr) override; + virtual IRenderVisual* model_CreateChild(LPCSTR name, IReader* data) override; + virtual IRenderVisual* model_Duplicate(IRenderVisual* V) override; + virtual void model_Delete(IRenderVisual*& V, bool bDiscard) override; + virtual void model_Delete(IRender_DetailModel*& F); + virtual void model_Logging(bool bEnable) override { Models->Logging(bEnable); } + virtual void models_Prefetch() override; + virtual void models_Clear(bool b_complete) override; + + // Occlusion culling + virtual bool occ_visible(vis_data& V) override; + virtual bool occ_visible(Fbox& B) override; + virtual bool occ_visible(sPoly& P) override; + + // Main + void BeforeFrame() override; + + virtual void Calculate() override; + virtual void Render() override; + virtual void Screenshot(ScreenshotMode mode = SM_NORMAL, LPCSTR name = nullptr) override; + virtual void Screenshot(ScreenshotMode mode, CMemoryWriter& memory_writer) override; + virtual void ScreenshotAsyncBegin() override; + virtual void ScreenshotAsyncEnd(CMemoryWriter& memory_writer) override; + virtual void OnFrame() override; + + void BeforeWorldRender() override; //--#SM+#-- +SecondVP+ Вызывается перед началом рендера мира и пост-эффектов + void AfterWorldRender() override; //--#SM+#-- +SecondVP+ Вызывается после рендера мира и перед UI + +#ifdef USE_OGLR1 + void ObtainRequiredWindowFlags(u32& windowFlags) override; + RenderContext GetCurrentContext() const override; + void MakeContextCurrent(RenderContext context) override; +#endif + + // Render mode + virtual void rmNear() override; + virtual void rmFar() override; + virtual void rmNormal() override; + + u32 active_phase() override { return phase; } + + // Constructor/destructor/loader + CRender(); + virtual ~CRender(); + + void addShaderOption(pcstr name, pcstr value); + void clearAllShaderOptions() { m_ShaderOptions.clear(); } + +private: + xr_string m_ShaderOptions; + +protected: + virtual void ScreenshotImpl(ScreenshotMode mode, LPCSTR name, CMemoryWriter* memory_writer) override; + +private: + FS_FileSet m_file_set; +}; + +extern CRender RImplementation; diff --git a/src/Layers/xrRenderPC_GLR1/FStaticRender_Blenders.cpp b/src/Layers/xrRenderPC_GLR1/FStaticRender_Blenders.cpp new file mode 100755 index 00000000000..9a95a77efe3 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/FStaticRender_Blenders.cpp @@ -0,0 +1,47 @@ +#include "stdafx.h" +#include "Layers/xrRender/blenders/BlenderDefault.h" +#include "Layers/xrRender/blenders/Blender_default_aref.h" +#include "Layers/xrRender/blenders/Blender_Vertex.h" +#include "Layers/xrRender/blenders/Blender_Vertex_aref.h" +#include "Layers/xrRender/blenders/Blender_Screen_SET.h" +#include "Layers/xrRender/blenders/Blender_Screen_GRAY.h" +#include "Layers/xrRender/blenders/Blender_Editor_Wire.h" +#include "Layers/xrRender/blenders/Blender_Editor_Selection.h" +#include "Layers/xrRender/blenders/Blender_LaEmB.h" +#include "Layers/xrRender/blenders/Blender_Lm(EbB).h" +#include "Layers/xrRender/blenders/Blender_BmmD.h" +#include "Layers/xrRender/blenders/Blender_Shadow_World.h" +#include "Layers/xrRender/blenders/Blender_Blur.h" +#include "Layers/xrRender/blenders/Blender_Model.h" +#include "Layers/xrRender/blenders/Blender_Model_EbB.h" +#include "Layers/xrRender/blenders/Blender_detail_still.h" +#include "Layers/xrRender/blenders/Blender_tree.h" +#include "Layers/xrRender/blenders/Blender_Particle.h" + +IBlender* CRender::blender_create(CLASS_ID cls) +{ + switch (cls) + { + case B_DEFAULT: return xr_new(); + case B_DEFAULT_AREF: return xr_new(); + case B_VERT: return xr_new(); + case B_VERT_AREF: return xr_new(); + case B_SCREEN_SET: return xr_new(); + case B_SCREEN_GRAY: return xr_new(); + case B_EDITOR_WIRE: return xr_new(); + case B_EDITOR_SEL: return xr_new(); + case B_LaEmB: return nullptr; + case B_LmEbB: return xr_new(); + case B_BmmD: return xr_new(); + case B_SHADOW_WORLD: return xr_new(); + case B_BLUR: return xr_new(); + case B_MODEL: return xr_new(); + case B_MODEL_EbB: return xr_new(); + case B_DETAIL: return xr_new(); + case B_TREE: return xr_new(); + case B_PARTICLE: return xr_new(); + } + return nullptr; +} + +void CRender::blender_destroy(IBlender*& B) { xr_delete(B); } diff --git a/src/Layers/xrRenderPC_GLR1/FStaticRender_Loader.cpp b/src/Layers/xrRenderPC_GLR1/FStaticRender_Loader.cpp new file mode 100755 index 00000000000..b40b6fcb72f --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/FStaticRender_Loader.cpp @@ -0,0 +1,447 @@ +#include "stdafx.h" +#include "Layers/xrRender/FBasicVisual.h" +#include "xrCore/FMesh.hpp" +#include "Common/LevelStructure.hpp" +#include "xrEngine/x_ray.h" +#include "xrEngine/IGame_Persistent.h" +#include "xrCore/stream_reader.h" + +#pragma warning(push) +#pragma warning(disable : 4995) +#include +#pragma warning(pop) + +void CRender::level_Load(IReader* fs) +{ + R_ASSERT(nullptr != g_pGameLevel); + R_ASSERT(!b_loaded); + + // Begin + pApp->LoadBegin(); + Resources->DeferredLoad(TRUE); + IReader* chunk; + + // Shaders + g_pGamePersistent->SetLoadStageTitle("st_loading_shaders"); + g_pGamePersistent->LoadTitle(); + { + chunk = fs->open_chunk(fsL_SHADERS); + R_ASSERT2(chunk, "Level doesn't builded correctly."); + u32 count = chunk->r_u32(); + Shaders.resize(count); + for (u32 i = 0; i < count; i++) // skip first shader as "reserved" one + { + string512 n_sh, n_tlist; + LPCSTR n = LPCSTR(chunk->pointer()); + chunk->skip_stringZ(); + if (0 == n[0]) + continue; + xr_strcpy(n_sh, n); + pstr delim = strchr(n_sh, '/'); + *delim = 0; + xr_strcpy(n_tlist, delim + 1); + Shaders[i] = Resources->Create(n_sh, n_tlist); + } + chunk->close(); + } + + // Components + L_Shadows = xr_new(); + L_Projector = xr_new(); + L_Glows = xr_new(); + Wallmarks = xr_new(); + Details = xr_new(); + + rmFar(); + rmNormal(); + + marker = 0; + + if (!GEnv.isDedicatedServer) + { + // VB,IB,SWI + g_pGamePersistent->SetLoadStageTitle("st_loading_geometry"); + g_pGamePersistent->LoadTitle(); + { + CStreamReader* geom = FS.rs_open("$level$", "level.geom"); + R_ASSERT2(geom, "level.geom"); + LoadBuffers(geom, false); + LoadSWIs(geom); + FS.r_close(geom); + } + + //...and alternate/fast geometry + if (ps_r1_force_geomx) + { + CStreamReader* geom = FS.rs_open("$level$", "level.geomx"); + R_ASSERT2(geom, "level.geomX"); + LoadBuffers(geom, true); + FS.r_close(geom); + } + + // Visuals + g_pGamePersistent->SetLoadStageTitle("st_loading_spatial_db"); + g_pGamePersistent->LoadTitle(); + chunk = fs->open_chunk(fsL_VISUALS); + LoadVisuals(chunk); + chunk->close(); + + // Details + g_pGamePersistent->SetLoadStageTitle("st_loading_details"); + g_pGamePersistent->LoadTitle(); + Details->Load(); + } + + // Sectors + g_pGamePersistent->SetLoadStageTitle("st_loading_sectors_portals"); + g_pGamePersistent->LoadTitle(); + LoadSectors(fs); + + // HOM + HOM.Load(); + + // Lights + g_pGamePersistent->SetLoadStageTitle("st_loading_lights"); + g_pGamePersistent->LoadTitle(); + LoadLights(fs); + + // End + pApp->LoadEnd(); + b_loaded = TRUE; +} + +void CRender::level_Unload() +{ + if (nullptr == g_pGameLevel) + return; + if (!b_loaded) + return; + + u32 I; + + // HOM + HOM.Unload(); + + //*** Details + Details->Unload(); + + //*** Sectors + // 1. + xr_delete(rmPortals); + pLastSector = nullptr; + vLastCameraPos.set(flt_max, flt_max, flt_max); + uLastLTRACK = 0; + + // 2. + for (I = 0; I < Sectors.size(); I++) + xr_delete(Sectors[I]); + Sectors.clear(); + // 3. + for (I = 0; I < Portals.size(); I++) + xr_delete(Portals[I]); + Portals.clear(); + + //*** Lights + L_Glows->Unload(); + Lights.Unload(); + + //*** Visuals + for (I = 0; I < Visuals.size(); I++) + { + Visuals[I]->Release(); + xr_delete(Visuals[I]); + } + Visuals.clear(); + + //*** SWI + for (I = 0; I < SWIs.size(); I++) + xr_free(SWIs[I].sw); + SWIs.clear(); + + //*** VB/IB + for (I = 0; I < nVB.size(); I++) + { + nVB[I].Release(); + } + + for (I = 0; I < xVB.size(); I++) + { + xVB[I].Release(); + } + nVB.clear(); + xVB.clear(); + + for (I = 0; I < nIB.size(); I++) + { + nIB[I].Release(); + } + + for (I = 0; I < xIB.size(); I++) + { + xIB[I].Release(); + } + + nIB.clear(); + xIB.clear(); + nDC.clear(); + xDC.clear(); + + //*** Components + xr_delete(Details); + xr_delete(Wallmarks); + xr_delete(L_Glows); + xr_delete(L_Projector); + xr_delete(L_Shadows); + + //*** Shaders + Shaders.clear(); + +#ifdef DEBUG + Resources->DBG_VerifyGeoms(); + Resources->DBG_VerifyTextures(); +#endif + b_loaded = FALSE; +} + +void CRender::LoadBuffers(CStreamReader* base_fs, bool alternative) +{ + Resources->Evict(); + + // Vertex buffers + if (base_fs->find_chunk(fsL_VB)) + { + xr_vector& _DC = alternative ? xDC : nDC; + xr_vector& _VB = alternative ? xVB : nVB; + + // Use DX9-style declarators + CStreamReader* fs = base_fs->open_chunk(fsL_VB); + u32 count = fs->r_u32(); + _DC.resize(count); + _VB.resize(count); + + u32 buffer_size = (MAXD3DDECLLENGTH + 1) * sizeof(VertexElement); + VertexElement* dcl = (VertexElement*)xr_alloca(buffer_size); + + for (u32 i = 0; i < count; i++) + { + // decl + + // D3DVERTEXELEMENT9 *dcl = (D3DVERTEXELEMENT9*) fs->pointer(); + + fs->r(dcl, buffer_size); + fs->advance(-(int)buffer_size); + + u32 dcl_len = GetDeclLength(dcl) + 1; + + _DC[i].resize(dcl_len); + fs->r(_DC[i].begin(), dcl_len * sizeof(VertexElement)); + //.????????? remove T&B from _DC[] + + // count, size + u32 vCount = fs->r_u32(); + u32 vSize = GetDeclVertexSize(dcl, 0); + Msg("* [Loading VB] %d verts, %d Kb", vCount, (vCount * vSize) / 1024); + + // Create and fill + _VB[i].Create(vCount * vSize); + u8* pData = static_cast(_VB[i].Map()); + fs->r(pData, vCount * vSize); + // CopyMemory (pData,fs->pointer(),vCount*vSize); //.???? copy while skip T&B + _VB[i].Unmap(true); // upload vertex data + + // fs->advance (vCount*vSize); + } + fs->close(); + } + else + { + FATAL("DX7-style FVFs unsupported"); + } + + // Index buffers + if (base_fs->find_chunk(fsL_IB)) + { + xr_vector& _IB = alternative ? xIB : nIB; + + CStreamReader* fs = base_fs->open_chunk(fsL_IB); + u32 count = fs->r_u32(); + _IB.resize(count); + for (u32 i = 0; i < count; i++) + { + u32 iCount = fs->r_u32(); + Msg("* [Loading IB] %d indices, %d Kb", iCount, (iCount * 2) / 1024); + + // Create and fill + _IB[i].Create(iCount * 2); + u8* pData = static_cast(_IB[i].Map()); + // CopyMemory (pData,fs->pointer(),iCount*2); + fs->r(pData, iCount * 2); + _IB[i].Unmap(true); // upload index data + + // fs->advance (iCount*2); + } + fs->close(); + } +} + +void CRender::LoadVisuals(IReader* fs) +{ + IReader* chunk = nullptr; + u32 index = 0; + dxRender_Visual* V = nullptr; + ogf_header H; + + while ((chunk = fs->open_chunk(index)) != nullptr) + { + chunk->r_chunk_safe(OGF_HEADER, &H, sizeof(H)); + V = Models->Instance_Create(H.type); + V->Load(nullptr, chunk, 0); + Visuals.push_back(V); + + chunk->close(); + index++; + } +} + +void CRender::LoadLights(IReader* fs) +{ + // lights + Lights.Load(fs); + + // glows + IReader* chunk = fs->open_chunk(fsL_GLOWS); + R_ASSERT(chunk && "Can't find glows"); + L_Glows->Load(chunk); + chunk->close(); +} + +void CRender::LoadSectors(IReader* fs) +{ + // allocate memory for portals + u32 size = fs->find_chunk(fsL_PORTALS); + R_ASSERT(0 == size % sizeof(CPortal::b_portal)); + u32 count = size / sizeof(CPortal::b_portal); + Portals.resize(count); + for (u32 c = 0; c < count; c++) + Portals[c] = xr_new(); + + // load sectors + IReader* S = fs->open_chunk(fsL_SECTORS); + for (u32 i = 0;; i++) + { + IReader* P = S->open_chunk(i); + if (nullptr == P) + break; + + CSector* __S = xr_new(); + __S->load(*P); + Sectors.push_back(__S); + + P->close(); + } + S->close(); + + // load portals + if (count) + { + bool do_rebuild = true; + const bool use_cache = strstr(Core.Params, "-cdb_cache"); + + string_path fName; + strconcat(fName, "cdb_cache" DELIMITER, FS.get_path("$level$")->m_Add, "portals.bin"); + FS.update_path(fName, "$app_data_root$", fName); + + // build portal model + rmPortals = xr_new(); + rmPortals->set_version(fs->get_age()); + if (use_cache && FS.exist(fName) && rmPortals->deserialize(fName)) + { +#ifndef MASTER_GOLD + Msg("* Loaded portals cache (%s)...", fName); +#endif + do_rebuild = false; + } + else + { +#ifndef MASTER_GOLD + Msg("* Portals cache for '%s' was not loaded. " + "Building the model from scratch..", fName); +#endif + } + + CDB::Collector CL; + fs->find_chunk(fsL_PORTALS); + for (u32 i = 0; i < count; i++) + { + CPortal::b_portal P; + fs->r(&P, sizeof(P)); + CPortal* __P = (CPortal*)Portals[i]; + __P->Setup(P.vertices.begin(), P.vertices.size(), (CSector*)getSector(P.sector_front), + (CSector*)getSector(P.sector_back)); + if (do_rebuild) + { + for (u32 j = 2; j < P.vertices.size(); j++) + CL.add_face_packed_D(P.vertices[0], P.vertices[j - 1], P.vertices[j], u32(i)); + } + } + + if (do_rebuild) + { + if (CL.getTS() < 2) + { + Fvector v1, v2, v3; + v1.set(-20000.f, -20000.f, -20000.f); + v2.set(-20001.f, -20001.f, -20001.f); + v3.set(-20002.f, -20002.f, -20002.f); + CL.add_face_packed_D(v1, v2, v3, 0); + } + rmPortals->build(CL.getV(), int(CL.getVS()), CL.getT(), int(CL.getTS())); + if (use_cache) + rmPortals->serialize(fName); + } + } + else + { + rmPortals = nullptr; + } + + // debug + // for (int d=0; dDebugDump (); + + pLastSector = nullptr; +} + +void CRender::LoadSWIs(CStreamReader* base_fs) +{ + // allocate memory for portals + if (base_fs->find_chunk(fsL_SWIS)) + { + CStreamReader* fs = base_fs->open_chunk(fsL_SWIS); + u32 item_count = fs->r_u32(); + + xr_vector::iterator it = SWIs.begin(); + xr_vector::iterator it_e = SWIs.end(); + + for (; it != it_e; ++it) + xr_free((*it).sw); + + SWIs.clear(); + + SWIs.resize(item_count); + for (u32 c = 0; c < item_count; c++) + { + FSlideWindowItem& swi = SWIs[c]; + swi.reserved[0] = fs->r_u32(); + swi.reserved[1] = fs->r_u32(); + swi.reserved[2] = fs->r_u32(); + swi.reserved[3] = fs->r_u32(); + swi.count = fs->r_u32(); + VERIFY(NULL == swi.sw); + swi.sw = xr_alloc(swi.count); + fs->r(swi.sw, sizeof(FSlideWindow) * swi.count); + } + + fs->close(); + } +} diff --git a/src/Layers/xrRenderPC_GLR1/FStaticRender_RenderTarget.cpp b/src/Layers/xrRenderPC_GLR1/FStaticRender_RenderTarget.cpp new file mode 100755 index 00000000000..d3fe8a736f8 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/FStaticRender_RenderTarget.cpp @@ -0,0 +1,414 @@ +#include "stdafx.h" +#include "FStaticRender_RenderTarget.h" +#include "FStaticRender_Types.h" +#include "xrEngine/IGame_Persistent.h" + +CRenderTarget::CRenderTarget() +{ + bAvailable = FALSE; + rt_Generic = nullptr; + rt_color_map = nullptr; + rt_temp_zb = nullptr; + rt_Depth = nullptr; + + param_blur = 0.f; + param_gray = 0.f; + param_noise = 0.f; + param_duality_h = 0.f; + param_duality_v = 0.f; + param_noise_fps = 25.f; + param_noise_scale = 1.f; + + param_color_map_influence = 0.0f; + param_color_map_interpolate = 0.0f; + + im_noise_time = 1.f / 100.0f; + im_noise_shift_w = 0; + im_noise_shift_h = 0; + + param_color_base = color_rgba(127, 127, 127, 0); + param_color_gray = color_rgba(85, 85, 85, 0); + param_color_add.set(0.0f, 0.0f, 0.0f); + + bAvailable = Create(); + Msg("* SSample: %s", bAvailable ? "enabled" : "disabled"); +} + +BOOL CRenderTarget::Create() +{ + curWidth = Device.dwWidth; + curHeight = Device.dwHeight; + + // Select mode to operate in + float amount = ps_r__Supersample ? float(ps_r__Supersample) : 1; + float scale = _sqrt(amount); + rtWidth = clampr(iFloor(scale * Device.dwWidth + .5f), 128, 2048); + rtHeight = clampr(iFloor(scale * Device.dwHeight + .5f), 128, 2048); + while (rtWidth % 2) + rtWidth--; + while (rtHeight % 2) + rtHeight--; + Msg("* SSample: %dx%d", rtWidth, rtHeight); + + // Bufferts + rt_Base.resize(HW.BackBufferCount); + for (u32 i = 0; i < HW.BackBufferCount; i++) + { + string32 temp; + xr_sprintf(temp, "%s%d", r1_RT_base, i); + rt_Base[i].create(temp, curWidth, curHeight, HW.Caps.fTarget, 1, { CRT::CreateBase }); + } + rt_Base_Depth.create(r1_RT_base_depth, curWidth, curHeight, HW.Caps.fDepth, 1, { CRT::CreateBase }); + + rt_Generic.create(r1_RT_generic, rtWidth, rtHeight, HW.Caps.fTarget); + rt_distort.create(rt_RT_distort, rtWidth, rtHeight, HW.Caps.fTarget); + if (RImplementation.o.color_mapping) + { + //rt_color_map.create(rt_RT_color_map, rtWidth, rtHeight, HW.Caps.fTarget); + rt_color_map.create(rt_RT_color_map, curWidth, curHeight, HW.Caps.fTarget); + } + // RImplementation.o.color_mapping = RT_color_map->valid(); + + if ((rtHeight != Device.dwHeight) || (rtWidth != Device.dwWidth)) + { + rt_Depth.create(r1_RT_depth, rtWidth, rtHeight, HW.Caps.fDepth, 0, { CRT::CreateSurface }); + } + else + { + rt_Depth = rt_Base_Depth; + } + + // Temp ZB, used by some of the shadowing code + rt_temp_zb.create(rt_RT_temp_zb, 512, 512, HW.Caps.fDepth, 0, { CRT::CreateSurface }); + + // Igor: TMP + // Create an RT for online screenshot makining + rt_async_ss.create(r1_RT_async_ss, rtWidth, rtHeight, HW.Caps.fTarget, 0, { CRT::CreateSurface }); + + // Shaders and stream + s_postprocess[0].create("postprocess"); + if (RImplementation.o.distortion) + s_postprocess_D[0].create("postprocess_d"); + if (RImplementation.o.color_mapping) + { + s_postprocess[1].create("postprocess_cm"); + if (RImplementation.o.distortion) + s_postprocess_D[1].create("postprocess_dcm"); + if (!s_postprocess[1] || !s_postprocess_D[1]) + { + Log("~ Color mapping disabled due to lack of one shader or both shaders"); + s_postprocess[1].destroy(); + s_postprocess_D[1].destroy(); + rt_color_map->destroy(); + RImplementation.o.color_mapping = FALSE; + } + } + g_postprocess.create( + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX3, RCache.Vertex.Buffer(), RCache.QuadIB); + return rt_Generic->valid() && rt_distort->valid(); +} + +CRenderTarget::~CRenderTarget() +{ + rt_Depth.destroy(); + s_postprocess_D[1].destroy(); + s_postprocess[1].destroy(); + s_postprocess_D[0].destroy(); + s_postprocess[1].destroy(); + g_postprocess.destroy(); + rt_distort.destroy(); + rt_color_map.destroy(); + rt_Generic.destroy(); +} + +void CRenderTarget::calc_tc_noise(Fvector2& p0, Fvector2& p1) +{ + //. CTexture* T = RCache.get_ActiveTexture (2); + //. VERIFY2 (T, "Texture #3 in noise shader should be setted up"); + //. u32 tw = iCeil(float(T->get_Width ())*param_noise_scale+EPS_S); + //. u32 th = iCeil(float(T->get_Height ())*param_noise_scale+EPS_S); + u32 tw = iCeil(256 * param_noise_scale + EPS_S); + u32 th = iCeil(256 * param_noise_scale + EPS_S); + VERIFY2(tw && th, "Noise scale can't be zero in any way"); + //. if (bDebug) Msg ("%d,%d,%f",tw,th,param_noise_scale); + + // calculate shift from FPSes + im_noise_time -= Device.fTimeDelta; + if (im_noise_time < 0) + { + im_noise_shift_w = ::Random.randI(tw ? tw : 1); + im_noise_shift_h = ::Random.randI(th ? th : 1); + float fps_time = 1 / param_noise_fps; + while (im_noise_time < 0) + im_noise_time += fps_time; + } + + u32 shift_w = im_noise_shift_w; + u32 shift_h = im_noise_shift_h; + float start_u = (float(shift_w) + .5f) / (tw); + float start_v = (float(shift_h) + .5f) / (th); + u32 _w = Device.dwWidth; + u32 _h = Device.dwHeight; + u32 cnt_w = _w / tw; + u32 cnt_h = _h / th; + float end_u = start_u + float(cnt_w) + 1; + float end_v = start_v + float(cnt_h) + 1; + + p0.set(start_u, start_v); + p1.set(end_u, end_v); +} + +void CRenderTarget::calc_tc_duality_ss(Fvector2& r0, Fvector2& r1, Fvector2& l0, Fvector2& l1) +{ + // Calculate ordinaty TCs from blur and SS + float tw = float(rtWidth); + float th = float(rtHeight); + if (rtHeight != Device.dwHeight) + param_blur = 1.f; + Fvector2 shift, p0, p1; + shift.set(.5f / tw, .5f / th); + shift.mul(param_blur); + p0.set(.5f / tw, .5f / th).add(shift); + p1.set((tw + .5f) / tw, (th + .5f) / th).add(shift); + + // Calculate Duality TC + float shift_u = param_duality_h * .5f; + float shift_v = param_duality_v * .5f; + + r0.set(p0.x, p0.y); + r1.set(p1.x - shift_u, p1.y - shift_v); + l0.set(p0.x + shift_u, p0.y + shift_v); + l1.set(p1.x, p1.y); +} + +bool CRenderTarget::NeedColorMapping() +{ + return RImplementation.o.color_mapping && (param_color_map_influence > 0.001f); +} + +BOOL CRenderTarget::NeedPostProcess() +{ + bool _blur = (param_blur > 0.001f); + bool _gray = (param_gray > 0.001f); + bool _noise = (param_noise > 0.001f); + bool _dual = (param_duality_h > 0.001f) || (param_duality_v > 0.001f); + + bool _menu_pp = g_pGamePersistent ? g_pGamePersistent->OnRenderPPUI_query() : false; + + bool _cmap = NeedColorMapping(); + + bool _cbase = false; + { + int _r = color_get_R(param_color_base); + _r = _abs(_r - int(0x7f)); + int _g = color_get_G(param_color_base); + _g = _abs(_g - int(0x7f)); + int _b = color_get_B(param_color_base); + _b = _abs(_b - int(0x7f)); + if (_r > 2 || _g > 2 || _b > 2) + _cbase = true; + } + bool _cadd = false; + { + // int _r = color_get_R(param_color_add) ; + // int _g = color_get_G(param_color_add) ; + // int _b = color_get_B(param_color_add) ; + // if (_r>2 || _g>2 || _b>2) _cadd = true ; + int _r = _abs((int)(param_color_add.x * 255)); + int _g = _abs((int)(param_color_add.y * 255)); + int _b = _abs((int)(param_color_add.z * 255)); + if (_r > 2 || _g > 2 || _b > 2) + _cadd = true; + } + return _blur || _gray || _noise || _dual || _cbase || _cadd || _cmap || _menu_pp; +} + +BOOL CRenderTarget::Perform() +{ + return Available() && (((BOOL)RImplementation.m_bMakeAsyncSS) || NeedPostProcess() || (ps_r__Supersample > 1) || + (frame_distort == (Device.dwFrame - 1))); +} + +#define SHOW(a) Log(#a, a); +#define SHOWX(a) Msg("%s %x", #a, a); +void CRenderTarget::Begin() +{ + /* + if (g_pGameLevel->IR_GetKeyState(SDL_SCANCODE_LSHIFT)) + { + Msg ("[%5d]------------------------",Device.dwFrame); + SHOW (param_blur) + SHOW (param_gray) + SHOW (param_duality_h) + SHOW (param_duality_v) + SHOW (param_noise) + SHOW (param_noise_scale) + SHOW (param_noise_fps) + + SHOWX (param_color_base) + SHOWX (param_color_gray) + SHOWX (param_color_add) + } + */ + + if (!Perform()) + { + // Base RT + RCache.set_RT(get_base_rt()); + RCache.set_ZB(get_base_zb()); + curWidth = Device.dwWidth; + curHeight = Device.dwHeight; + } + else + { + // Our + RCache.set_RT(rt_Generic->pRT); + RCache.set_ZB(rt_Depth->pRT); + curWidth = rtWidth; + curHeight = rtHeight; + } + Device.Clear(); +} + +struct TL_2c3uv +{ + Fvector4 p; + u32 color0; + u32 color1; + Fvector2 uv[3]; + + void set(float x, float y, u32 c0, u32 c1, float u0, float v0, float u1, float v1, float u2, float v2) + { + p.set(x, y, EPS_S, 1.f); + color0 = c0; + color1 = c1; + uv[0].set(u0, v0); + uv[1].set(u1, v1); + uv[2].set(u2, v2); + } +}; + +void CRenderTarget::DoAsyncScreenshot() +{ + // Igor: screenshot will not have postprocess applied. + // TODO: fox that later + if (RImplementation.m_bMakeAsyncSS) + { + HRESULT hr; + + glBindTexture(GL_TEXTURE_2D, t_ss_async); + CHK_GL(glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, Device.dwWidth, Device.dwHeight, 0)); + + RImplementation.m_bMakeAsyncSS = false; + } +} + +void CRenderTarget::End() +{ + if (g_pGamePersistent) + g_pGamePersistent->OnRenderPPUI_main(); // PP-UI + + // find if distortion is needed at all + BOOL bPerform = Perform(); + BOOL bDistort = RImplementation.o.distortion; + BOOL bCMap = NeedColorMapping(); + bool _menu_pp = g_pGamePersistent ? g_pGamePersistent->OnRenderPPUI_query() : false; + if ((0 == RImplementation.mapDistort.size()) && !_menu_pp) + bDistort = FALSE; + if (bDistort) + phase_distortion(); + + // combination/postprocess + RCache.set_RT(get_base_rt()); + RCache.set_ZB(get_base_zb()); + curWidth = Device.dwWidth; + curHeight = Device.dwHeight; + + if (!bPerform) + return; + + int gblend = clampr(iFloor((1 - param_gray) * 255.f), 0, 255); + int nblend = clampr(iFloor((1 - param_noise) * 255.f), 0, 255); + u32 p_color = subst_alpha(param_color_base, nblend); + u32 p_gray = subst_alpha(param_color_gray, gblend); + Fvector p_brightness = param_color_add; + // Msg ("param_gray:%f(%d),param_noise:%f(%d)",param_gray,gblend,param_noise,nblend); + // Msg ("base: %d,%d,%d", color_get_R(p_color), color_get_G(p_color), + // color_get_B(p_color)); + // Msg ("gray: %d,%d,%d", color_get_R(p_gray), color_get_G(p_gray), color_get_B(p_gray)); + // Msg ("add: %d,%d,%d", color_get_R(p_brightness), color_get_G(p_brightness), + // color_get_B(p_brightness)); + + // Draw full-screen quad textured with our scene image + u32 Offset; + float _w = float(Device.dwWidth); + float _h = float(Device.dwHeight); + + Fvector2 n0, n1, r0, r1, l0, l1; + calc_tc_duality_ss(r0, r1, l0, l1); + calc_tc_noise(n0, n1); + + // Fill vertex buffer + float du = ps_r1_pps_u, dv = ps_r1_pps_v; + TL_2c3uv* pv = (TL_2c3uv*)RCache.Vertex.Lock(4, g_postprocess.stride(), Offset); + pv->set(du + 0, dv + float(_h), p_color, p_gray, r0.x, r1.y, l0.x, l1.y, n0.x, n1.y); + pv++; + pv->set(du + 0, dv + 0, p_color, p_gray, r0.x, r0.y, l0.x, l0.y, n0.x, n0.y); + pv++; + pv->set(du + float(_w), dv + float(_h), p_color, p_gray, r1.x, r1.y, l1.x, l1.y, n1.x, n1.y); + pv++; + pv->set(du + float(_w), dv + 0, p_color, p_gray, r1.x, r0.y, l1.x, l0.y, n1.x, n0.y); + pv++; + RCache.Vertex.Unlock(4, g_postprocess.stride()); + + static shared_str s_colormap = "c_colormap"; + if (bCMap) + { + RCache.set_RT(rt_color_map->pRT); + + // Prepare colormapped buffer + RCache.set_Element(bDistort ? s_postprocess_D[1]->E[4] : s_postprocess[1]->E[4]); + RCache.set_Geometry(g_postprocess); + RCache.set_c(s_colormap, param_color_map_influence, param_color_map_interpolate, 0.0f, 0.0f); + RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 4, 0, 2); + + RCache.set_RT(get_base_rt()); + // return; + } + + // Element 0 for for normal post-process + // Element 4 for color map post-process + // int iShaderElement = bCMap ? 4 : 0; + // RCache.set_Element (bDistort ? s_postprocess_D->E[iShaderElement] : s_postprocess->E[iShaderElement]); + + RCache.set_Shader(bDistort ? s_postprocess_D[bCMap] : s_postprocess[bCMap]); + + // RCache.set_Shader (bDistort ? s_postprocess_D : s_postprocess); + + // Actual rendering + static shared_str s_brightness = "c_brightness"; + RCache.set_c(s_brightness, p_brightness.x, p_brightness.y, p_brightness.z, 0.0f); + RCache.set_c(s_colormap, param_color_map_influence, param_color_map_interpolate, 0.0f, 0.0f); + RCache.set_Geometry(g_postprocess); + RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 4, 0, 2); +} + +void CRenderTarget::phase_distortion() +{ + /* + frame_distort = Device.dwFrame; + RCache.set_RT(rt_distort->pRT); + RCache.set_ZB(rt_Depth->pRT); + RCache.set_CullMode(CULL_CCW); + RCache.set_ColorWriteEnable(); + RCache.ClearRT(rt_distort, color_rgba(127, 127, 127, 127)); + + if (g_pGameLevel && g_pGamePersistent && !g_pGamePersistent->OnRenderPPUI_query()) + RImplementation.r_dsgraph_render_distort(); + else + RImplementation.mapDistort.clear(); + + if (g_pGamePersistent) + g_pGamePersistent->OnRenderPPUI_PP(); // PP-UI + */ +} diff --git a/src/Layers/xrRenderPC_GLR1/FStaticRender_RenderTarget.h b/src/Layers/xrRenderPC_GLR1/FStaticRender_RenderTarget.h new file mode 100755 index 00000000000..08089302d48 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/FStaticRender_RenderTarget.h @@ -0,0 +1,107 @@ +#pragma once + +#include "Layers/xrRender/ColorMapManager.h" + +class CRenderTarget : public IRender_Target +{ +private: + BOOL bAvailable; + u32 rtWidth; + u32 rtHeight; + + u32 curWidth; + u32 curHeight; + +public: + // Base targets + xr_vector rt_Base; + ref_rt rt_Base_Depth; + +private: + ref_rt rt_Generic; + ref_rt rt_Depth; + + ref_rt rt_color_map; + ref_rt rt_distort; + + // Can't implement in a single pass of a shader since + // should be compiled only for the hardware that supports it. + ref_shader s_postprocess[2]; // Igor: 0 - plain, 1 - colormapped + ref_shader s_postprocess_D[2]; // Igor: 0 - plain, 1 - colormapped + ref_geom g_postprocess; + + float im_noise_time; + u32 im_noise_shift_w; + u32 im_noise_shift_h; + + float param_blur; + float param_gray; + float param_duality_h; + float param_duality_v; + float param_noise; + float param_noise_scale; + float param_noise_fps; + + // Color mapping + float param_color_map_influence; + float param_color_map_interpolate; + ColorMapManager color_map_manager; + + u32 param_color_base; + u32 param_color_gray; + Fvector param_color_add; + + u32 frame_distort; + +public: + ref_rt rt_temp_zb; + + // Igor: for async screenshots + ref_rt rt_async_ss; // 32bit (r,g,b,a) is situated in the system memory + GLuint t_ss_async; + +private: + BOOL Create(); + bool NeedColorMapping(); + BOOL NeedPostProcess(); + BOOL Available() { return bAvailable; } + BOOL Perform(); + + void calc_tc_noise(Fvector2& p0, Fvector2& p1); + void calc_tc_duality_ss(Fvector2& r0, Fvector2& r1, Fvector2& l0, Fvector2& l1); + void phase_distortion(); + +public: + CRenderTarget(); + ~CRenderTarget(); + + void Begin(); + void End(); + + void DoAsyncScreenshot(); + + GLuint get_base_rt() { return rt_Base[HW.CurrentBackBuffer]->pRT; } + GLuint get_base_zb() { return rt_Base_Depth->pZRT; } + + virtual void set_blur(float f) { param_blur = f; } + virtual void set_gray(float f) { param_gray = f; } + virtual void set_duality_h(float f) { param_duality_h = _abs(f); } + virtual void set_duality_v(float f) { param_duality_v = _abs(f); } + virtual void set_noise(float f) { param_noise = f; } + virtual void set_noise_scale(float f) { param_noise_scale = f; } + virtual void set_noise_fps(float f) { param_noise_fps = _abs(f) + EPS_S; } + virtual void set_color_base(u32 f) { param_color_base = f; } + virtual void set_color_gray(u32 f) { param_color_gray = f; } + virtual void set_color_add(const Fvector& f) { param_color_add = f; } + virtual void set_cm_imfluence(float f) { param_color_map_influence = f; } + virtual void set_cm_interpolate(float f) { param_color_map_interpolate = f; } + virtual void set_cm_textures(const shared_str& tex0, const shared_str& tex1) + { + color_map_manager.SetTextures(tex0, tex1); + } + + virtual u32 get_width() { return curWidth; } + virtual u32 get_height() { return curHeight; } + u32 get_rtwidth() { return rtWidth; } + u32 get_rtheight() { return rtHeight; } +}; diff --git a/src/Layers/xrRenderPC_GLR1/FStaticRender_Shaders.cpp b/src/Layers/xrRenderPC_GLR1/FStaticRender_Shaders.cpp new file mode 100755 index 00000000000..dcb67d89c28 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/FStaticRender_Shaders.cpp @@ -0,0 +1,1005 @@ +#include "stdafx.h" +#include "FStaticRender.h" +#include "Layers/xrRender/ShaderResourceTraits.h" +#include "xrCore/FileCRC32.h" + +#if 0 +template +static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name, + T*& result, bool const disasm) +{ + HRESULT _hr = ShaderTypeTraits::CreateHWShader(buffer, buffer_size, result->sh); + if (!SUCCEEDED(_hr)) + { + Log("! Shader: ", file_name); + Msg("! CreateHWShader hr == 0x%08x", _hr); + return E_FAIL; + } + + LPCVOID data = nullptr; + + _hr = D3DXFindShaderComment(buffer, MAKEFOURCC('C', 'T', 'A', 'B'), &data, nullptr); + + if (SUCCEEDED(_hr) && data) + { + // Parse constant table data + LPD3DXSHADER_CONSTANTTABLE pConstants = LPD3DXSHADER_CONSTANTTABLE(data); + result->constants.parse(pConstants, ShaderTypeTraits::GetShaderDest()); + } + else + Msg("! D3DXFindShaderComment %s hr == 0x%08x", file_name, _hr); + + if (disasm) + { + ID3DXBuffer* disasm = nullptr; + D3DXDisassembleShader(LPDWORD(buffer), FALSE, nullptr, &disasm); + if (!disasm) + return _hr; + + string_path dname; + strconcat(sizeof(dname), dname, "disasm" DELIMITER, file_name, ('v' == pTarget[0]) ? ".vs" : ".ps"); + IWriter* W = FS.w_open("$app_data_root$", dname); + W->w(disasm->GetBufferPointer(), disasm->GetBufferSize()); + FS.w_close(W); + _RELEASE(disasm); + } + + return _hr; +} + +inline HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name, + void*& result, bool const disasm) +{ + if (pTarget[0] == 'p') + return create_shader(pTarget, buffer, buffer_size, file_name, (SPS*&)result, disasm); + + if (pTarget[0] == 'v') + return create_shader(pTarget, buffer, buffer_size, file_name, (SVS*&)result, disasm); + + NODEFAULT; + return E_FAIL; +} + + +class includer : public ID3DXInclude +{ +public: + HRESULT __stdcall Open( + D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes) + { + string_path pname; + strconcat(sizeof(pname), pname, GEnv.Render->getShaderPath(), pFileName); + IReader* R = FS.r_open("$game_shaders$", pname); + if (nullptr == R) + { + // possibly in shared directory or somewhere else - open directly + R = FS.r_open("$game_shaders$", pFileName); + if (nullptr == R) + return E_FAIL; + } + + // duplicate and zero-terminate + const size_t size = R->length(); + u8* data = xr_alloc(size + 1); + CopyMemory(data, R->pointer(), size); + data[size] = 0; + FS.r_close(R); + + *ppData = data; + *pBytes = size; + return D3D_OK; + } + HRESULT __stdcall Close(LPCVOID pData) + { + xr_free(pData); + return D3D_OK; + } +}; + +static inline bool match_shader_id( + LPCSTR const debug_shader_id, LPCSTR const full_shader_id, FS_FileSet const& file_set, string_path& result); + + +HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName, pcstr pTarget, u32 Flags, void*& result) +{ + D3DXMACRO defines[128]; + int def_it = 0; + + char sh_name[MAX_PATH] = ""; + u32 len = 0; + // options + if (o.forceskinw) + { + defines[def_it].Name = "SKIN_COLOR"; + defines[def_it].Definition = "1"; + def_it++; + } + sh_name[len] = '0' + char(o.forceskinw); + ++len; + + // skinning + if (m_skinning < 0) + { + defines[def_it].Name = "SKIN_NONE"; + defines[def_it].Definition = "1"; + def_it++; + sh_name[len] = '1'; + ++len; + } + else + { + sh_name[len] = '0'; + ++len; + } + + if (0 == m_skinning) + { + defines[def_it].Name = "SKIN_0"; + defines[def_it].Definition = "1"; + def_it++; + } + sh_name[len] = '0' + char(0 == m_skinning); + ++len; + + if (1 == m_skinning) + { + defines[def_it].Name = "SKIN_1"; + defines[def_it].Definition = "1"; + def_it++; + } + sh_name[len] = '0' + char(1 == m_skinning); + ++len; + + if (2 == m_skinning) + { + defines[def_it].Name = "SKIN_2"; + defines[def_it].Definition = "1"; + def_it++; + } + sh_name[len] = '0' + char(2 == m_skinning); + ++len; + + if (3 == m_skinning) + { + defines[def_it].Name = "SKIN_3"; + defines[def_it].Definition = "1"; + def_it++; + } + sh_name[len] = '0' + char(3 == m_skinning); + ++len; + + if (4 == m_skinning) + { + defines[def_it].Name = "SKIN_4"; + defines[def_it].Definition = "1"; + def_it++; + } + sh_name[len] = '0' + char(4 == m_skinning); + ++len; + + sh_name[len] = '\0'; + + // finish + defines[def_it].Name = nullptr; + defines[def_it].Definition = nullptr; + def_it++; + R_ASSERT(def_it < 128); + + HRESULT _result = E_FAIL; + + char extension[3]; + strncpy_s(extension, pTarget, 2); + + string_path filename; + strconcat(sizeof(filename), filename, "glr1" DELIMITER, name, ".", extension); + + string_path folder_name, folder; + strconcat(sizeof(folder), folder, "glr1" DELIMITER "objects" DELIMITER, filename); + + FS.update_path(folder_name, "$game_shaders$", folder); + xr_strcat(folder_name, DELIMITER); + + m_file_set.clear(); + FS.file_list(m_file_set, folder_name, FS_ListFiles | FS_RootOnly, "*"); + + string_path temp_file_name, file_name; + if (!match_shader_id(name, sh_name, m_file_set, temp_file_name)) + { + string_path file; + strconcat(sizeof(file), file, "shaders_cache_oxr" DELIMITER, filename, DELIMITER, sh_name); + strconcat(sizeof(filename), filename, filename, DELIMITER, sh_name); + FS.update_path(file_name, "$app_data_root$", file); + } + else + { + xr_strcpy(file_name, folder_name); + xr_strcat(file_name, temp_file_name); + } + + string_path shadersFolder; + FS.update_path(shadersFolder, "$game_shaders$", GEnv.Render->getShaderPath()); + + u32 fileCrc = 0; + getFileCrc32(fs, shadersFolder, fileCrc); + fs->seek(0); + + if (FS.exist(file_name)) + { + IReader* file = FS.r_open(file_name); + if (file->length() > 4) + { + u32 savedFileCrc = file->r_u32(); + if (savedFileCrc == fileCrc) + { + u32 savedBytecodeCrc = file->r_u32(); + u32 bytecodeCrc = crc32(file->pointer(), file->elapsed()); + if (bytecodeCrc == savedBytecodeCrc) + { +#ifdef DEBUG + Log("* Loading shader:", file_name); +#endif + _result = + create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), filename, result, o.disasm); + } + } + } + file->close(); + } + + if (FAILED(_result)) + { + includer Includer; + LPD3DXBUFFER pShaderBuf = nullptr; + LPD3DXBUFFER pErrorBuf = nullptr; + LPD3DXCONSTANTTABLE pConstants = nullptr; + LPD3DXINCLUDE pInclude = (LPD3DXINCLUDE)&Includer; + + _result = D3DXCompileShader((LPCSTR)fs->pointer(), fs->length(), defines, pInclude, pFunctionName, pTarget, + Flags | D3DXSHADER_USE_LEGACY_D3DX9_31_DLL, &pShaderBuf, &pErrorBuf, &pConstants); + if (SUCCEEDED(_result)) + { + IWriter* file = FS.w_open(file_name); + + file->w_u32(fileCrc); + + u32 crc = crc32(pShaderBuf->GetBufferPointer(), pShaderBuf->GetBufferSize()); + file->w_u32(crc); // Do not write anything below this line, take a look at reading (crc32) + + file->w(pShaderBuf->GetBufferPointer(), (u32)pShaderBuf->GetBufferSize()); + + FS.w_close(file); +#ifdef DEBUG + Log("- Compile shader:", file_name); +#endif + _result = create_shader(pTarget, (DWORD*)pShaderBuf->GetBufferPointer(), pShaderBuf->GetBufferSize(), + filename, result, o.disasm); + } + else + { + Log("! ", file_name); + if (pErrorBuf) + Log("! error: ", (LPCSTR)pErrorBuf->GetBufferPointer()); + else + Msg("Can't compile shader hr=0x%08x", _result); + } + } + + return _result; +} + + +static inline bool match_shader( + LPCSTR const debug_shader_id, LPCSTR const full_shader_id, LPCSTR const mask, size_t const mask_length) +{ + u32 const full_shader_id_length = xr_strlen(full_shader_id); + R_ASSERT2(full_shader_id_length == mask_length, + make_string("bad cache for shader %s, [%s], [%s]", debug_shader_id, mask, full_shader_id)); + char const* i = full_shader_id; + char const* const e = full_shader_id + full_shader_id_length; + char const* j = mask; + for (; i != e; ++i, ++j) + { + if (*i == *j) + continue; + + if (*j == '_') + continue; + + return false; + } + + return true; +} + +static inline bool match_shader_id( + LPCSTR const debug_shader_id, LPCSTR const full_shader_id, FS_FileSet const& file_set, string_path& result) +{ +#if 1 + strcpy_s(result, ""); + return false; +#else // #if 1 +#ifdef DEBUG + LPCSTR temp = ""; + bool found = false; + FS_FileSet::const_iterator i = file_set.begin(); + FS_FileSet::const_iterator const e = file_set.end(); + for (; i != e; ++i) + { + if (match_shader(debug_shader_id, full_shader_id, (*i).name.c_str(), (*i).name.size())) + { + VERIFY(!found); + found = true; + temp = (*i).name.c_str(); + } + } + + xr_strcpy(result, temp); + return found; +#else // #ifdef DEBUG + FS_FileSet::const_iterator i = file_set.begin(); + FS_FileSet::const_iterator const e = file_set.end(); + for (; i != e; ++i) + { + if (match_shader(debug_shader_id, full_shader_id, (*i).name.c_str(), (*i).name.size())) + { + xr_strcpy(result, (*i).name.c_str()); + return true; + } + } + + return false; +#endif // #ifdef DEBUG +#endif // #if 1 +} + + + +#else + +void CRender::addShaderOption(const char* name, const char* value) +{ + m_ShaderOptions += "#define "; + m_ShaderOptions += name; + m_ShaderOptions += " "; + m_ShaderOptions += value; + m_ShaderOptions += "\n"; +} + +void show_errors(cpcstr filename, GLuint* program, GLuint* shader) +{ + GLint length; + GLchar *errors = nullptr, *sources = nullptr; + + if (program) + { + CHK_GL(glGetProgramiv(*program, GL_INFO_LOG_LENGTH, &length)); + errors = xr_alloc(length); + CHK_GL(glGetProgramInfoLog(*program, length, nullptr, errors)); + } + else if (shader) + { + CHK_GL(glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &length)); + errors = xr_alloc(length); + CHK_GL(glGetShaderInfoLog(*shader, length, nullptr, errors)); + + CHK_GL(glGetShaderiv(*shader, GL_SHADER_SOURCE_LENGTH, &length)); + sources = xr_alloc(length); + CHK_GL(glGetShaderSource(*shader, length, nullptr, sources)); + } + + Log("! shader compilation failed:", filename); + if (errors) + Log("! error: ", errors); + + if (sources) + { + Log("Shader source:"); + Log(sources); + Log("Shader source end."); + } + xr_free(errors); + xr_free(sources); +} + +template +static GLuint create_shader(pcstr* buffer, size_t const buffer_size, cpcstr filename, + T*& result, const GLenum* format) +{ + auto [shader, program] = ShaderTypeTraits::CreateHWShader(buffer, buffer_size, result->sh, format, filename); + + const bool success = shader == 0 && program != 0 && program != GLuint(-1); + + // Parse constant, texture, sampler binding + if (success) + { + result->sh = program; + // Let constant table parse it's data + result->constants.parse(&program, ShaderTypeTraits::GetShaderDest()); + } + else + { + if (shader != 0 && shader != GLuint(-1)) + { + show_errors(filename, nullptr, &shader); + glDeleteShader(shader); + } + else + { + show_errors(filename, &program, nullptr); + glDeleteProgram(program); + } + } + + return success ? program : 0; +} + +static GLuint create_shader(cpcstr pTarget, pcstr* buffer, size_t const buffer_size, + cpcstr filename, void*& result, const GLenum* format) +{ + switch (pTarget[0]) + { + case 'p': + return create_shader(buffer, buffer_size, filename, (SPS*&)result, format); + case 'v': + return create_shader(buffer, buffer_size, filename, (SVS*&)result, format); + /* + case 'g': + return create_shader(buffer, buffer_size, filename, (SGS*&)result, format); + case 'c': + return create_shader(buffer, buffer_size, filename, (SCS*&)result, format); + case 'h': + return create_shader(buffer, buffer_size, filename, (SHS*&)result, format); + case 'd': + return create_shader(buffer, buffer_size, filename, (SDS*&)result, format); + */ + default: + NODEFAULT; + return 0; + } +} + +class shader_name_holder +{ + size_t pos{}; + string_path name; + +public: + void append(cpcstr string) + { + const size_t size = xr_strlen(string); + for (size_t i = 0; i < size; ++i) + { + name[pos] = string[i]; + ++pos; + } + } + + void append(u32 value) + { + name[pos] = '0' + char(value); // NOLINT + ++pos; + } + + void finish() + { + name[pos] = '\0'; + } + + pcstr c_str() const { return name; } +}; + +class shader_options_holder +{ + size_t pos{}; + string512 m_options[128]; + +public: + void add(cpcstr name, cpcstr value) + { + // It's important to have postfix increment! + xr_sprintf(m_options[pos++], "#define %s\t%s\n", name, value); + } + + void finish() + { + m_options[pos][0] = '\0'; + } + + [[nodiscard]] size_t size() const { return pos; } + string512& operator[](size_t idx) { return m_options[idx]; } +}; + +class shader_sources_manager +{ + pcstr* m_sources{}; + size_t m_sources_lines{}; + xr_vector m_source, m_includes; + string512 m_name_comment; + +public: + explicit shader_sources_manager(cpcstr name) + { + xr_sprintf(m_name_comment, "// %s\n", name); + } + + ~shader_sources_manager() + { + // Free string resources + xr_free(m_sources); + for (pstr include : m_includes) + xr_free(include); + m_source.clear(); + m_includes.clear(); + } + + [[nodiscard]] auto get() const { return m_sources; } + [[nodiscard]] auto length() const { return m_sources_lines; } + + [[nodiscard]] static constexpr bool optimized() + { +#ifdef DEBUG + return false; +#else + return true; +#endif + } + + void compile(IReader* file, shader_options_holder& options) + { + load_includes(file); + apply_options(options); + } + +private: + // TODO: OGL: make ignore commented includes + void load_includes(IReader* file) + { + cpcstr sourceData = static_cast(file->pointer()); + const size_t dataLength = file->length(); + + // Copy source file data into a null-terminated buffer + cpstr data = xr_alloc(dataLength + 2); + CopyMemory(data, sourceData, dataLength); + data[dataLength] = '\n'; + data[dataLength + 1] = '\0'; + m_includes.push_back(data); + m_source.push_back(data); + + string_path path; + pstr str = data; + while (strstr(str, "#include") != nullptr) + { + // Get filename of include directive + str = strstr(str, "#include"); // Find the include directive + char* fn = strchr(str, '"') + 1; // Get filename, skip quotation + *str = '\0'; // Terminate previous source + str = strchr(fn, '"'); // Get end of filename path + *str = '\0'; // Terminate filename path + + // Create path to included shader + strconcat(sizeof(path), path, GEnv.Render->getShaderPath(), fn); + FS.update_path(path, _game_shaders_, path); + while (cpstr sep = strchr(path, '/')) + *sep = '\\'; + + // Open and read file, recursively load includes + IReader* R = FS.r_open(path); + R_ASSERT2(R, path); + load_includes(R); + FS.r_close(R); + + // Add next source, skip quotation + ++str; + m_source.push_back(str); + } + } + + void apply_options(shader_options_holder& options) + { + // Compile sources list + const size_t head_lines = 2; // "#version" line + name_comment line + m_sources_lines = m_source.size() + options.size() + head_lines; + m_sources = xr_alloc(m_sources_lines); +#ifdef DEBUG + m_sources[0] = "#version 410\n#pragma optimize (off)\n"; +#else + m_sources[0] = "#version 410\n"; +#endif + m_sources[1] = m_name_comment; + + // Make define lines + for (size_t i = 0; i < options.size(); ++i) + { + m_sources[head_lines + i] = options[i]; + } + CopyMemory(m_sources + head_lines + options.size(), m_source.data(), m_source.size() * sizeof(pstr)); + } +}; + +HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName, + pcstr pTarget, u32 Flags, void*& result) +{ + shader_options_holder options; + shader_name_holder sh_name; + + // Don't move these variables to lower scope! + string32 c_smapsize; + string32 c_gloss; + string32 c_sun_shafts; + string32 c_ssao; + string32 c_sun_quality; + string32 c_water_reflection; + + // TODO: OGL: Implement these parameters. + UNUSED(pFunctionName); + UNUSED(Flags); + + // options: + const auto appendShaderOption = [&](u32 option, cpcstr macro, cpcstr value) + { + if (option) + options.add(macro, value); + + sh_name.append(option); + }; + + // Shadow map size + /*{ + xr_itoa(o.smapsize, c_smapsize, 10); + options.add("SMAP_size", c_smapsize); + sh_name.append(c_smapsize); + }*/ + + // FP16 Filter + //appendShaderOption(o.fp16_filter, "FP16_FILTER", "1"); + + // FP16 Blend + //appendShaderOption(o.fp16_blend, "FP16_BLEND", "1"); + + // HW smap + //appendShaderOption(o.HW_smap, "USE_HWSMAP", "1"); + + // HW smap PCF + //appendShaderOption(o.HW_smap_PCF, "USE_HWSMAP_PCF", "1"); + + // Fetch4 + //appendShaderOption(o.HW_smap_FETCH4, "USE_FETCH4", "1"); + + // SJitter + //appendShaderOption(o.sjitter, "USE_SJITTER", "1"); + + // Branching + appendShaderOption(HW.Caps.raster_major >= 3, "USE_BRANCHING", "1"); + + // Vertex texture fetch + appendShaderOption(HW.Caps.geometry.bVTF, "USE_VTF", "1"); + + // Tshadows + //appendShaderOption(o.Tshadows, "USE_TSHADOWS", "1"); + + // Motion blur + //appendShaderOption(o.mblur, "USE_MBLUR", "1"); + + // Sun filter + //appendShaderOption(o.sunfilter, "USE_SUNFILTER", "1"); + + // Static sun on R2 and higher + //appendShaderOption(o.sunstatic, "USE_R2_STATIC_SUN", "1"); + + // Force gloss + { + //xr_sprintf(c_gloss, "%f", o.forcegloss_v); + //appendShaderOption(o.forcegloss, "FORCE_GLOSS", c_gloss); + } + + // Force skinw + appendShaderOption(o.forceskinw, "SKIN_COLOR", "1"); + + // SSAO Blur + //appendShaderOption(o.ssao_blur_on, "USE_SSAO_BLUR", "1"); + + // SSAO HDAO + /*if (o.ssao_hdao) + { + options.add("HDAO", "1"); + sh_name.append(static_cast(1)); // HDAO on + sh_name.append(static_cast(0)); // HBAO off + sh_name.append(static_cast(0)); // HBAO vectorized off + } + else // SSAO HBAO + { + sh_name.append(static_cast(0)); // HDAO off + sh_name.append(o.ssao_hbao); // HBAO on/off + + appendShaderOption(o.ssao_hbao, "USE_HBAO", "1"); + appendShaderOption(o.hbao_vectorized, "VECTORIZED_CODE", "1"); + } + + if (o.ssao_opt_data) + { + if (o.ssao_half_data) + options.add("SSAO_OPT_DATA", "2"); + else + options.add("SSAO_OPT_DATA", "1"); + } + sh_name.append(o.ssao_opt_data ? (o.ssao_half_data ? u32(2) : u32(1)) : u32(0)); +*/ + // skinning + // SKIN_NONE + appendShaderOption(m_skinning < 0, "SKIN_NONE", "1"); + + // SKIN_0 + appendShaderOption(0 == m_skinning, "SKIN_0", "1"); + + // SKIN_1 + appendShaderOption(1 == m_skinning, "SKIN_1", "1"); + + // SKIN_2 + appendShaderOption(2 == m_skinning, "SKIN_2", "1"); + + // SKIN_3 + appendShaderOption(3 == m_skinning, "SKIN_3", "1"); + + // SKIN_4 + appendShaderOption(4 == m_skinning, "SKIN_4", "1"); + + // Igor: need restart options + // Soft water + { + //const bool softWater = RImplementation.o.advancedpp && ps_r2_ls_flags.test(R2FLAG_SOFT_WATER); + //appendShaderOption(softWater, "USE_SOFT_WATER", "1"); + } + + // Water reflections + /*if (RImplementation.o.advancedpp && ps_r_water_reflection) + { + xr_sprintf(c_water_reflection, "%d", ps_r_water_reflection); + options.add("SSR_QUALITY", c_water_reflection); + sh_name.append(ps_r_water_reflection); + const bool sshHalfDepth = ps_r2_ls_flags_ext.test(R3FLAGEXT_SSR_HALF_DEPTH); + appendShaderOption(sshHalfDepth, "SSR_HALF_DEPTH", "1"); + const bool ssrJitter = ps_r2_ls_flags_ext.test(R3FLAGEXT_SSR_JITTER); + appendShaderOption(ssrJitter, "SSR_JITTER", "1"); + } + else + { + sh_name.append(static_cast(0)); + }*/ + + // Soft particles + { + //const bool useSoftParticles = RImplementation.o.advancedpp && ps_r2_ls_flags.test(R2FLAG_SOFT_PARTICLES); + //appendShaderOption(useSoftParticles, "USE_SOFT_PARTICLES", "1"); + } + + // Depth of field + { + //const bool dof = RImplementation.o.advancedpp && ps_r2_ls_flags.test(R2FLAG_DOF); + //appendShaderOption(dof, "USE_DOF", "1"); + } + + // Sun shafts + /*if (RImplementation.o.advancedpp && ps_r_sun_shafts) + { + xr_sprintf(c_sun_shafts, "%d", ps_r_sun_shafts); + options.add("SUN_SHAFTS_QUALITY", c_sun_shafts); + sh_name.append(ps_r_sun_shafts); + } + else + sh_name.append(static_cast(0));*/ + + /*if (RImplementation.o.advancedpp && ps_r_ssao) + { + xr_sprintf(c_ssao, "%d", ps_r_ssao); + options.add("SSAO_QUALITY", c_ssao); + sh_name.append(ps_r_ssao); + } + else + sh_name.append(static_cast(0));*/ + + // Sun quality + /*if (RImplementation.o.advancedpp && ps_r_sun_quality) + { + xr_sprintf(c_sun_quality, "%d", ps_r_sun_quality); + options.add("SUN_QUALITY", c_sun_quality); + sh_name.append(ps_r_sun_quality); + } + else + sh_name.append(static_cast(0));*/ + + // Steep parallax + { + //const bool steepParallax = RImplementation.o.advancedpp && ps_r2_ls_flags.test(R2FLAG_STEEP_PARALLAX); + //appendShaderOption(steepParallax, "ALLOW_STEEPPARALLAX", "1"); + } + + // Geometry buffer optimization + //appendShaderOption(o.dx10_gbuffer_opt, "GBUFFER_OPTIMIZATION", "1"); + + // Shader Model 4.1 + //appendShaderOption(o.dx10_sm4_1, "SM_4_1", "1"); + + // Minmax SM + //appendShaderOption(o.dx10_minmax_sm, "USE_MINMAX_SM", "1"); + + // Shadow of Chernobyl compatibility + appendShaderOption(ShadowOfChernobylMode, "USE_SHOC_RESOURCES", "1"); + + // add a #define for DX10_1 MSAA support + /*if (o.dx10_msaa) + { + appendShaderOption(o.dx10_msaa, "USE_MSAA", "1"); + + { + static char samples[2]; + samples[0] = char(o.dx10_msaa_samples) + '0'; + samples[1] = 0; + appendShaderOption(o.dx10_msaa_samples, "MSAA_SAMPLES", samples); + } + + { + static char def[2]; + if (m_MSAASample < 0) + def[0] = '0'; + else + def[0] = '0' + char(m_MSAASample); + + def[1] = 0; + options.add("ISAMPLE", def); + sh_name.append(static_cast(0)); + } + + appendShaderOption(o.dx10_msaa_opt, "MSAA_OPTIMIZATION", "1"); + + switch (o.dx10_msaa_alphatest) + { + case MSAA_ATEST_DX10_0_ATOC: + options.add("MSAA_ALPHATEST_DX10_0_ATOC", "1"); + + sh_name.append(static_cast(1)); // DX10_0_ATOC on + sh_name.append(static_cast(0)); // DX10_1_ATOC off + sh_name.append(static_cast(0)); // DX10_1_NATIVE off + break; + case MSAA_ATEST_DX10_1_ATOC: + options.add("MSAA_ALPHATEST_DX10_1_ATOC", "1"); + + sh_name.append(static_cast(0)); // DX10_0_ATOC off + sh_name.append(static_cast(1)); // DX10_1_ATOC on + sh_name.append(static_cast(0)); // DX10_1_NATIVE off + break; + case MSAA_ATEST_DX10_1_NATIVE: + options.add("MSAA_ALPHATEST_DX10_1", "1"); + + sh_name.append(static_cast(0)); // DX10_0_ATOC off + sh_name.append(static_cast(0)); // DX10_1_ATOC off + sh_name.append(static_cast(1)); // DX10_1_NATIVE on + break; + default: + sh_name.append(static_cast(0)); // DX10_0_ATOC off + sh_name.append(static_cast(0)); // DX10_1_ATOC off + sh_name.append(static_cast(0)); // DX10_1_NATIVE off + } + } + else + { + sh_name.append(static_cast(0)); // MSAA off + sh_name.append(static_cast(0)); // No MSAA samples + sh_name.append(static_cast(0)); // No MSAA ISAMPLE + sh_name.append(static_cast(0)); // No MSAA optimization + sh_name.append(static_cast(0)); // DX10_0_ATOC off + sh_name.append(static_cast(0)); // DX10_1_ATOC off + sh_name.append(static_cast(0)); // DX10_1_NATIVE off + }*/ + + // Don't mix optimized and unoptimized shaders + sh_name.append(static_cast(shader_sources_manager::optimized())); + + // finish + options.finish(); + sh_name.finish(); + + char extension[3]; + strncpy_s(extension, pTarget, 2); + + u32 fileCrc = 0; + string_path filename, full_path; + strconcat(sizeof(filename), filename, "glr1" DELIMITER, name, ".", extension, DELIMITER, sh_name.c_str()); + if (HW.ShaderBinarySupported) + { + string_path file; + strconcat(sizeof(file), file, "shaders_cache_oxr" DELIMITER, filename); + FS.update_path(full_path, "$app_data_root$", file); + + string_path shadersFolder; + FS.update_path(shadersFolder, "$game_shaders$", GEnv.Render->getShaderPath()); + + getFileCrc32(fs, shadersFolder, fileCrc); + fs->seek(0); + } + + GLuint program = 0; + if (HW.ShaderBinarySupported && FS.exist(full_path)) + { + IReader* file = FS.r_open(full_path); + if (file->length() > 8) + { + xr_string renderer, glVer, shadingVer; + file->r_string(renderer); + file->r_string(glVer); + file->r_string(shadingVer); + + if (0 == xr_strcmp(renderer.c_str(), HW.AdapterName) && + 0 == xr_strcmp(glVer.c_str(), HW.OpenGLVersionString) && + 0 == xr_strcmp(shadingVer.c_str(), HW.ShadingVersion)) + { + const GLenum binaryFormat = file->r_u32(); + + const u32 savedFileCrc = file->r_u32(); + if (savedFileCrc == fileCrc) + { + const u32 savedBytecodeCrc = file->r_u32(); + const u32 bytecodeCrc = crc32(file->pointer(), file->elapsed()); + if (bytecodeCrc == savedBytecodeCrc) + { +#ifdef DEBUG + Log("* Loading shader:", full_path); +#endif + program = create_shader(pTarget, (pcstr*)file->pointer(), file->elapsed(), filename, result, &binaryFormat); + } + } + } + } + file->close(); + } + + // Failed to use cached shader, then: + if (!program) + { +#ifdef DEBUG + Log("- Compile shader:", full_path); +#endif + // Compile sources list + shader_sources_manager sources(name); + sources.compile(fs, options); + + // Compile the shader from sources + program = create_shader(pTarget, sources.get(), sources.length(), filename, result, nullptr); + + if (HW.ShaderBinarySupported && program) + { + GLvoid* binary{}; + GLint binaryLength{}; + GLenum binaryFormat{}; + glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength); + if (binaryLength) + binary = static_cast(xr_malloc(binaryLength)); + + if (binary) + { + glGetProgramBinary(program, binaryLength, nullptr, &binaryFormat, binary); + IWriter* file = FS.w_open(full_path); + + file->w_string(HW.AdapterName); + file->w_string(HW.OpenGLVersionString); + file->w_string(HW.ShadingVersion); + + file->w_u32(binaryFormat); + file->w_u32(fileCrc); + + const u32 bytecodeCrc = crc32(binary, binaryLength); + file->w_u32(bytecodeCrc); // Do not write anything below this line, take a look at reading (crc32) + + file->w(binary, binaryLength); + FS.w_close(file); + xr_free(binary); + } + } + } + + if (program) + return S_OK; + + return E_FAIL; +} + +#endif \ No newline at end of file diff --git a/src/Layers/xrRenderPC_GLR1/FStaticRender_Types.h b/src/Layers/xrRenderPC_GLR1/FStaticRender_Types.h new file mode 100755 index 00000000000..d8f442f49f0 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/FStaticRender_Types.h @@ -0,0 +1,20 @@ +#pragma once + +// Base targets +#define r1_RT_base "$user$base_" +#define r1_RT_base_depth "$user$base_depth" + +#define r1_RT_generic "$user$rendertarget" + +#define rt_RT_color_map "$user$rendertarget_color_map" +#define rt_RT_distort "$user$distort" + +#define r1_RT_depth "$user$depth" // surface + +// Used in LightShadows +#define r1_RT_shadow "$user$shadow" +#define r1_RT_temp "$user$temp" +#define rt_RT_temp_zb "$user$temp_zb" // surface + +#define r1_RT_async_ss "$user$async_ss" // surface + diff --git a/src/Layers/xrRenderPC_GLR1/GlowManager.cpp b/src/Layers/xrRenderPC_GLR1/GlowManager.cpp new file mode 100755 index 00000000000..882740f454a --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/GlowManager.cpp @@ -0,0 +1,315 @@ +// GlowManager.cpp: implementation of the CGlowManager class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "xrEngine/IGame_Persistent.h" +#include "xrEngine/Environment.h" +#include "xrEngine/x_ray.h" +#include "xrEngine/GameFont.h" +#include "GlowManager.h" +#include "xrEngine/xr_object.h" + +#define FADE_SCALE_UP 4096.f +#define FADE_SCALE_DOWN 1024.f +#define MAX_GlowsDist1 float(g_pGamePersistent->Environment().CurrentEnv->far_plane) +#define MAX_GlowsDist2 float(MAX_GlowsDist1 * MAX_GlowsDist1) + +////////////////////////////////////////////////////////////////////// +CGlow::CGlow() : SpatialBase(g_SpatialSpace) +{ + flags.bActive = false; + position.set(0, 0, 0); + direction.set(0, 0, 0); + radius = 0.1f; + color.set(1, 1, 1, 1); + bTestResult = FALSE; + fade = 1.f; + dwFrame = 0; + spatial.type = STYPE_RENDERABLE; +} +CGlow::~CGlow() +{ + set_active(false); + shader.destroy(); +} + +void CGlow::set_active(bool a) +{ + if (a) + { + if (flags.bActive) + return; + flags.bActive = true; + spatial_register(); + } + else + { + if (!flags.bActive) + return; + flags.bActive = false; + spatial_unregister(); + } +} + +bool CGlow::get_active() { return flags.bActive; } +void CGlow::set_position(const Fvector& P) +{ + if (position.similar(P)) + return; + position.set(P); + spatial_move(); +}; +void CGlow::set_direction(const Fvector& D) { direction.normalize_safe(D); }; +void CGlow::set_radius(float R) +{ + if (fsimilar(radius, R)) + return; + radius = R; + spatial_move(); +}; +void CGlow::set_texture(LPCSTR name) { shader.create("effects" DELIMITER "glow", name); } +void CGlow::set_color(const Fcolor& C) { color = C; } +void CGlow::set_color(float r, float g, float b) { color.set(r, g, b, 1); } +void CGlow::spatial_move() +{ + spatial.sphere.set(position, radius); + SpatialBase::spatial_move(); +} +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CGlowManager::CGlowManager() {} +CGlowManager::~CGlowManager() {} +void CGlowManager::Load(IReader* fs) +{ + // glows itself + const size_t size = fs->length(); + R_ASSERT(size); + const size_t one = sizeof(Fvector) + sizeof(float) + sizeof(u16); + R_ASSERT(size % one == 0); + size_t count = size / one; + Glows.reserve(count); + + for (; count; count--) + { + CGlow* G = xr_new(); + fs->r(&G->position, sizeof(Fvector)); + fs->r(&G->radius, sizeof(float)); + G->spatial.sphere.set(G->position, G->radius); + G->direction.set(0, 0, 0); + + u16 S = fs->r_u16(); + G->shader = ::RImplementation.getShader(S); + + G->fade = 255.f; + G->dwFrame = 0x0; + G->bTestResult = TRUE; + + G->spatial.type = STYPE_RENDERABLE; + + G->set_active(true); + + Glows.push_back(G); + } + dwTestID = 0; + + hGeom.create(FVF::F_LIT, RCache.Vertex.Buffer(), RCache.QuadIB); +} + +void CGlowManager::Unload() +{ + // glows + SelectedToTest_2.clear(); + SelectedToTest_1.clear(); + SelectedToTest_0.clear(); + Selected.clear(); + Glows.clear(); +} + +IC bool glow_compare(ref_glow g1, ref_glow g2) { return ((CGlow*)g1._get())->shader < ((CGlow*)g2._get())->shader; } +void CGlowManager::add(ref_glow G_) +{ + CGlow* G = (CGlow*)G_._get(); + if (G->dwFrame == Device.dwFrame) + return; + G->dwFrame = Device.dwFrame; + float dt = Device.fTimeDelta; + float dlim2 = MAX_GlowsDist2; + + float range = Device.vCameraPosition.distance_to_sqr(G->spatial.sphere.P); + if (range < dlim2) + { + // 2. Use result of test + if (G->bTestResult) + { + G->fade -= dt * FADE_SCALE_DOWN; + if (G->fade < 1.) + G->fade = 1; + } + else + { + G->fade += dt * FADE_SCALE_UP; + if (G->fade > 255.f) + G->fade = 255.f; + } + + Selected.push_back(G); + return; + } + G->fade -= dt * FADE_SCALE_DOWN; + if (G->fade < 1.) + G->fade = 1; +} + +IC void FillSprite(FVF::LIT*& pv, const Fvector& pos, float r, u32 clr) +{ + const Fvector& T = Device.vCameraTop; + const Fvector& R = Device.vCameraRight; + Fvector Vr, Vt; + Vr.mul(R, r); + Vt.mul(T, r); + + Fvector a, b, c, d; + a.sub(Vt, Vr); + b.add(Vt, Vr); + c.invert(a); + d.invert(b); + pv->set(d.x + pos.x, d.y + pos.y, d.z + pos.z, clr, 0.f, 1.f); + pv++; + pv->set(a.x + pos.x, a.y + pos.y, a.z + pos.z, clr, 0.f, 0.f); + pv++; + pv->set(c.x + pos.x, c.y + pos.y, c.z + pos.z, clr, 1.f, 1.f); + pv++; + pv->set(b.x + pos.x, b.y + pos.y, b.z + pos.z, clr, 1.f, 0.f); + pv++; +} + +void CGlowManager::Render() +{ + if (Selected.empty()) + return; + RCache.set_xform_world(Fidentity); + render_sw(); +} + +void CGlowManager::render_sw() +{ + // 0. save main view and disable + IGameObject* o_main = g_pGameLevel->CurrentViewEntity(); + + // 1. Test some number of glows + Fvector start = Device.vCameraPosition; + for (int i = 0; i < ps_r1_GlowsPerFrame; i++, dwTestID++) + { + u32 ID = dwTestID % Selected.size(); + CGlow& G = *((CGlow*)Selected[ID]._get()); + if (G.dwFrame == 'test') + break; + G.dwFrame = 'test'; + Fvector dir; + dir.sub(G.spatial.sphere.P, start); + float range = dir.magnitude(); + if (range > EPS_S) + { + dir.div(range); + G.bTestResult = g_pGameLevel->ObjectSpace.RayTest(start, dir, range, collide::rqtBoth, &G.RayCache, o_main); + } + } + + // 2. Render selected + render_selected(); +} + +void CGlowManager::render_hw() +{ + // 0. query result from 'SelectedToTest_2' + SelectedToTest_2 = SelectedToTest_1; + SelectedToTest_1 = SelectedToTest_0; + SelectedToTest_0.clear(); + + // 1. Sort into two parts - 1(selected-to-test)[to-test], 2(selected)[just-draw] + // Fvector &start = Device.vCameraPosition; + for (int i = 0; (i < ps_r1_GlowsPerFrame) && Selected.size(); i++, dwTestID++) + { + u32 ID = dwTestID % Selected.size(); + SelectedToTest_0.push_back(Selected[ID]); + Selected.erase(Selected.begin() + ID); + } + + // 2. Render selected + render_selected(); + + // +} + +void CGlowManager::render_selected() +{ + // 2. Sort by shader + std::sort(Selected.begin(), Selected.end(), glow_compare); + + FVF::LIT* pv; + + u32 pos = 0, count; + ref_shader T; + + Fplane NP; + NP.build(Device.vCameraPosition, Device.vCameraDirection); + + float dlim2 = MAX_GlowsDist2; + for (; pos < Selected.size();) + { + T = ((CGlow*)Selected[pos]._get())->shader; + count = 0; + while ((pos + count < Selected.size()) && (((CGlow*)Selected[pos + count]._get())->shader == T)) + count++; + + u32 vOffset; + u32 end = pos + count; + FVF::LIT* pvs = pv = (FVF::LIT*)RCache.Vertex.Lock(count * 4, hGeom->vb_stride, vOffset); + for (; pos < end; pos++) + { + // Cull invisible + CGlow& G = *((CGlow*)Selected[pos]._get()); + if (G.fade <= 1.f) + continue; + + // Now perform dotproduct if need it + float scale = 1.f, dist_sq; + Fvector dir; + dir.sub(Device.vCameraPosition, G.position); + dist_sq = dir.square_magnitude(); + if (G.direction.square_magnitude() > EPS) + { + dir.div(_sqrt(dist_sq)); + scale = dir.dotproduct(G.direction); + } + if (G.fade * scale <= 1.f) + continue; + + // near fade + float dist_np = NP.distance(G.position) - VIEWPORT_NEAR; + float snear = dist_np / 0.15f; + clamp(snear, 0.f, 1.f); + scale *= snear; + if (G.fade * scale <= 1.f) + continue; + + u32 C = iFloor(G.fade * scale * (1 - (dist_sq / dlim2))); + u32 clr = color_rgba(C, C, C, C); + Fvector gp; + gp.mad(G.position, dir, G.radius * scale); + FillSprite(pv, G.position, G.radius, clr); + } + int vCount = int(pv - pvs); + RCache.Vertex.Unlock(vCount, hGeom->vb_stride); + if (vCount) + { + RCache.set_Shader(T); + RCache.set_Geometry(hGeom); + RCache.Render(D3DPT_TRIANGLELIST, vOffset, 0, vCount, 0, vCount / 2); + } + } + Selected.clear(); +} diff --git a/src/Layers/xrRenderPC_GLR1/GlowManager.h b/src/Layers/xrRenderPC_GLR1/GlowManager.h new file mode 100755 index 00000000000..187bd638848 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/GlowManager.h @@ -0,0 +1,78 @@ +// GlowManager.h: interface for the CGlowManager class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_GLOWMANAGER_H__EC35911F_479B_469A_845C_1A64D81D0326__INCLUDED_) +#define AFX_GLOWMANAGER_H__EC35911F_479B_469A_845C_1A64D81D0326__INCLUDED_ +#pragma once + +#include "xrCDB/ISpatial.h" +#include "xrCDB/xr_collide_defs.h" + +class CGlow : public IRender_Glow, public SpatialBase +{ +public: + struct + { + u32 bActive : 1; + } flags; + float fade; + ref_shader shader; + u32 dwFrame; + + Fvector position; + Fvector direction; + float radius; + Fcolor color; + + // Ray-testing cache + BOOL bTestResult; + collide::ray_cache RayCache; + u32 qid_pass; + u32 qid_total; + +public: + CGlow(); + virtual ~CGlow(); + + virtual void set_active(bool); + virtual bool get_active(); + virtual void set_position(const Fvector& P); + virtual void set_direction(const Fvector& P); + virtual void set_radius(float R); + virtual void set_texture(LPCSTR name); + virtual void set_color(const Fcolor& C); + virtual void set_color(float r, float g, float b); + virtual void spatial_move(); +}; + +#define MAX_GlowsPerFrame 64 + +class CGlowManager +{ + xr_vector Glows; + xr_vector Selected; + xr_vector SelectedToTest_2; // 2-frames behind + xr_vector SelectedToTest_1; // 1-frames behind + xr_vector SelectedToTest_0; // 0-frames behind + ref_geom hGeom; + + BOOL b_hardware; + u32 dwTestID; + +public: + void add(ref_glow g); + + void Load(IReader* fs); + void Unload(); + + void render_selected(); + void render_sw(); + void render_hw(); + void Render(); + + CGlowManager(); + ~CGlowManager(); +}; + +#endif // !defined(AFX_GLOWMANAGER_H__EC35911F_479B_469A_845C_1A64D81D0326__INCLUDED_) diff --git a/src/Layers/xrRenderPC_GLR1/LightPPA.cpp b/src/Layers/xrRenderPC_GLR1/LightPPA.cpp new file mode 100755 index 00000000000..1ff2a83a4ab --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/LightPPA.cpp @@ -0,0 +1,342 @@ +// LightPPA.cpp: implementation of the CLightPPA class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "LightPPA.h" +#include "xrEngine/IGame_Persistent.h" +#include "xrEngine/Environment.h" +#include "Layers/xrRender/FBasicVisual.h" +#include "xrEngine/CustomHUD.h" + +const u32 MAX_POLYGONS = 1024 * 8; +const float MAX_DISTANCE = 50.f; +const float SSM_near_plane = .1f; +const float SSM_tex_size = 32.f; + +////////////////////////////////////////////////////////////////////////// +// binders for lighting +////////////////////////////////////////////////////////////////////////// +void cl_light_PR::setup(R_constant* C) +{ + Fvector& P = RImplementation.r1_dlight_light->position; + float R = RImplementation.r1_dlight_light->range; + if (RImplementation.phase == CRender::PHASE_POINT) + RCache.set_c(C, P.x, P.y, P.z, .5f / R); + else + RCache.set_c(C, P.x, P.y, P.z, 1.f / R); +} +void cl_light_C::setup(R_constant* C) +{ + Fcolor _C = RImplementation.r1_dlight_light->color; + _C.mul_rgb(RImplementation.r1_dlight_scale); + RCache.set_c(C, _C.r, _C.g, _C.b, 1.f); +} +void cl_light_XFORM::setup(R_constant* C) { RCache.set_c(C, RImplementation.r1_dlight_tcgen); } +////////////////////////////////////////////////////////////////////////// +/* +IC void mk_vertex (CLightR_Vertex& D, Fvector& P, Fvector& N, Fvector& C, float r2) +{ + D.P.set (P); + D.N.set (P); + D.u0 = (P.x-C.x)/r2+.5f; + D.v0 = (P.z-C.z)/r2+.5f; + D.u1 = (P.y-C.y)/r2+.5f; + D.v1 =.5f; +} + +void CLightR_Manager::render_point () +{ + // Implementation banned / non-working ? + // return; + + // World/View/Projection + float _43 = Device.mProject._43; + Device.mProject._43 -= 0.001f; + RCache.set_xform_world (Fidentity); + RCache.set_xform_project (Device.mProject); + + RImplementation.r1_dlight_light = selected_point.front(); + RCache.set_Shader (hShader); + for (xr_vector::iterator it=selected_point.begin(); it!=selected_point.end(); it++) + { + // 2. Set global light-params to be used by shading + RImplementation.r1_dlight_light = *it; + light& PPL = *(*it); + + // Culling + if (PPL.range<0.05f) continue; + if (PPL.color.magnitude_sqr_rgb()=1) continue; + if (!RImplementation.ViewBase.testSphere_dirty (PPL.position,PPL.range)) continue; + + // Calculations and rendering + Device.Statistic->RenderDUMP_Lights.Begin(); + Fcolor factor; + factor.mul_rgba (PPL.color,(1-alpha)); + RCache.set_c (hPPAcolor,factor.r,factor.g,factor.b,1); + { + // Build bbox + float size_f = PPL.range+EPS_L; + Fvector size; + size.set (size_f,size_f,size_f); + + // Query collision DB (Select polygons) + xrc.box_options (0); + xrc.box_query (g_pGameLevel->ObjectSpace.GetStaticModel(),PPL.position,size); + u32 triCount = xrc.r_count (); + if (0==triCount) return; + CDB::TRI* tris = g_pGameLevel->ObjectSpace.GetStaticTris(); + Fvector* verts = g_pGameLevel->ObjectSpace.GetStaticVerts(); + + // Lock + RCache.set_Geometry (hGeom); + u32 triLock = _min(256u,triCount); + u32 vOffset; + CLightR_Vertex* VB = (CLightR_Vertex*)RCache.Vertex.Lock(triLock*3,hGeom->vb_stride,vOffset); + + // Cull and triangulate polygons + Fvector cam = Device.vCameraPosition; + float r2 = PPL.range*2; + u32 actual = 0; + for (u32 t=0; t=triLock) + { + RCache.Vertex.Unlock (actual*3,hGeom->vb_stride); + if (actual) RCache.Render (D3DPT_TRIANGLELIST,vOffset,actual); + actual = 0; + triLock = _min(256u,triCount-t); + VB = +(CLightR_Vertex*)RCache.Vertex.Lock(triLock*3,hGeom->vb_stride,vOffset); + } + } + + // Unlock and render + RCache.Vertex.Unlock (actual*3,hGeom->vb_stride); + if (actual) RCache.Render (D3DPT_TRIANGLELIST,vOffset,actual); + } + Device.Statistic->RenderDUMP_Lights.End (); + } + + // Projection + Device.mProject._43 = _43; + RCache.set_xform_project (Device.mProject); +} +*/ + +void CLightR_Manager::render_point(u32 _priority) +{ + // for each light + Fvector lc_COP = Device.vCameraPosition; + float lc_limit = ps_r1_dlights_clip; + for (xr_vector::iterator it = selected_point.begin(); it != selected_point.end(); ++it) + { + light* L = *it; + VERIFY(L->spatial.sector && _valid(L->range)); + + // 0. Dimm & Clip + float lc_dist = lc_COP.distance_to(L->spatial.sphere.P) - L->spatial.sphere.R; + float lc_scale = 1 - lc_dist / lc_limit; + if (lc_scale < EPS) + continue; + if (L->range < 0.01f) + continue; + + // 1. Calculate light frustum + Fvector L_dir, L_up, L_right, L_pos; + Fmatrix L_view, L_project, L_combine; + L_dir.set(0, -1, 0); + L_up.set(0, 0, 1); + L_right.crossproduct(L_up, L_dir); + L_right.normalize(); + L_up.crossproduct(L_dir, L_right); + L_up.normalize(); + float _camrange = 300.f; + L_pos.set(L->position); + // L_pos.y += _camrange; + L_view.build_camera_dir(L_pos, L_dir, L_up); + L_project.build_projection(deg2rad(2.f), 1.f, _camrange - L->range, _camrange + L->range); + L_combine.mul(L_project, L_view); + + // 2. Calculate matrix for TC-gen + float fTexelOffs = (.5f / SSM_tex_size); + float fRange = 1.f / L->range; + float fBias = 0.f; + Fmatrix m_TexelAdjust = {0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, fRange, 0.0f, + 0.5f + fTexelOffs, 0.5f + fTexelOffs, fBias, 1.0f}; + Fmatrix L_texgen; + L_texgen.mul(m_TexelAdjust, L_combine); + + // 2. Set global light-params to be used by shading + RImplementation.r1_dlight_light = L; + RImplementation.r1_dlight_scale = clampr(lc_scale, 0.f, 1.f); + RImplementation.r1_dlight_tcgen = L_texgen; + + // 3. Calculate visibility for light + build soring tree + VERIFY(L->spatial.sector); + if (_priority == 1) + RImplementation.r_pmask(false, true); + + RImplementation.r_dsgraph_render_subspace(L->spatial.sector, L_combine, L_pos, true, true); + + if (_priority == 1) + RImplementation.r_pmask(true, true); + + // 4. Analyze if HUD intersects light volume + BOOL bHUD = FALSE; + CFrustum F; + F.CreateFromMatrix(L_combine, FRUSTUM_P_ALL); + bHUD = F.testSphere_dirty(Device.vCameraPosition, 2.f); + + // 5. Dump sorting tree + RCache.set_Constants((R_constant_table*)nullptr); + if (bHUD && _priority == 0) + g_hud->Render_Last(); + RImplementation.r_dsgraph_render_graph(_priority); + if (bHUD && _priority == 0) + RImplementation.r_dsgraph_render_hud(); + } + // ??? grass ??? +} + +void CLightR_Manager::render_spot(u32 _priority) +{ + // for each light + // Msg ("l=%d",selected_spot.size()); + Fvector lc_COP = Device.vCameraPosition; + float lc_limit = ps_r1_dlights_clip; + + for (xr_vector::iterator it = selected_spot.begin(); it != selected_spot.end(); ++it) + { + light* L = *it; + + // 0. Dimm & Clip + float lc_dist = lc_COP.distance_to(L->spatial.sphere.P) - L->spatial.sphere.R; + float lc_scale = 1 - lc_dist / lc_limit; + if (lc_scale < EPS) + continue; + + // 1. Calculate light frustum + Fvector L_dir, L_up, L_right, L_pos; + Fmatrix L_view, L_project, L_combine; + L_dir.set(L->direction); + L_dir.normalize(); + L_up.set(0, 1, 0); + if (_abs(L_up.dotproduct(L_dir)) > .99f) + L_up.set(0, 0, 1); + L_right.crossproduct(L_up, L_dir); + L_right.normalize(); + L_up.crossproduct(L_dir, L_right); + L_up.normalize(); + L_pos.set(L->position); + L_view.build_camera_dir(L_pos, L_dir, L_up); + L_project.build_projection(L->cone, 1.f, SSM_near_plane, L->range + EPS_S); + L_combine.mul(L_project, L_view); + + // 2. Calculate matrix for TC-gen + float fTexelOffs = (.5f / SSM_tex_size); + float fRange = 1.f / L->range; + float fBias = 0.f; + Fmatrix m_TexelAdjust = {0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, fRange, 0.0f, + 0.5f + fTexelOffs, 0.5f + fTexelOffs, fBias, 1.0f}; + Fmatrix L_texgen; + L_texgen.mul(m_TexelAdjust, L_combine); + + // 2. Set global light-params to be used by shading + RImplementation.r1_dlight_light = L; + RImplementation.r1_dlight_scale = clampr(lc_scale, 0.f, 1.f); + RImplementation.r1_dlight_tcgen = L_texgen; + + // 3. Calculate visibility for light + build soring tree + VERIFY(L->spatial.sector); + // RImplementation.marker ++; + if (_priority == 1) + RImplementation.r_pmask(false, true); + + RImplementation.r_dsgraph_render_subspace(L->spatial.sector, L_combine, L_pos, TRUE, + TRUE // precise portals + ); + + if (_priority == 1) + RImplementation.r_pmask(true, true); + + // 4. Analyze if HUD intersects light volume + BOOL bHUD = FALSE; + CFrustum F; + F.CreateFromMatrix(L_combine, FRUSTUM_P_ALL); + bHUD = F.testSphere_dirty(Device.vCameraPosition, 2.f); + // if (bHUD) Msg ("HUD"); + + // 4. Dump sorting tree + //RCache.set_ClipPlanes(true, &L_combine); + RCache.set_Constants((R_constant_table*)nullptr); + if (bHUD && _priority == 0) + g_hud->Render_Last(); + RImplementation.r_dsgraph_render_graph(_priority); + if (bHUD && _priority == 0) + RImplementation.r_dsgraph_render_hud(); + //RCache.set_ClipPlanes(false, &L_combine); + } + // ??? grass ???l +} + +void CLightR_Manager::render(u32 _priority) +{ + if (selected_spot.size()) + { + RImplementation.phase = CRender::PHASE_SPOT; + render_spot(_priority); + + if (_priority == 1) + selected_spot.clear(); + } + if (selected_point.size()) + { + RImplementation.phase = CRender::PHASE_POINT; + render_point(_priority); + + if (_priority == 1) + selected_point.clear(); + } +} + +void CLightR_Manager::add(light* L) +{ + if (L->range < 0.1f) + return; + if (nullptr == L->spatial.sector) + return; + if (IRender_Light::POINT == L->flags.type) + { + // PPA + selected_point.push_back(L); + } + else + { + // spot/flash + selected_spot.push_back(L); + } + VERIFY(L->spatial.sector); +} +// XXX stats: add to statistics +CLightR_Manager::CLightR_Manager() : xrc("LightR_Manager") {} +CLightR_Manager::~CLightR_Manager() {} diff --git a/src/Layers/xrRenderPC_GLR1/LightPPA.h b/src/Layers/xrRenderPC_GLR1/LightPPA.h new file mode 100755 index 00000000000..cf6844b88c1 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/LightPPA.h @@ -0,0 +1,51 @@ +// LightPPA.h: interface for the CLightPPA class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_LIGHTPPA_H__E5B97AC9_84A6_4773_9FEF_3BC5D1CEF8B6__INCLUDED_) +#define AFX_LIGHTPPA_H__E5B97AC9_84A6_4773_9FEF_3BC5D1CEF8B6__INCLUDED_ +#pragma once + +#include "Layers/xrRender/light.h" + +struct CLightR_Vertex +{ + Fvector P; + Fvector N; + float u0, v0; + float u1, v1; +}; + +class CLightR_Manager +{ + xrXRC xrc; + xr_vector selected_point; + xr_vector selected_spot; + +public: + CLightR_Manager(); + virtual ~CLightR_Manager(); + + void add(light* L); + void render(u32 _priority); + void render_point(u32 _priority); + void render_spot(u32 _priority); +}; + +////////////////////////////////////////////////////////////////////////// +// binders for lighting +////////////////////////////////////////////////////////////////////////// +class cl_light_PR : public R_constant_setup +{ + virtual void setup(R_constant* C); +}; +class cl_light_C : public R_constant_setup +{ + virtual void setup(R_constant* C); +}; +class cl_light_XFORM : public R_constant_setup +{ + virtual void setup(R_constant* C); +}; + +#endif // !defined(AFX_LIGHTPPA_H__E5B97AC9_84A6_4773_9FEF_3BC5D1CEF8B6__INCLUDED_) diff --git a/src/Layers/xrRenderPC_GLR1/LightProjector.cpp b/src/Layers/xrRenderPC_GLR1/LightProjector.cpp new file mode 100755 index 00000000000..ae0d23e7920 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/LightProjector.cpp @@ -0,0 +1,389 @@ +// LightProjector.cpp: implementation of the CLightProjector class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "LightProjector.h" +#include "Include/xrRender/RenderVisual.h" +#include "xrEngine/xr_object.h" +#include "Layers/xrRender/LightTrack.h" + +// tir2.xrdemo -> 45.2 +// tir2.xrdemo -> 61.8 + +const float P_distance = 50; // switch distance between LOW-q light and HIGH-q light +const float P_cam_dist = 200; +const float P_cam_range = 7.f; +const D3DFORMAT P_rtf = D3DFMT_A8R8G8B8; +const float P_blur_kernel = .5f; +const int time_min = 30 * 1000; +const int time_max = 90 * 1000; +const float P_ideal_size = 1.f; + +float clipD(float R) { return P_distance * (R / P_ideal_size); } +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CLightProjector::CLightProjector() +{ + current = nullptr; + RT = nullptr; + + // + RT.create("$user$projector", P_rt_size, P_rt_size, P_rtf); + + // ref-str for faster const-search + c_xform = "m_plmap_xform"; + c_clamp = "m_plmap_clamp"; + c_factor = "m_plmap_factor"; + + cache.resize(P_o_count); + Device.seqAppActivate.Add(this); +} + +CLightProjector::~CLightProjector() +{ + Device.seqAppActivate.Remove(this); + RT.destroy(); +} + +void CLightProjector::set_object(IRenderable* O) +{ + if (current == O) + return; + + if ((nullptr == O) || (receivers.size() >= P_o_count)) + current = nullptr; + else + { + if (!O->renderable_ShadowReceive() || O->renderable_Invisible() || + ((CROS_impl*)O->renderable_ROS())->shadow_recv_frame == Device.dwFrame) + { + current = nullptr; + return; + } + + const vis_data& vis = O->GetRenderData().visual->getVisData(); + Fvector C; + O->GetRenderData().xform.transform_tiny(C, vis.sphere.P); + float R = vis.sphere.R; + float D = C.distance_to(Device.vCameraPosition) + R; + + if (D < clipD(R)) + current = O; + else + current = nullptr; + + if (current) + { + ISpatial* spatial = dynamic_cast(O); + if (nullptr == spatial) + current = nullptr; + else + { + spatial->spatial_updatesector(); + if (nullptr == spatial->GetSpatialData().sector) + { + IGameObject* obj = dynamic_cast(O); + if (obj) + Msg("! Invalid object '%s' position. Outside of sector structure.", obj->cName().c_str()); + current = nullptr; + } + } + } + if (current) + { + CROS_impl* LT = (CROS_impl*)current->renderable_ROS(); + LT->shadow_recv_frame = Device.dwFrame; + receivers.push_back(current); + } + } +} + +// +void CLightProjector::setup(int id) +{ + if (id >= int(cache.size()) || id < 0) + { + //Log("! CLightProjector::setup - ID out of range"); + return; + } + recv& R = cache[id]; + float Rd = R.O->GetRenderData().visual->getVisData().sphere.R; + float dist = R.C.distance_to(Device.vCameraPosition) + Rd; + float factor = _sqr(dist / clipD(Rd)) * (1 - ps_r1_lmodel_lerp) + ps_r1_lmodel_lerp; + RCache.set_c(c_xform, R.UVgen); + Fvector& m = R.UVclamp_min; + RCache.set_ca(c_clamp, 0, m.x, m.y, m.z, factor); + Fvector& M = R.UVclamp_max; + RCache.set_ca(c_clamp, 1, M.x, M.y, M.z, 0.0f); +} + +void CLightProjector::invalidate() +{ + for (u32 c_it = 0; c_it < cache.size(); c_it++) + cache[c_it].dwTimeValid = 0; +} + +void CLightProjector::OnAppActivate() { invalidate(); } +// +#include "Layers/xrRender/SkeletonCustom.h" +void CLightProjector::calculate() +{ +#ifdef _GPA_ENABLED + TAL_SCOPED_TASK_NAMED("CLightProjector::calculate()"); +#endif // _GPA_ENABLED + + if (receivers.empty()) + return; + + // perform validate / markup + for (u32 r_it = 0; r_it < receivers.size(); r_it++) + { + // validate + BOOL bValid = TRUE; + IRenderable* O = receivers[r_it]; + CROS_impl* LT = (CROS_impl*)O->renderable_ROS(); + int slot = LT->shadow_recv_slot; + if (slot < 0 || slot >= P_o_count) + bValid = FALSE; // invalid slot + else if (cache[slot].O != O) + bValid = FALSE; // not the same object + else + { + // seems to be valid + Fbox bb; + bb.xform(O->GetRenderData().visual->getVisData().box, O->GetRenderData().xform); + if (cache[slot].BB.contains(bb)) + { + // inside, but maybe timelimit exceeded? + if (Device.dwTimeGlobal > cache[slot].dwTimeValid) + bValid = FALSE; // timeout + } + else + bValid = FALSE; // out of bounds + } + + // + if (bValid) + { + // Ok, use cached version + cache[slot].dwFrame = Device.dwFrame; + } + else + { + taskid.push_back(r_it); + } + } + if (taskid.empty()) + return; + + // Begin + RCache.set_RT(RT->pRT); + RCache.set_ZB(RImplementation.Target->rt_temp_zb->pRT); + RCache.ClearZB(RImplementation.Target->rt_temp_zb, 1.f, 0); + RCache.set_xform_world(Fidentity); + + // reallocate/reassociate structures + perform all the work + for (u32 c_it = 0; c_it < cache.size(); c_it++) + { + if (taskid.empty()) + break; + if (Device.dwFrame == cache[c_it].dwFrame) + continue; + + // found not used slot + int tid = taskid.back(); + taskid.pop_back(); + recv& R = cache[c_it]; + IRenderable* O = receivers[tid]; + const vis_data& vis = O->GetRenderData().visual->getVisData(); + CROS_impl* LT = (CROS_impl*)O->renderable_ROS(); + VERIFY2(_valid(O->GetRenderData().xform), "Invalid object transformation"); + VERIFY2(_valid(vis.sphere.P), "Invalid object's visual sphere"); + + Fvector C; + O->GetRenderData().xform.transform_tiny(C, vis.sphere.P); + R.O = O; + R.C = C; + R.C.y += vis.sphere.R * 0.1f; //. YURA: 0.1 can be more + R.BB.xform(vis.box, O->GetRenderData().xform).scale(0.1f); + R.dwTimeValid = Device.dwTimeGlobal + ::Random.randI(time_min, time_max); + LT->shadow_recv_slot = c_it; + + // Msg ("[%f,%f,%f]-%f",C.C.x,C.C.y,C.C.z,C.O->renderable.visual->vis.sphere.R); + // calculate projection-matrix + Fmatrix mProject; + float p_R = R.O->GetRenderData().visual->getVisData().sphere.R * 1.1f; + // VERIFY2 (p_R>EPS_L,"Object has no physical size"); + VERIFY3(p_R > EPS_L, "Object has no physical size", R.O->GetRenderData().visual->getDebugName().c_str()); + float p_hat = p_R / P_cam_dist; + float p_asp = 1.f; + float p_near = P_cam_dist - EPS_L; + float p_far = P_cam_dist + p_R + P_cam_range; + mProject.build_projection_HAT(p_hat, p_asp, p_near, p_far); + RCache.set_xform_project(mProject); + + // calculate view-matrix + Fmatrix mView; + Fvector v_C, v_Cs, v_N; + v_C.set(R.C); + v_Cs = v_C; + v_C.y += P_cam_dist; + v_N.set(0, 0, 1); + VERIFY(_valid(v_C) && _valid(v_Cs) && _valid(v_N)); + + // validate + Fvector v; + v.sub(v_Cs, v_C); + ; +#ifdef DEBUG + if ((v.x * v.x + v.y * v.y + v.z * v.z) <= flt_zero) + { + IGameObject* OO = dynamic_cast(R.O); + Msg("Object[%s] Visual[%s] has invalid position. ", *OO->cName(), *OO->cNameVisual()); + Fvector cc; + OO->Center(cc); + Log("center=", cc); + + Log("visual_center=", OO->Visual()->getVisData().sphere.P); + + Log("full_matrix=", OO->XFORM()); + + Log("v_N", v_N); + Log("v_C", v_C); + Log("v_Cs", v_Cs); + + Log("all bones transform:--------"); + CKinematics* K = dynamic_cast(OO->Visual()); + + for (u16 ii = 0; ii < K->LL_BoneCount(); ++ii) + { + Fmatrix tr; + + tr = K->LL_GetTransform(ii); + Log("bone ", K->LL_BoneName_dbg(ii)); + Log("bone_matrix", tr); + } + Log("end-------"); + } +#endif + // handle invalid object-bug + if ((v.x * v.x + v.y * v.y + v.z * v.z) <= flt_zero) + { + // invalidate record, so that object will be unshadowed, but doesn't crash + R.dwTimeValid = Device.dwTimeGlobal; + LT->shadow_recv_frame = Device.dwFrame - 1; + LT->shadow_recv_slot = -1; + continue; + } + + mView.build_camera(v_C, v_Cs, v_N); + RCache.set_xform_view(mView); + + // Select slot, set viewport + int s_x = c_it % P_o_line; + int s_y = c_it / P_o_line; + const D3D_VIEWPORT viewport = { s_x * P_o_size, s_y * P_o_size, P_o_size, P_o_size, 0.f, 1.f }; + RCache.SetViewport(viewport); + + // Clear color to ambience + Fvector& cap = LT->get_approximate(); + RCache.ClearRT(RT, color_rgba_f(cap.x, cap.y, cap.z, (cap.x + cap.y + cap.z) / 4.f)); + + // calculate uv-gen matrix and clamper + Fmatrix mCombine; + mCombine.mul(mProject, mView); + Fmatrix mTemp; + float fSlotSize = float(P_o_size) / float(P_rt_size); + float fSlotX = float(s_x * P_o_size) / float(P_rt_size); + float fSlotY = float(s_y * P_o_size) / float(P_rt_size); + float fTexelOffs = (.5f / P_rt_size); + Fmatrix m_TexelAdjust = {0.5f /*x-scale*/, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f /*y-scale*/, 0.0f, 0.0f, 0.0f, 0.0f, + 1.0f /*z-range*/, 0.0f, 0.5f /*x-bias*/, 0.5f + fTexelOffs /*y-bias*/, 0.0f /*z-bias*/, 1.0f}; + R.UVgen.mul(m_TexelAdjust, mCombine); + mTemp.scale(fSlotSize, fSlotSize, 1); + R.UVgen.mulA_44(mTemp); + mTemp.translate(fSlotX + fTexelOffs, fSlotY + fTexelOffs, 0); + R.UVgen.mulA_44(mTemp); + + // Build bbox and render + Fvector min, max; + Fbox BB; + min.set(R.C.x - p_R, R.C.y - (p_R + P_cam_range), R.C.z - p_R); + max.set(R.C.x + p_R, R.C.y + 0, R.C.z + p_R); + BB.set(min, max); + R.UVclamp_min.set(min).add(.05f); // shrink a little + R.UVclamp_max.set(max).sub(.05f); // shrink a little + ISpatial* spatial = dynamic_cast(O); + if (spatial) + { + spatial->spatial_updatesector(); + if (spatial->GetSpatialData().sector) + RImplementation.r_dsgraph_render_R1_box(spatial->GetSpatialData().sector, BB, SE_R1_LMODELS); + } + // if (spatial) RImplementation.r_dsgraph_render_subspace (spatial->spatial.sector,mCombine,v_C,FALSE); + } + + // Blur + /* + { + // Fill vertex buffer + u32 Offset; + FVF::TL4uv* pv = (FVF::TL4uv*) RCache.Vertex.Lock (4,geom_Blur.stride(),Offset); + RImplementation.ApplyBlur4 (pv,P_rt_size,P_rt_size,P_blur_kernel); + RCache.Vertex.Unlock (4,geom_Blur.stride()); + + // Actual rendering (pass0, temp2real) + RCache.set_RT (RT->pRT); + RCache.set_ZB (NULL); + RCache.set_Shader (sh_BlurTR ); + RCache.set_Geometry (geom_Blur ); + RCache.Render (D3DPT_TRIANGLELIST,Offset,0,4,0,2); + } + */ + + // Finita la comedia + RCache.set_xform_project(Device.mProject); + RCache.set_xform_view(Device.mView); +} + +#ifdef DEBUG +void CLightProjector::render() +{ + /* + #define CLS(a) color_rgba(a,a,a,a) + RCache.set_xform_world (Fidentity); + Device.Resources->OnFrameEnd (); + for (u32 it=0; itLock(4,Offset); + pv->set(0, float(_h), .0001f,.9999f, C, p0.x, p1.y); pv++; + pv->set(0, 0, .0001f,.9999f, C, p0.x, p0.y); pv++; + pv->set(float(_w), float(_h), .0001f,.9999f, C, p1.x, p1.y); pv++; + pv->set(float(_w), 0, .0001f,.9999f, C, p1.x, p0.y); pv++; + geom_Screen->Unlock (4); + + // Actual rendering + RCache.set_Shader(sh_Screen); + RCache.Draw (geom_Screen,4,2,Offset,Device.Streams_QuadIB); + } + */ +} +#endif diff --git a/src/Layers/xrRenderPC_GLR1/LightProjector.h b/src/Layers/xrRenderPC_GLR1/LightProjector.h new file mode 100755 index 00000000000..fc028e2fc94 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/LightProjector.h @@ -0,0 +1,65 @@ +// LightShadows.h: interface for the CLightShadows class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_LIGHTPRJ_H__CFA216D9_CACB_4515_9FBE_7C531649168F__INCLUDED_) +#define AFX_LIGHTPRJ_H__CFA216D9_CACB_4515_9FBE_7C531649168F__INCLUDED_ +#pragma once + +#include "Layers/xrRender/r__dsgraph_types.h" + +class CLightProjector : public pureAppActivate +{ +private: + static const int P_rt_size = 512; + static const int P_o_size = 51; + static const int P_o_line = P_rt_size / P_o_size; + static const int P_o_count = P_o_line * P_o_line; + + // + typedef R_dsgraph::_MatrixItem NODE; + struct recv + { + IRenderable* O; + Fvector C; + Fmatrix UVgen; + Fvector UVclamp_min; + Fvector UVclamp_max; + Fbox BB; + u32 dwFrame; + u32 dwTimeValid; + }; + +private: + IRenderable* current; + xr_vector cache; // same as number of slots + xr_vector receivers; + xr_vector taskid; + + ref_rt RT; + shared_str c_xform; + shared_str c_clamp; + shared_str c_factor; + +public: + void set_object(IRenderable* O); + BOOL shadowing() { return current != nullptr; } + void calculate(); + void setup(int slot); + void finalize() + { + receivers.clear(); + taskid.clear(); + } + void invalidate(); + + virtual void OnAppActivate(); +#ifdef DEBUG + void render(); +#endif + + CLightProjector(); + ~CLightProjector(); +}; + +#endif // !defined(AFX_LIGHTPRJ_H__CFA216D9_CACB_4515_9FBE_7C531649168F__INCLUDED_) diff --git a/src/Layers/xrRenderPC_GLR1/LightShadows.cpp b/src/Layers/xrRenderPC_GLR1/LightShadows.cpp new file mode 100755 index 00000000000..124a47072b8 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/LightShadows.cpp @@ -0,0 +1,645 @@ +#include "stdafx.h" +#include "LightShadows.h" +#include "FStaticRender_Types.h" +#include "Layers/xrRender/LightTrack.h" +#include "xrEngine/xr_object.h" +#include "Layers/xrRender/FBasicVisual.h" +#include "xrEngine/CustomHUD.h" +#include "xrCore/Math/MathUtil.hpp" +using namespace XRay::Math; + +const float S_distance = 144; +const float S_distance2 = S_distance * S_distance; +const float S_ideal_size = 4.f; // ideal size for the object +const float S_fade = 4.5; +const float S_fade2 = S_fade * S_fade; + +const float S_level = .05f; // clip by energy level +const int batch_size = 256; +const float S_tess = .5f; +const int S_ambient = 32; +const int S_clip = 256 - 8; +const D3DFORMAT S_rtf = D3DFMT_A8R8G8B8; +const float S_blur_kernel = 0.75f; + +const u32 cache_old = 30 * 1000; // 30 secs + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +void CLightShadows::recreate_rt() +{ + rt_shadow.destroy(); + rt_temp.destroy(); + + rt_size = ps_r2_smapsize / 2; + rt_shadow.create(r1_RT_shadow, rt_size, rt_size, S_rtf); + rt_temp.create(r1_RT_temp, rt_size, rt_size, S_rtf); +} + +#define TWO_TEMP_TEXTURES r1_RT_temp "," r1_RT_temp +#define TWO_SHADOW_TEXTURES r1_RT_shadow "," r1_RT_shadow + +// XXX: add to statistics +CLightShadows::CLightShadows() : xrc("LightShadows") +{ + current = nullptr; + rt_size = 0; + + // + recreate_rt(); + + sh_World.create("effects" DELIMITER "shadow_world", r1_RT_shadow); + geom_World.create(FVF::F_LIT, RCache.Vertex.Buffer(), NULL); + + sh_BlurTR.create("blur4", TWO_TEMP_TEXTURES); + sh_BlurRT.create("blur4", TWO_SHADOW_TEXTURES); + geom_Blur.create(FVF::F_TL4uv, RCache.Vertex.Buffer(), RCache.QuadIB); + + // Debug + sh_Screen.create("effects" DELIMITER "screen_set", r1_RT_shadow); + geom_Screen.create(FVF::F_TL, RCache.Vertex.Buffer(), RCache.QuadIB); +} + +CLightShadows::~CLightShadows() +{ + // Debug + sh_Screen.destroy(); + geom_Screen.destroy(); + + geom_Blur.destroy(); + geom_World.destroy(); + + sh_BlurRT.destroy(); + sh_BlurTR.destroy(); + sh_World.destroy(); + rt_temp.destroy(); + rt_shadow.destroy(); + + // casters + for (u32 it = 0; it < casters_pool.size(); it++) + xr_delete(casters_pool[it]); + casters_pool.clear(); + + // cache + for (u32 it = 0; it < cache.size(); it++) + xr_free(cache[it].tris); + cache.clear(); +} + +void CLightShadows::set_object(IRenderable* O) +{ + if (current == O) + return; + + if (nullptr == O) + current = nullptr; + else + { + if (!O->renderable_ShadowGenerate() || O->renderable_HUD() || + ((CROS_impl*)O->renderable_ROS())->shadow_gen_frame == Device.dwFrame) + { + current = nullptr; + return; + } + + const vis_data& vis = O->GetRenderData().visual->getVisData(); + Fvector C; + O->GetRenderData().xform.transform_tiny(C, vis.sphere.P); + float R = vis.sphere.R; + float D = C.distance_to(Device.vCameraPosition) + R; + // D=0 -> P=0; + // R P=max, R>S_ideal_size -> P=min + float _priority = (D / S_distance) * (S_ideal_size / (R + EPS)); + if (_priority < 1.f) + current = O; + else + current = nullptr; + + if (current) + { + ((CROS_impl*)O->renderable_ROS())->shadow_gen_frame = Device.dwFrame; + + // alloc + caster* cs = nullptr; + if (casters_pool.empty()) + cs = xr_new(); + else + { + cs = casters_pool.back(); + casters_pool.pop_back(); + } + + // + casters.push_back(cs); + cs->O = current; + cs->C = C; + cs->D = D; + cs->nodes.clear(); + } + } +} + +void CLightShadows::add_element(const NODE& N) +{ + if (nullptr == current) + return; + VERIFY2(casters.back()->nodes.size() < 24, "Object exceeds limit of 24 renderable parts/materials"); + if (nullptr == N.pVisual->shader->E[SE_R1_LMODELS]._get()) + return; + casters.back()->nodes.push_back(N); +} + +// +void CLightShadows::calculate() +{ +#ifdef _GPA_ENABLED + TAL_SCOPED_TASK_NAMED("CLightShadows::calculate()"); +#endif // _GPA_ENABLED + + if (casters.empty()) + return; + + BOOL bRTS = FALSE; + RCache.set_Z(false); + + if (rt_size != ps_r2_smapsize / 2) + recreate_rt(); + + // iterate on objects + int slot_id = 0; + int s_size = int(rt_size * ps_r2_ls_squality / (512 / 85)); + int slot_line = rt_size / s_size; + int slot_max = slot_line * slot_line; + const float eps = 2 * EPS_L; + for (u32 o_it = 0; o_it < casters.size(); o_it++) + { + caster& C = *casters[o_it]; + if (C.nodes.empty()) + continue; + + // Select lights and calc importance + CROS_impl* LT = (CROS_impl*)C.O->renderable_ROS(); + xr_vector& lights = LT->lights; + + // iterate on lights + for (u32 l_it = 0; (l_it < lights.size()) && (slot_id < slot_max); l_it++) + { + CROS_impl::Light& L = lights[l_it]; + if (L.energy < S_level) + continue; + + // Msg ("~ light: %d",l_it); + + // setup rt+state(s) for first use + if (!bRTS) + { + bRTS = TRUE; + RCache.set_RT(rt_temp->pRT); + RCache.set_ZB(RImplementation.Target->rt_temp_zb->pRT); + RCache.ClearRT(rt_temp, { 1.0f, 1.0f, 1.0f, 1.0f }); + } + + // calculate light center + Fvector Lpos = L.source->position; + float Lrange = L.source->range; + // Log ("* l-pos:",Lpos); + // Msg ("* l-range: %f",Lrange); + if (L.source->flags.type == IRender_Light::DIRECT) + { + // Msg (" -direct- : %f",L.energy); + Lpos.mul(L.source->direction, -100); + Lpos.add(C.C); + Lrange = 120; + } + else + { + VERIFY(_valid(Lpos)); + VERIFY(_valid(C.C)); + float _dist; + while (true) + { + _dist = C.C.distance_to(Lpos); + // Msg ("* o-dist: %f", _dist); + if (_dist > EPS_L) + break; + Lpos.y += .01f; //. hack to avoid light-in-the-center-of-object + } + float _R = C.O->GetRenderData().visual->getVisData().sphere.R + 0.1f; + // Msg ("* o-r: %f",_R); + if (_dist < _R) + { + Fvector Ldir; + Ldir.sub(C.C, Lpos); + Ldir.normalize(); + Lpos.mad(Lpos, Ldir, _dist - _R); + // Msg ("* moving lpos"); + } + } + + // calculate projection-matrix + Fmatrix mProject, mProjectR; + float p_dist = C.C.distance_to(Lpos); + float p_R = C.O->GetRenderData().visual->getVisData().sphere.R; + float p_hat = p_R / p_dist; + float p_asp = 1.f; + float p_near = p_dist - p_R - eps; + // float p_nearR = C.C.distance_to(L.source->position) + p_R*0.85f + eps; + // p_nearR = p_near; + float p_far = std::min(Lrange, std::max(p_dist + S_fade, p_dist + p_R)); + if (p_near < eps) + continue; + if (p_far < (p_near + eps)) + continue; + // Igor: make check here instead of assertion in buil_projection_hat + if (!(_abs(p_far - p_near) > eps)) + continue; + if (p_hat > 0.9f) + continue; + if (p_hat < 0.01f) + continue; + + // Msg ("* near(%f), near-x(%f)",p_near,p_nearR); + + mProject.build_projection_HAT(p_hat, p_asp, p_near, p_far); + // Igor: strange bug with building projection_hat + // building projection with the same parameters fails for the + // second time + // mProjectR.build_projection_HAT (p_hat,p_asp,p_nearR, p_far); + mProjectR = mProject; + RCache.set_xform_project(mProject); + + // calculate view-matrix + Fmatrix mView; + Fvector v_D, v_N, v_R; + v_D.sub(C.C, Lpos); + v_D.normalize(); + if (1 - _abs(v_D.y) < EPS) + v_N.set(1, 0, 0); + else + v_N.set(0, 1, 0); + v_R.crossproduct(v_N, v_D); + v_N.crossproduct(v_D, v_R); + mView.build_camera(Lpos, C.C, v_N); + RCache.set_xform_view(mView); + + // combine and build frustum + Fmatrix mCombine, mCombineR; + mCombine.mul(mProject, mView); + mCombineR.mul(mProjectR, mView); + + // Select slot and set viewport + int s_x = slot_id % slot_line; + int s_y = slot_id / slot_line; + const D3D_VIEWPORT viewport = { s_x * s_size, s_y * s_size, s_size, s_size, 0.f, 1.f }; + RCache.SetViewport(viewport); + + // Render object-parts + for (u32 n_it = 0; n_it < C.nodes.size(); n_it++) + { + NODE& N = C.nodes[n_it]; + dxRender_Visual* V = N.pVisual; + RCache.set_Element(V->shader->E[SE_R1_LMODELS]); + RCache.set_xform_world(N.Matrix); + V->Render(-1.0f); + } + + // register shadow and increment slot + shadows.push_back(shadow()); + shadows.back().O = C.O; + shadows.back().slot = slot_id; + shadows.back().C = C.C; + shadows.back().M = mCombineR; + shadows.back().L = L.source; + shadows.back().E = L.energy; +#ifdef DEBUG + shadows.back().dbg_HAT = p_hat; +#endif + slot_id++; + } + } + + // clear casters + for (u32 cs = 0; cs < casters.size(); cs++) + casters_pool.push_back(casters[cs]); + casters.clear(); + + // Blur + if (bRTS) + { + // Fill VB + u32 Offset; + FVF::TL4uv* pv = (FVF::TL4uv*)RCache.Vertex.Lock(4, geom_Blur.stride(), Offset); + RImplementation.ApplyBlur4(pv, rt_size, rt_size, S_blur_kernel); + RCache.Vertex.Unlock(4, geom_Blur.stride()); + + // Actual rendering (pass0, temp2real) + RCache.set_RT(rt_shadow->pRT); + RCache.set_ZB(RImplementation.Target->rt_temp_zb->pRT); + RCache.set_Shader(sh_BlurTR); + RCache.set_Geometry(geom_Blur); + RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 4, 0, 2); + } + + // Finita la comedia + RCache.set_Z(true); + + RCache.set_xform_project(Device.mProject); + RCache.set_xform_view(Device.mView); +} + +#define CLS(a) color_rgba(a, a, a, a) + +IC bool cache_search(const CLightShadows::cache_item& A, const CLightShadows::cache_item& B) +{ + if (A.O < B.O) + return true; + if (A.O > B.O) + return false; + if (A.L < B.L) + return true; + if (A.L > B.L) + return false; + return false; // eq +} + +// XXX: use PLC_energy from xrCore +IC float PLC_energy(Fvector& P, Fvector& N, light* L, float E) +{ + Fvector Ldir; + if (L->flags.type == IRender_Light::DIRECT) + { + // Cos + Ldir.invert(L->direction); + float D = Ldir.dotproduct(N); + if (D <= 0) + return 0; + return E; + } + else + { + // Distance + float sqD = P.distance_to_sqr(L->position); + if (sqD > (L->range * L->range)) + return 0; + + // Dir + Ldir.sub(L->position, P); + Ldir.normalize_safe(); + float D = Ldir.dotproduct(N); + if (D <= 0) + return 0; + + // Trace Light + float R = _sqrt(sqD); + float att = 1 - (1 / (1 + R)); + return (E * att); + } +} + +// XXX: use PLC_calc from xrCore (maybe) +IC int PLC_calc(Fvector& P, Fvector& N, light* L, float energy, Fvector& O) +{ + float E = PLC_energy(P, N, L, energy); + float C1 = clampr(Device.vCameraPosition.distance_to_sqr(P) / S_distance2, 0.f, 1.f); + float C2 = clampr(O.distance_to_sqr(P) / S_fade2, 0.f, 1.f); + float A = 1.f - 1.5f * E * (1.f - C1) * (1.f - C2); + return iCeil(255.f * A); +} + +void CLightShadows::render() +{ + // Gain access to collision-DB + CDB::MODEL* DB = g_pGameLevel->ObjectSpace.GetStaticModel(); + CDB::TRI* TRIS = DB->get_tris(); + Fvector* VERTS = DB->get_verts(); + + int s_size = int(rt_size * ps_r2_ls_squality / (512 / 85)); + int slot_line = rt_size / s_size; + + // Projection and xform + float _43 = Device.mProject._43; + + // Handle biasing problem when near changes + const float fMinNear = 0.1f; + const float fMaxNear = 0.2f; + const float fMinNearBias = 0.0002f; + const float fMaxNearBias = 0.002f; + float fLerpCoeff = (_43 - fMinNear) / (fMaxNear - fMinNear); + clamp(fLerpCoeff, 0.0f, 1.0f); + // lerp + Device.mProject._43 -= fMinNearBias + (fMaxNearBias - fMinNearBias) * fLerpCoeff; + // Device.mProject._43 -= 0.0002f; + Device.mProject._43 -= 0.002f; + // Device.mProject._43 -= 0.0008f; + RCache.set_xform_world(Fidentity); + RCache.set_xform_project(Device.mProject); + Fvector View = Device.vCameraPosition; + + // Render shadows + RCache.set_Shader(sh_World); + RCache.set_Geometry(geom_World); + int batch = 0; + u32 Offset = 0; + FVF::LIT* pv = (FVF::LIT*)RCache.Vertex.Lock(batch_size * 3, geom_World->vb_stride, Offset); + for (u32 s_it = 0; s_it < shadows.size(); s_it++) + { + shadow& S = shadows[s_it]; + float Le = S.L->color.intensity() * S.E; + int s_x = S.slot % slot_line; + int s_y = S.slot / slot_line; + Fvector2 t_scale, t_offset; + t_scale.set(float(s_size) / float(rt_size), float(s_size) / float(rt_size)); + t_scale.mul(.5f); + t_offset.set(float(s_x) / float(slot_line), float(s_y) / float(slot_line)); + t_offset.x += .5f / rt_size; + t_offset.y += .5f / rt_size; + + // Search the cache + cache_item* CI = nullptr; + BOOL bValid = FALSE; + cache_item CI_what; + CI_what.O = S.O; + CI_what.L = S.L; + CI_what.tris = nullptr; + xr_vector::iterator CI_ptr = std::lower_bound(cache.begin(), cache.end(), CI_what, cache_search); + if (CI_ptr == cache.end()) + { // empty ? + CI_ptr = cache.insert(CI_ptr, CI_what); + CI = &*CI_ptr; + bValid = FALSE; + } + else + { + if (CI_ptr->O != CI_what.O || CI_ptr->L != CI_what.L) + { // we found something different + CI_ptr = cache.insert(CI_ptr, CI_what); + CI = &*CI_ptr; + bValid = FALSE; + } + else + { + // Everything, OK. Check if info is still relevant... + CI = &*CI_ptr; + bValid = TRUE; + if (!CI->Op.similar(CI->O->GetRenderData().xform.c)) + bValid = FALSE; + else if (!CI->Lp.similar(CI->L->position)) + bValid = FALSE; + } + } + CI->time = Device.dwTimeGlobal; // acess time + + if (!bValid) + { + // Frustum + CFrustum F; + F.CreateFromMatrix(S.M, FRUSTUM_P_ALL); + + // Query + xrc.frustum_options(0); + xrc.frustum_query(DB, F); + if (0 == xrc.r_count()) + continue; + + // Clip polys by frustum + tess.clear(); + for (auto &p : *xrc.r_get()) + { + VERIFY((p.id >= 0) && (p.id < DB->get_tris_count())); + // + CDB::TRI& t = TRIS[p.id]; + if (t.suppress_shadows) + continue; + sPoly A, B; + A.push_back(VERTS[t.verts[0]]); + A.push_back(VERTS[t.verts[1]]); + A.push_back(VERTS[t.verts[2]]); + + // Calc plane, throw away degenerate tris and invisible to light polygons + Fplane P; + float mag = 0; + Fvector t1, t2, n; + t1.sub(A[0], A[1]); + t2.sub(A[0], A[2]); + n.crossproduct(t1, t2); + mag = n.square_magnitude(); + if (mag < EPS_S) + continue; + n.mul(1.f / _sqrt(mag)); + P.build_unit_normal(A[0], n); + float DOT_Fade = P.classify(S.L->position); + if (DOT_Fade < 0) + continue; + + // Clip polygon + sPoly* clip = F.ClipPoly(A, B); + if (nullptr == clip) + continue; + + // Triangulate poly + for (u32 v = 2; v < clip->size(); v++) + { + tess.push_back(tess_tri()); + tess_tri& T = tess.back(); + T.v[0] = (*clip)[0]; + T.v[1] = (*clip)[v - 1]; + T.v[2] = (*clip)[v]; + T.N = P.n; + } + } + + // Remember params which builded cache item + CI->O = S.O; + CI->Op = CI->O->GetRenderData().xform.c; + CI->L = S.L; + CI->Lp = CI->L->position; + CI->tcnt = tess.size(); + // Msg ("---free--- %x",u32(CI->tris)); + xr_free(CI->tris); + VERIFY(nullptr == CI->tris); + if (tess.size()) + { + CI->tris = xr_alloc(CI->tcnt); + // Msg ("---alloc--- %x",u32(CI->tris)); + CopyMemory(CI->tris, &*tess.begin(), CI->tcnt * sizeof(tess_tri)); + } + } + + // Fill VB + for (u32 tid = 0; tid < CI->tcnt; tid++) + { + tess_tri& TT = CI->tris[tid]; + Fvector* v = TT.v; + Fvector T; + Fplane ttp; + ttp.build_unit_normal(v[0], TT.N); + + if (ttp.classify(View) < 0) + continue; + /* + int c0 = PLC_calc(v[0],TT.N,S.L,Le,S.C); + int c1 = PLC_calc(v[1],TT.N,S.L,Le,S.C); + int c2 = PLC_calc(v[2],TT.N,S.L,Le,S.C); + */ + int c0, c1, c2; + + PLCCalc(c0, c1, c2, Device.vCameraPosition, v, TT.N, S.L, Le, S.C); + + if (c0 > S_clip && c1 > S_clip && c2 > S_clip) + continue; + clamp(c0, S_ambient, 255); + clamp(c1, S_ambient, 255); + clamp(c2, S_ambient, 255); + + S.M.transform(T, v[0]); + pv->set(v[0], CLS(c0), (T.x + 1) * t_scale.x + t_offset.x, (1 - T.y) * t_scale.y + t_offset.y); + pv++; + S.M.transform(T, v[1]); + pv->set(v[1], CLS(c1), (T.x + 1) * t_scale.x + t_offset.x, (1 - T.y) * t_scale.y + t_offset.y); + pv++; + S.M.transform(T, v[2]); + pv->set(v[2], CLS(c2), (T.x + 1) * t_scale.x + t_offset.x, (1 - T.y) * t_scale.y + t_offset.y); + pv++; + + batch++; + if (batch == batch_size) + { + // Flush + RCache.Vertex.Unlock(batch * 3, geom_World->vb_stride); + RCache.Render(D3DPT_TRIANGLELIST, Offset, batch); + + pv = (FVF::LIT*)RCache.Vertex.Lock(batch_size * 3, geom_World->vb_stride, Offset); + batch = 0; + } + } + } + + // Flush if nessesary + RCache.Vertex.Unlock(batch * 3, geom_World->vb_stride); + if (batch) + { + RCache.Render(D3DPT_TRIANGLELIST, Offset, batch); + } + + // Clear all shadows and free old entries in the cache + shadows.clear(); + for (int cit = 0; cit < int(cache.size()); cit++) + { + cache_item& ci = cache[cit]; + u32 time = Device.dwTimeGlobal - ci.time; + if (time > cache_old) + { + // Msg ("---free--- %x",u32(ci.tris)); + xr_free(ci.tris); + VERIFY(nullptr == ci.tris); + cache.erase(cache.begin() + cit); + cit--; + } + } + + // Projection + Device.mProject._43 = _43; + RCache.set_xform_project(Device.mProject); +} diff --git a/src/Layers/xrRenderPC_GLR1/LightShadows.h b/src/Layers/xrRenderPC_GLR1/LightShadows.h new file mode 100755 index 00000000000..f58a74cf28f --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/LightShadows.h @@ -0,0 +1,91 @@ +#if !defined(AFX_LIGHTSHADOWS_H__CFA216D9_CACB_4515_9FBE_7C531649168F__INCLUDED_) +#define AFX_LIGHTSHADOWS_H__CFA216D9_CACB_4515_9FBE_7C531649168F__INCLUDED_ +#pragma once + +#include "Layers/xrRender/light.h" +#include "Layers/xrRender/r__dsgraph_types.h" + +class CLightShadows +{ +private: + // + typedef R_dsgraph::_MatrixItem NODE; + struct caster + { + IRenderable* O; + Fvector C; + float D; + xr_vector nodes; + }; + struct shadow + { +#ifdef DEBUG + float dbg_HAT; +#endif + IRenderable* O; + int slot; + Fvector C; + Fmatrix M; + light* L; + float E; + }; + struct tess_tri + { + Fvector v[3]; + Fvector N; + }; + +public: + struct cache_item + { + IRenderable* O; + Fvector Op; + light* L; + Fvector Lp; + u32 time; + tess_tri* tris; + u32 tcnt; + + cache_item() + { + O = nullptr; + L = nullptr; + tris = nullptr; + } + }; + +private: + IRenderable* current; + xr_vector casters_pool; + xr_vector casters; + xr_vector shadows; + xr_vector tess; + xr_vector cache; + xrXRC xrc; + + ref_rt rt_shadow; + ref_rt rt_temp; + ref_shader sh_BlurTR; + ref_shader sh_BlurRT; + ref_geom geom_Blur; + ref_shader sh_World; + ref_geom geom_World; + ref_shader sh_Screen; + ref_geom geom_Screen; + + u32 rt_size; + +private: + void recreate_rt(); + +public: + void set_object(IRenderable* O); + void add_element(const NODE& N); + void calculate(); + void render(); + + CLightShadows(); + ~CLightShadows(); +}; + +#endif // !defined(AFX_LIGHTSHADOWS_H__CFA216D9_CACB_4515_9FBE_7C531649168F__INCLUDED_) diff --git a/src/Layers/xrRenderPC_GLR1/glTexture.cpp b/src/Layers/xrRenderPC_GLR1/glTexture.cpp new file mode 100755 index 00000000000..a2f94766bb8 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/glTexture.cpp @@ -0,0 +1,244 @@ +// Texture.cpp: implementation of the CTexture class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" + +#include + +constexpr cpcstr NOT_EXISTING_TEXTURE = "ed" DELIMITER "ed_not_existing_texture"; + +void fix_texture_name(pstr fn) +{ + pstr _ext = strext(fn); + if (_ext && + (0 == xr_stricmp(_ext, ".tga") || + 0 == xr_stricmp(_ext, ".dds") || + 0 == xr_stricmp(_ext, ".bmp") || + 0 == xr_stricmp(_ext, ".ogm"))) + *_ext = 0; +} + +int get_texture_load_lod(LPCSTR fn) +{ + CInifile::Sect& sect = pSettings->r_section("reduce_lod_texture_list"); + auto it_ = sect.Data.cbegin(); + auto it_e_ = sect.Data.cend(); + + auto it = it_; + auto it_e = it_e_; + + for (; it != it_e; ++it) + { + if (strstr(fn, it->first.c_str())) + { + if (psTextureLOD < 1) + return 0; + if (psTextureLOD < 3) + return 1; + return 2; + } + } + + if (psTextureLOD < 2) + return 0; + if (psTextureLOD < 4) + return 1; + return 2; +} + +u32 calc_texture_size(int lod, u32 mip_cnt, size_t orig_size) +{ + if (1 == mip_cnt) + return orig_size; + + int _lod = lod; + float res = float(orig_size); + + while (_lod > 0) + { + --_lod; + res -= res / 1.333f; + } + return iFloor(res); +} + +GLuint CRender::texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc) +{ + GLuint pTexture = 0; + string_path fn; + size_t img_size = 0; + int img_loaded_lod = 0; + gli::gl::format fmt; + u32 mip_cnt = u32(-1); + // validation + R_ASSERT(fRName); + R_ASSERT(fRName[0]); + + bool dummyTextureExist; + + // make file name + string_path fname; + strcpy_s(fname, fRName); //. andy if (strext(fname)) *strext(fname)=0; + fix_texture_name(fname); + IReader* S = nullptr; + if (!FS.exist(fn, "$game_textures$", fname, ".dds") && strstr(fname, "_bump")) goto _BUMP_from_base; + if (FS.exist(fn, "$level$", fname, ".dds")) goto _DDS; + if (FS.exist(fn, "$game_saves$", fname, ".dds")) goto _DDS; + if (FS.exist(fn, "$game_textures$", fname, ".dds")) goto _DDS; + + +#ifdef _EDITOR + ELog.Msg(mtError, "Can't find texture '%s'", fname); + return 0; +#else + + Msg("! Can't find texture '%s'", fname); + dummyTextureExist = FS.exist(fn, "$game_textures$", NOT_EXISTING_TEXTURE, ".dds"); + if (!ShadowOfChernobylMode) + R_ASSERT3(dummyTextureExist, "Dummy texture doesn't exist", NOT_EXISTING_TEXTURE); + if (!dummyTextureExist) + return 0; + +#endif + +_DDS: + { + // Load and get header + S = FS.r_open(fn); +#ifdef DEBUG + Msg("* Loaded: %s[%d]b", fn, S->length()); +#endif // DEBUG + img_size = S->length(); + R_ASSERT(S); + gli::texture texture = gli::load((char*)S->pointer(), img_size); + R_ASSERT2(!texture.empty(), fn); + + + gli::gl GL(gli::gl::PROFILE_GL33); + + gli::gl::format const format = GL.translate(texture.format(), texture.swizzles()); + GLenum target = GL.translate(texture.target()); + + glGenTextures(1, &pTexture); + glBindTexture(target, pTexture); + + glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, static_cast(texture.levels() - 1)); + + if (gli::gl::EXTERNAL_RED != format.External) // skip for properly greyscale-alpfa fonts textures + glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, &format.Swizzles[gli::SWIZZLE_RED]); + + glm::tvec3 const tex_extent(texture.extent()); + + switch (texture.target()) + { + case gli::TARGET_2D: + case gli::TARGET_CUBE: + CHK_GL(glTexStorage2D(target, static_cast(texture.levels()), format.Internal, + tex_extent.x, tex_extent.y)); + break; + case gli::TARGET_3D: + CHK_GL(glTexStorage3D(target, static_cast(texture.levels()), format.Internal, + tex_extent.x, tex_extent.y, tex_extent.z)); + break; + default: + NODEFAULT; + break; + } + + for (std::size_t layer = 0; layer < texture.layers(); ++layer) + { + for (std::size_t face = 0; face < texture.faces(); ++face) + { + for (std::size_t level = 0; level < texture.levels(); ++level) + { + glm::tvec3 const tex_level_extent(texture.extent(level)); + GLenum sub_target = gli::is_target_cube(texture.target()) + ? static_cast(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face) + : target; + + switch (texture.target()) + { + case gli::TARGET_2D: + case gli::TARGET_CUBE: + { + if (gli::is_compressed(texture.format())) + { + CHK_GL(glCompressedTexSubImage2D(sub_target, static_cast(level), + 0, 0, tex_level_extent.x, tex_level_extent.y, + format.Internal, static_cast(texture.size(level)), + texture.data(layer, face, level))); + } + else + { + CHK_GL(glTexSubImage2D(sub_target, static_cast(level), + 0, 0, tex_level_extent.x, tex_level_extent.y, + format.External, format.Type, + texture.data(layer, face, level))); + } + break; + } + case gli::TARGET_3D: + { + if (gli::is_compressed(texture.format())) + { + CHK_GL(glCompressedTexSubImage3D(target, static_cast(level), + 0, 0, 0, tex_level_extent.x, tex_level_extent.y, tex_level_extent.z, + format.Internal, static_cast(texture.size(level)), + texture.data(layer, face, level))); + } + else + { + CHK_GL(glTexSubImage3D(target, static_cast(level), + 0, 0, 0, tex_level_extent.x, tex_level_extent.y, tex_level_extent.z, + format.External, format.Type, + texture.data(layer, face, level))); + } + break; + } + default: + NODEFAULT; + break; + } + } + } + } + + FS.r_close(S); + + xr_strlwr(fn); + ret_desc = target; + img_loaded_lod = is_target_cube(texture.target()) ? img_loaded_lod : get_texture_load_lod(fn); + ret_msize = calc_texture_size(img_loaded_lod, mip_cnt, img_size); + return pTexture; + } + +_BUMP_from_base: + { + //Msg ("! auto-generated bump map: %s",fname); + Msg("! Fallback to default bump map: %s", fname); + ////////////////// + if (strstr(fname, "_bump#")) + { + R_ASSERT2 (FS.exist(fn,"$game_textures$", "ed" DELIMITER "ed_dummy_bump#", ".dds"), "ed_dummy_bump#"); + S = FS.r_open(fn); + R_ASSERT2 (S, fn); + img_size = S->length(); + goto _DDS; + } + if (strstr(fname, "_bump")) + { + R_ASSERT2 (FS.exist(fn,"$game_textures$", "ed" DELIMITER "ed_dummy_bump", ".dds"),"ed_dummy_bump"); + S = FS.r_open(fn); + + R_ASSERT2 (S, fn); + + img_size = S->length(); + goto _DDS; + } + ////////////////// + } + + return 0; +} diff --git a/src/Layers/xrRenderPC_GLR1/glr_constants.cpp b/src/Layers/xrRenderPC_GLR1/glr_constants.cpp new file mode 100755 index 00000000000..3940f640f76 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/glr_constants.cpp @@ -0,0 +1,173 @@ +#include "stdafx.h" +#pragma hdrstop + +#include "../xrRender/r_constants.h" + +static class cl_sampler : public R_constant_setup +{ + void setup(R_constant* C) override + { + CHK_GL(glProgramUniform1i(C->samp.program, C->samp.location, C->samp.index)); + } +} binder_sampler; + +IC bool p_sort(const ref_constant& C1, const ref_constant& C2) +{ + return xr_strcmp(C1->name, C2->name) < 0; +} + +// TODO: OGL: Use constant buffers like DX10. +BOOL R_constant_table::parse(void* _desc, u32 destination) +{ + GLuint program = *(GLuint*)_desc; + + // Get the maximum length of the constant name and allocate a buffer for it + GLint maxLength; + CHK_GL(glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength)); + GLchar* name = xr_alloc(maxLength + 1); // Null terminator + + // Iterate all uniforms and parse the entries for the constant table. + GLint uniformCount; + CHK_GL(glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &uniformCount)); + + for (GLint i = 0; i < uniformCount; i++) + { + GLint size; + GLenum reg; + CHK_GL(glGetActiveUniform(program, i, maxLength, NULL, &size, ®, name)); + + // Remove index from arrays + if (size > 1) + { + char* str = strstr(name, "[0]"); + if (str) *str = '\0'; + } + + u16 type = RC_float; + if (GL_BOOL == reg || + GL_BOOL_VEC2 == reg || + GL_BOOL_VEC3 == reg || + GL_BOOL_VEC4 == reg) + type = RC_bool; + if (GL_INT == reg || + GL_INT_VEC2 == reg || + GL_INT_VEC3 == reg || + GL_INT_VEC4 == reg) + type = RC_int; + + // Rindex,Rcount,Rlocation + u16 r_index = i; + u16 r_type = u16(-1); + GLuint r_location = glGetUniformLocation(program, name); + + // TypeInfo + class + BOOL bSkip = FALSE; + switch (reg) + { + case GL_FLOAT: + case GL_BOOL: + case GL_INT: + r_type = RC_1x1; + break; + case GL_FLOAT_VEC2: + case GL_BOOL_VEC2: + case GL_INT_VEC2: + r_type = RC_1x2; + break; + case GL_FLOAT_VEC3: + case GL_BOOL_VEC3: + case GL_INT_VEC3: + r_type = RC_1x3; + break; + case GL_FLOAT_VEC4: + case GL_BOOL_VEC4: + case GL_INT_VEC4: + r_type = RC_1x4; + break; + case GL_FLOAT_MAT2: + case GL_FLOAT_MAT3: + fatal("GL_FLOAT_MAT: unsupported number of dimensions"); + break; + case GL_FLOAT_MAT4x2: + r_type = RC_2x4; + break; + case GL_FLOAT_MAT4x3: + r_type = RC_3x4; + break; + case GL_FLOAT_MAT4: + r_type = RC_4x4; + break; + case GL_SAMPLER_1D: + case GL_SAMPLER_2D: + case GL_SAMPLER_3D: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_2D_SHADOW: + case GL_SAMPLER_2D_MULTISAMPLE: + { + // ***Register sampler*** + // We have determined all valuable info, search if constant already created + // Assign an unused stage as the index + ref_constant C = get(name); + if (!C) + { + C = table.emplace_back(xr_new());//.g_constant_allocator.create(); + C->name = name; + C->destination = RC_dest_sampler; + C->type = RC_sampler; + C->handler = &binder_sampler; + R_constant_load& L = C->samp; + L.index = u16(r_index + ((destination & 1) ? 0 : CTexture::rstVertex)); + L.cls = RC_sampler; + L.location = r_location; + L.program = program; + } + else + { + R_ASSERT(C->destination == RC_dest_sampler); + R_ASSERT(C->type == RC_sampler); + R_ASSERT(C->handler == &binder_sampler); + R_constant_load& L = C->samp; + R_ASSERT(L.index == r_index); + R_ASSERT(L.cls == RC_sampler); + R_ASSERT(L.location == r_location); + R_ASSERT(L.program == program); + } + } + bSkip = TRUE; + break; + default: + fatal("unsupported uniform"); + bSkip = TRUE; + break; + } + if (bSkip) continue; + + // We have determined all valuable info, search if constant already created + ref_constant C = get(name); + if (!C) + { + C = table.emplace_back(xr_new()); //.g_constant_allocator.create(); + C->name = name; + C->destination = destination; + C->type = type; + R_constant_load& L = destination & 1 ? C->ps : C->vs; + L.index = r_index; + L.cls = r_type; + L.location = r_location; + L.program = program; + } + else + { + C->destination |= destination; + VERIFY (C->type == type); + R_constant_load& L = destination & 1 ? C->ps : C->vs; + L.index = r_index; + L.cls = r_type; + L.location = r_location; + L.program = program; + } + } + sort(table.begin(), table.end(), p_sort); + xr_free(name); + return TRUE; +} diff --git a/src/Layers/xrRenderPC_GLR1/rgl_test_hw.cpp b/src/Layers/xrRenderPC_GLR1/rgl_test_hw.cpp new file mode 100755 index 00000000000..29d233d3a05 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/rgl_test_hw.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" + +class sdl_window_test_helper +{ + SDL_Window* m_window = nullptr; + SDL_GLContext m_context = nullptr; + +public: + sdl_window_test_helper() + { + HW.SetPrimaryAttributes(); + m_window = SDL_CreateWindow("TestOpenGLWindow", 0, 0, 1, 1, SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL); + if (!m_window) + { + Log("~ Cannot create helper window for OpenGL:", SDL_GetError()); + return; + } + + m_context = SDL_GL_CreateContext(m_window); + if (!m_context) + { + Log("~ Cannot create OpenGL context:", SDL_GetError()); + return; + } + } + + bool successful() const + { + return m_window && m_context; + } + + ~sdl_window_test_helper() + { + SDL_GL_DeleteContext(m_context); + SDL_DestroyWindow(m_window); + } +}; + +bool TestOpenGLSupport() +{ + // Check if minimal required OpenGL features are available + const sdl_window_test_helper windowTest; + + if (!windowTest.successful()) + return false; + /* + if (glewInit() != GLEW_OK) + { + Log("~ Could not initialize glew."); + return false; + } + + if (!glewIsSupported("GL_ARB_separate_shader_objects")) + { + Log("~ GL_ARB_separate_shader_objects not supported"); + return false; + } + */ + return true; +} + +BOOL xrRender_test_hw() +{ + return TestOpenGLSupport() ? TRUE : FALSE; +} diff --git a/src/Layers/xrRenderPC_GLR1/stdafx.cpp b/src/Layers/xrRenderPC_GLR1/stdafx.cpp new file mode 100755 index 00000000000..726a13677a0 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// xrRender_R1.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/src/Layers/xrRenderPC_GLR1/stdafx.h b/src/Layers/xrRenderPC_GLR1/stdafx.h new file mode 100755 index 00000000000..2e2f6717f41 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/stdafx.h @@ -0,0 +1,66 @@ +#pragma once + +//#include "Common/Common.hpp" + +#pragma warning(disable:4995) +#include "xrEngine/stdafx.h" +#pragma warning(default:4995) +#pragma warning(disable:4714) +#pragma warning( 4 : 4018 ) +#pragma warning( 4 : 4244 ) +#pragma warning(disable:4237) + +#include "xrEngine/vis_common.h" +#include "xrEngine/Render.h" +#include "xrEngine/IGame_Level.h" + +#include "xrParticles/psystem.h" + +#define GLEW_STATIC +#include +#include "SDL_opengl.h" +#include +#include "SDL_opengl_glext.h" + +#include "Layers/xrRenderGLR1/CommonTypes.h" + +#include "Layers/xrRenderGLR1/glHW.h" +#include "Layers/xrRender/Debug/dxPixEventWrapper.h" + +//#include "Layers/xrRender/BufferUtils.h" + +#include "Layers/xrRender/Shader.h" + +#include "Layers/xrRender/R_Backend.h" +#include "Layers/xrRender/R_Backend_Runtime.h" + +#include "Layers/xrRender/Blender.h" +#include "Layers/xrRender/Blender_CLSID.h" + +#define R_GL 0 +#define R_GLR1 5 +#define R_R1 1 +#define R_R2 2 +#define R_R3 3 +#define R_R4 4 +#define RENDER R_GLR1 + +#include "Common/_d3d_extensions.h" + +#include "Layers/xrRender/ResourceManager.h" +#include "Layers/xrRender/xrRender_console.h" + +#include "FStaticRender.h" + +#define TEX_POINT_ATT "internal" DELIMITER "internal_light_attpoint" +#define TEX_SPOT_ATT "internal" DELIMITER "internal_light_attclip" + +/* +IC void jitter(CBlender_Compile& C) +{ + C.r_Sampler("jitter0", JITTER(0), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); + C.r_Sampler("jitter1", JITTER(1), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); + C.r_Sampler("jitter2", JITTER(2), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); + C.r_Sampler("jitter3", JITTER(3), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); +} +*/ \ No newline at end of file diff --git a/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.cpp b/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.cpp new file mode 100755 index 00000000000..30107a8e7b1 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Layers/xrRender/dxRenderFactory.h" +#include "Layers/xrRender/dxUIRender.h" +#include "Layers/xrRender/dxDebugRender.h" +#include "Layers/xrRender/D3DUtils.h" + +constexpr pcstr RENDERER_RGLR1_MODE = "renderer_rglr1"; + +class RGLRendererModule final : public RendererModule +{ + xr_vector modes; + +public: + bool CheckCanAddMode() const + { + // don't duplicate + if (!modes.empty()) + { + return false; + } + // Check if shaders are available + if (!FS.exist("$game_shaders$", RImplementation.getShaderPath())) + { + Log("~ No shaders found for xrRender_GLR1"); + return false; + } + return xrRender_test_hw; + } + + const xr_vector& ObtainSupportedModes() override + { + if (CheckCanAddMode()) + { + modes.emplace_back(RENDERER_RGLR1_MODE); + } + return modes; + } + + void CheckModeConsistency(pcstr mode) const + { + R_ASSERT3(0 == xr_strcmp(mode, RENDERER_RGLR1_MODE), + "Wrong mode passed to xrRender_GLR1", mode); + } + + void SetupEnv(pcstr mode) override + { + CheckModeConsistency(mode); + GEnv.Render = &RImplementation; + GEnv.RenderFactory = &RenderFactoryImpl; + GEnv.DU = &DUImpl; + GEnv.UIRender = &UIRenderImpl; +#ifdef DEBUG + GEnv.DRender = &DebugRenderImpl; +#endif + xrRender_initconsole(); + } +} static s_rglr1_module; + +extern "C" +{ +XR_EXPORT RendererModule* GetRendererModule() +{ + return &s_rglr1_module; +} +} diff --git a/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj b/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj new file mode 100755 index 00000000000..4dcc8e3c6d0 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj @@ -0,0 +1,375 @@ + + + + + + + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E2} + xrRender_R1 + Win32Proj + + + + + + + + + + + + + + + + $(xrExternals)OpenAutomate\inc;$(xrSdkDir)include\nvapi;%(AdditionalIncludeDirectories) + _USRDLL;XRRENDER_R1_EXPORTS;USE_DX9;%(PreprocessorDefinitions) + + + nvapi$(PlatformArchitecture).lib;%(AdditionalDependencies) + $(xrExternals)OpenAutomate\libraries;%(AdditionalLibraryDirectories) + $(xrExternals)nvapi\x86;%(AdditionalLibraryDirectories) + $(xrExternals)nvapi\amd64;%(AdditionalLibraryDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + + + + + + + + + {a0f7d1fb-59a7-4717-a7e4-96f37e91998e} + + + {2578c6d8-660d-48ae-9322-7422f8664f06} + + + {94a1c366-3d19-48e6-8170-4adc2e70df97} + + + {132c62de-de85-4978-9675-c78ed4da46f0} + + + {1daec516-e52c-4a3c-a4da-ae3553e6e0f8} + + + {7885cf3c-ee04-4c67-9467-1fbf9a36b037} + + + {a19b1df2-82ec-4364-8bdf-85d13a1c89b5} + + + {ccd4afae-aa10-42c6-a452-fdee497ccdf1} + + + {632aeeb6-dc06-4e15-9551-b2b09a4b73c5} + + + {61d4856f-fa82-4f02-bb88-909ddfb1fe74} + + + + + + + + + + + + + + + + + + Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}. + + + + + + + \ No newline at end of file diff --git a/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj.filters b/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj.filters new file mode 100755 index 00000000000..98ee632a384 --- /dev/null +++ b/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj.filters @@ -0,0 +1,996 @@ + + + + + {d20e30ac-a0c2-4c5d-9c5d-98239175f95d} + + + {aa70fc28-ad7e-4c84-923b-67e5bad0bb22} + + + {94289d53-8bce-47ee-b6a3-7bd40f187842} + + + {56b1ef7c-d745-47a9-b97a-ecfda1685ee6} + + + {e335f18b-e79a-4a63-ad42-2635fae165ca} + + + {5a2a6297-0742-4e10-ad9d-148429119c67} + + + {f362ac90-e081-4ae5-bf82-2afaff5e3b8d} + + + {62f446be-e40c-45cb-b678-13fbaf88f103} + + + {f61d78ad-8bc5-4ee3-887a-b99735247683} + + + {b751bdf8-4824-46ad-9c71-a83becefb71c} + + + {67c6d54d-5182-4f90-b236-8eb5b15e3cbe} + + + {ea428694-2b88-4d5d-8ccf-9867535a0128} + + + {38d0807c-eb1a-4719-8f31-d3a62dbcd99b} + + + {b015ca6a-d62c-4bcf-aa05-964d95101276} + + + {fb91aa85-38a4-44c4-988e-a6c4608e421a} + + + {4bc3705f-0312-42a9-9c04-71a4e17647d2} + + + {66d08dfb-b689-48d3-9f9c-58e949f5e6c7} + + + {8e643d5a-2333-414d-94d0-bd3b6af60ca4} + + + {3bd0be1c-3d2a-4d1c-b6ba-edb4ac3ad03f} + + + {ee175dd1-7446-4350-a884-6b9f28ea53ef} + + + {ccd303ff-7af1-40dc-9900-5695143286c6} + + + {8842d9db-0ed0-485a-8c4c-593be3902820} + + + {5abddc08-e7aa-430e-9d1b-cca64b08b0fc} + + + {7d42b98b-7ac3-4006-9966-e35ea8237855} + + + {334782cb-bef8-436e-b8b7-5fc24b84fa03} + + + {acc438b5-6f37-45ea-bb13-d5e31298b733} + + + {2f617ea1-91cd-4273-81f3-71333014a1a6} + + + {81602497-3433-41cd-99df-828e0f3b33e2} + + + {70abdbe0-5414-4c57-84d3-3c87db6afe4a} + + + {025a08f5-9104-413d-b196-d537225343b0} + + + {142a12fd-bffd-4b0b-8c71-b3377a72a53d} + + + {f868f8bf-e10d-4fa4-800f-7b6ae4d2cac0} + + + {e23ab82d-de2d-4d32-a7ec-fa4628b63982} + + + {abff5563-b6a9-4373-b73c-2f68342e9056} + + + {5943c1a5-d8da-4b83-987e-8fa360e74a33} + + + {8395d7ee-36d7-4976-904d-da14a7441e4c} + + + {ee69b180-c562-417f-8c86-924cf5f3a989} + + + {08063a0f-5fd4-4fe0-b225-eee710ef1c1e} + + + {51e44ec6-6871-4bc1-b4bb-c331c2e64244} + + + {b0161bfa-db03-487f-b3e2-334cd1ad0375} + + + {d345b891-53f6-4a48-ae0b-a842420cd7f5} + + + {db38553d-ce02-45a5-b88d-08b43f73e71e} + + + {30e655d3-a486-47c4-8d8e-08698e168ced} + + + {d118a1ec-f8d6-4dbf-9d05-d5b5be72beaa} + + + {12b2bbc5-3ac4-4d4a-bb6e-c6731ab67487} + + + {1c1d6ff9-2dc4-4417-8633-908ed69079b1} + + + {46b96d75-9c27-4322-b372-4981f0618cb0} + + + {b4233fe2-78dd-48d9-94ff-620753340597} + + + {8b1f96de-4574-4866-a5c0-371b1d2d7a17} + + + + + Kernel + + + Kernel + + + Core + + + Core + + + Core + + + Core + + + Core\ColorMap + + + Details + + + Details + + + Details + + + Stripifier + + + Stripifier + + + Stripifier + + + Stripifier + + + Glows + + + Wallmarks + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Visibility\Sector/Portal + + + Visibility\HOM Occlusion + + + Visibility\HOM Occlusion + + + Lights + + + Lights + + + Lights + + + Lights + + + Lights + + + Lights + + + Interface implementations\RenderFactory + + + Interface implementations\RenderFactory + + + Interface implementations\LensFlare + + + Interface implementations\LensFlare + + + Interface implementations\FactoryPtr + + + Interface implementations\RainRender + + + Interface implementations\RainRender + + + Interface implementations\ThunderboltRender + + + Interface implementations\ThunderboltRender + + + Interface implementations\EnvironmentRender + + + Interface implementations\EnvironmentRender + + + Interface implementations\ConsoleRender + + + Interface implementations\ConsoleRender + + + Interface implementations\ObjectSpaceRender + + + Interface implementations\ObjectSpaceRender + + + Interface implementations\FontRender + + + Interface implementations\FontRender + + + Interface implementations\WallMarkArray + + + Interface implementations\WallMarkArray + + + Interface implementations\StatGraphRender + + + Interface implementations\StatGraphRender + + + Interface implementations\ThunderboltDescRender + + + Interface implementations\ThunderboltDescRender + + + Interface implementations\Debug + + + Interface implementations\Debug\DebugRender + + + Interface implementations\Debug\DebugRender + + + Interface implementations\UI\UIRender + + + Interface implementations\UI\UIRender + + + Interface implementations\UI\UIShader + + + Interface implementations\UI\UIShader + + + Interface implementations\UI\UISequenceVideoItem + + + Interface implementations\UI\UISequenceVideoItem + + + Refactored\HW + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources\dx9_R_shader + + + Refactored\Execution & 3D\Shaders\Resources\dx9_R_shader + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\Execution & 3D\Shaders\Blender + + + Refactored\Execution & 3D\Shaders\Blender + + + Refactored\Execution & 3D\Shaders\Blender + + + Refactored\Execution & 3D\Shaders\Blender + + + Refactored\Execution & 3D\Shaders\Blender + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\Visuals + + + Refactored\Execution & 3D\Visuals + + + Refactored\Execution & 3D\Visuals + + + Refactored\Execution & 3D\Visuals + + + Refactored\Execution & 3D\Visuals + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Gamma + + + Refactored\Interfaces + + + Refactored\Interfaces + + + Refactored\stats_manager + + + Models + + + Models + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Core + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\HW + + + Kernel + + + Refactored\HW + + + Models\Visuals + + + Core + + + Core + + + Debug + + + + + Kernel + + + Kernel + + + Kernel + + + Core + + + Core + + + Core + + + Core + + + Core + + + Core + + + Core + + + Core + + + Core + + + Core + + + Core\ColorMap + + + Details + + + Details + + + Details + + + Details + + + Details + + + Stripifier + + + Stripifier + + + Stripifier + + + Stripifier + + + Glows + + + Wallmarks + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Shading templates + + + Visibility\Sector/Portal + + + Visibility\Sector/Portal + + + Visibility\HOM Occlusion + + + Visibility\HOM Occlusion + + + Visibility\HOM Occlusion + + + Lights + + + Lights + + + Lights + + + Lights + + + Lights + + + Lights + + + Lights + + + Interface implementations\RenderFactory + + + Interface implementations\LensFlare + + + Interface implementations\RainRender + + + Interface implementations\ThunderboltRender + + + Interface implementations\EnvironmentRender + + + Interface implementations\ConsoleRender + + + Interface implementations\ObjectSpaceRender + + + Interface implementations\FontRender + + + Interface implementations\WallMarkArray + + + Interface implementations\StatGraphRender + + + Interface implementations\ThunderboltDescRender + + + Interface implementations\Debug\DebugRender + + + Interface implementations\UI\UIRender + + + Interface implementations\UI\UIShader + + + Interface implementations\UI\UISequenceVideoItem + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Backend + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\Execution & 3D\Shaders\Resources\dx9_R_shader + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Refactored\Execution & 3D\Shaders\Blender + + + Refactored\Execution & 3D\Shaders\Blender + + + Refactored\Execution & 3D\Shaders\Blender + + + Refactored\Execution & 3D\Shaders\Blender + + + Refactored\Execution & 3D\Shaders\Blender + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\DebugDraw + + + Refactored\Execution & 3D\Visuals + + + Refactored\Execution & 3D\Visuals + + + Refactored\Execution & 3D\Visuals + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Visuals\Skeleton + + + Refactored\Execution & 3D\Gamma + + + Refactored\stats_manager + + + Models + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Models\Visuals + + + Core + + + Core + + + Refactored\HW + + + Refactored\HW + + + Refactored\Execution & 3D\Shaders\Resources + + + Refactored\HW + + + Refactored\Execution & 3D\Shaders\ShaderManager + + + Visibility\Sector/Portal + + + + + + + + + + + + \ No newline at end of file From 706b71a4b926ed100d60fa683c9d6a690aacba93 Mon Sep 17 00:00:00 2001 From: Nealsbo Date: Tue, 10 May 2022 02:21:06 +0300 Subject: [PATCH 2/9] Add variables to engine about renderer and update cmake --- src/Layers/CMakeLists.txt | 3 ++- src/xrEngine/EngineAPI.cpp | 8 +++++--- src/xrEngine/main.cpp | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Layers/CMakeLists.txt b/src/Layers/CMakeLists.txt index 2ac726ff79a..ab97c177134 100644 --- a/src/Layers/CMakeLists.txt +++ b/src/Layers/CMakeLists.txt @@ -3,4 +3,5 @@ add_subdirectory(xrAPI) #add_subdirectory(xrRenderPC_R2) #add_subdirectory(xrRenderPC_R3) #add_subdirectory(xrRenderPC_R4) -add_subdirectory(xrRenderPC_GL) +#add_subdirectory(xrRenderPC_GL) +add_subdirectory(xrRenderPC_GLR1) diff --git a/src/xrEngine/EngineAPI.cpp b/src/xrEngine/EngineAPI.cpp index 83baaa04ce8..c520335dfa9 100644 --- a/src/xrEngine/EngineAPI.cpp +++ b/src/xrEngine/EngineAPI.cpp @@ -18,6 +18,7 @@ constexpr pcstr GET_RENDERER_MODULE_FUNC = "GetRendererModule"; constexpr pcstr r1_library = "xrRender_R1"; constexpr pcstr gl_library = "xrRender_GL"; +constexpr pcstr glr1_library = "xrRender_GLR1"; constexpr pcstr RENDER_LIBRARIES[] = { @@ -26,7 +27,8 @@ constexpr pcstr RENDER_LIBRARIES[] = "xrRender_R2", "xrRender_R4", #endif - gl_library + gl_library, + glr1_library }; static bool r2_available = false; @@ -206,7 +208,7 @@ void CEngineAPI::CreateRendererList() #if defined(XR_PLATFORM_WINDOWS) R_ASSERT2(loadLibrary(r1_library), "Dedicated server needs xrRender_R1 to work"); #else - R_ASSERT2(loadLibrary(gl_library), "Dedicated server needs xrRender_GL to work"); + R_ASSERT2(loadLibrary(glr1_library), "Dedicated server needs xrRender_GL to work"); #endif } else @@ -248,7 +250,7 @@ void CEngineAPI::CreateRendererList() #if defined(XR_PLATFORM_WINDOWS) static cpcstr renderForDedicated = r1_library; #else - static cpcstr renderForDedicated = gl_library; + static cpcstr renderForDedicated = glr1_library; #endif const auto it = std::find_if(renderers.begin(), renderers.end(), [](RendererDesc& desc) { diff --git a/src/xrEngine/main.cpp b/src/xrEngine/main.cpp index 1da55eb7e5c..1c7894e1ccb 100644 --- a/src/xrEngine/main.cpp +++ b/src/xrEngine/main.cpp @@ -221,6 +221,8 @@ void CheckAndSetupRenderer() if (strstr(Core.Params, "-rgl")) Console->Execute("renderer renderer_rgl"); + else if (strstr(Core.Params, "-rglr1")) + Console->Execute("renderer renderer_rglr1"); else if (strstr(Core.Params, "-r4")) Console->Execute("renderer renderer_r4"); else if (strstr(Core.Params, "-r3")) From 43d8d212773dd8995543f748cd42656cf2b57071 Mon Sep 17 00:00:00 2001 From: Nealsbo Date: Tue, 10 May 2022 02:22:57 +0300 Subject: [PATCH 3/9] Add r1 shaders, TODO: convert to work with ogl --- res/gamedata/shaders/glr1/add_point.ps | Bin 0 -> 613 bytes res/gamedata/shaders/glr1/add_ppa.ps | Bin 0 -> 500 bytes res/gamedata/shaders/glr1/add_spot.ps | Bin 0 -> 624 bytes res/gamedata/shaders/glr1/avg2.ps | Bin 0 -> 416 bytes res/gamedata/shaders/glr1/avg4.ps | Bin 0 -> 638 bytes res/gamedata/shaders/glr1/base_lplanes.ps | Bin 0 -> 391 bytes res/gamedata/shaders/glr1/base_lplanes.vs | 25 + res/gamedata/shaders/glr1/blur2.s | 7 + res/gamedata/shaders/glr1/blur4.s | 9 + res/gamedata/shaders/glr1/c.cmd | 5 + res/gamedata/shaders/glr1/clouds.ps | Bin 0 -> 437 bytes res/gamedata/shaders/glr1/clouds.s | 10 + res/gamedata/shaders/glr1/clouds.vs | 23 + res/gamedata/shaders/glr1/common.h | 138 +++++ res/gamedata/shaders/glr1/common_cbuffers.h | 22 + res/gamedata/shaders/glr1/common_defines.h | 22 + res/gamedata/shaders/glr1/common_functions.h | 491 ++++++++++++++++++ res/gamedata/shaders/glr1/common_iostructs.h | 473 +++++++++++++++++ res/gamedata/shaders/glr1/common_policies.h | 39 ++ res/gamedata/shaders/glr1/common_samplers.h | 77 +++ res/gamedata/shaders/glr1/detail.ps | Bin 0 -> 350 bytes res/gamedata/shaders/glr1/detail_still.vs | 37 ++ res/gamedata/shaders/glr1/detail_wave.vs | 51 ++ res/gamedata/shaders/glr1/details_lod.s | 23 + res/gamedata/shaders/glr1/editor.vs | 21 + .../shaders/glr1/effects_lightplanes.s | 9 + .../shaders/glr1/effects_wallmarkblend.s | 17 + .../shaders/glr1/effects_wallmarkmult.s | 19 + .../shaders/glr1/effects_wallmarkset.s | 16 + res/gamedata/shaders/glr1/effects_water.s | 29 ++ .../shaders/glr1/effects_waterryaska.s | 29 ++ .../shaders/glr1/effects_waterstuden.s | 29 ++ res/gamedata/shaders/glr1/font2.ps | Bin 0 -> 384 bytes res/gamedata/shaders/glr1/hud3d.ps | Bin 0 -> 183 bytes res/gamedata/shaders/glr1/hud3d.vs | 27 + res/gamedata/shaders/glr1/hud_crosshair.s | 6 + res/gamedata/shaders/glr1/hud_font.ps | Bin 0 -> 175 bytes res/gamedata/shaders/glr1/hud_font.s | 7 + res/gamedata/shaders/glr1/hud_font2.s | 7 + res/gamedata/shaders/glr1/hud_movie.s | 7 + res/gamedata/shaders/glr1/hud_p3d.s | 7 + res/gamedata/shaders/glr1/impl.ps | Bin 0 -> 722 bytes res/gamedata/shaders/glr1/impl.vs | 26 + res/gamedata/shaders/glr1/impl_dt.ps | Bin 0 -> 894 bytes res/gamedata/shaders/glr1/impl_dt.vs | 29 ++ res/gamedata/shaders/glr1/impl_l.ps | Bin 0 -> 611 bytes res/gamedata/shaders/glr1/impl_l.vs | 22 + res/gamedata/shaders/glr1/impl_point.vs | 13 + res/gamedata/shaders/glr1/impl_spot.vs | 13 + res/gamedata/shaders/glr1/iostructs/p_aa_aa.h | 26 + .../shaders/glr1/iostructs/p_aa_aa_combine.h | 40 ++ .../shaders/glr1/iostructs/p_aa_aa_sun.h | 54 ++ res/gamedata/shaders/glr1/iostructs/p_accum.h | 41 ++ res/gamedata/shaders/glr1/iostructs/p_build.h | 20 + .../shaders/glr1/iostructs/p_bumped.h | 67 +++ .../shaders/glr1/iostructs/p_bumped_atoc.h | 38 ++ .../shaders/glr1/iostructs/p_clouds.h | 25 + .../shaders/glr1/iostructs/p_combine.h | 55 ++ res/gamedata/shaders/glr1/iostructs/p_dumb.h | 9 + .../shaders/glr1/iostructs/p_filter.h | 28 + res/gamedata/shaders/glr1/iostructs/p_flat.h | 63 +++ .../shaders/glr1/iostructs/p_flat_atoc.h | 34 ++ res/gamedata/shaders/glr1/iostructs/p_lmape.h | 37 ++ res/gamedata/shaders/glr1/iostructs/p_lod.h | 68 +++ .../shaders/glr1/iostructs/p_lplanes.h | 22 + .../shaders/glr1/iostructs/p_mark_msaa.h | 32 ++ .../shaders/glr1/iostructs/p_model_def.h | 25 + .../shaders/glr1/iostructs/p_model_env_lq.h | 28 + .../shaders/glr1/iostructs/p_naa_aa_combine.h | 48 ++ .../shaders/glr1/iostructs/p_particle.h | 41 ++ .../glr1/iostructs/p_particle_deffer.h | 71 +++ .../shaders/glr1/iostructs/p_postpr.h | 31 ++ .../shaders/glr1/iostructs/p_rain_apply.h | 23 + .../shaders/glr1/iostructs/p_rain_layer.h | 23 + .../shaders/glr1/iostructs/p_rain_patch.h | 43 ++ .../shaders/glr1/iostructs/p_shadow_aref.h | 14 + .../shaders/glr1/iostructs/p_simple.h | 19 + .../shaders/glr1/iostructs/p_simple_color.h | 11 + res/gamedata/shaders/glr1/iostructs/p_sky.h | 35 ++ .../shaders/glr1/iostructs/p_ssao_calc.h | 44 ++ res/gamedata/shaders/glr1/iostructs/p_tl.h | 22 + res/gamedata/shaders/glr1/iostructs/p_tl0uv.h | 14 + .../shaders/glr1/iostructs/p_tl_sun.h | 46 ++ res/gamedata/shaders/glr1/iostructs/p_vert.h | 25 + .../shaders/glr1/iostructs/p_volume.h | 50 ++ .../shaders/glr1/iostructs/p_volume_sun.h | 37 ++ .../shaders/glr1/iostructs/p_volumetric.h | 39 ++ .../glr1/iostructs/p_volumetric_combine.h | 37 ++ res/gamedata/shaders/glr1/iostructs/p_water.h | 72 +++ .../shaders/glr1/iostructs/p_waterd.h | 42 ++ res/gamedata/shaders/glr1/iostructs/v_aa_aa.h | 45 ++ res/gamedata/shaders/glr1/iostructs/v_build.h | 33 ++ .../shaders/glr1/iostructs/v_clouds.h | 42 ++ .../shaders/glr1/iostructs/v_combine.h | 44 ++ .../shaders/glr1/iostructs/v_detail.h | 41 ++ res/gamedata/shaders/glr1/iostructs/v_dumb.h | 16 + .../shaders/glr1/iostructs/v_editor.h | 33 ++ .../shaders/glr1/iostructs/v_filter.h | 49 ++ res/gamedata/shaders/glr1/iostructs/v_lmape.h | 58 +++ res/gamedata/shaders/glr1/iostructs/v_lod.h | 63 +++ .../shaders/glr1/iostructs/v_lplanes.h | 43 ++ .../shaders/glr1/iostructs/v_model_bump.h | 104 ++++ .../shaders/glr1/iostructs/v_model_def.h | 92 ++++ .../glr1/iostructs/v_model_def_lplanes.h | 90 ++++ .../shaders/glr1/iostructs/v_model_distort.h | 89 ++++ .../shaders/glr1/iostructs/v_model_env_lq.h | 96 ++++ .../shaders/glr1/iostructs/v_model_flat.h | 100 ++++ .../shaders/glr1/iostructs/v_model_shadow.h | 77 +++ .../glr1/iostructs/v_model_shadow_aref.h | 80 +++ .../shaders/glr1/iostructs/v_particle.h | 59 +++ .../shaders/glr1/iostructs/v_particle_flat.h | 58 +++ .../shaders/glr1/iostructs/v_portal.h | 36 ++ .../shaders/glr1/iostructs/v_postpr.h | 37 ++ .../shaders/glr1/iostructs/v_shadow.h | 22 + .../shaders/glr1/iostructs/v_shadow_aref.h | 39 ++ res/gamedata/shaders/glr1/iostructs/v_sky.h | 44 ++ .../shaders/glr1/iostructs/v_static_bump.h | 69 +++ .../shaders/glr1/iostructs/v_static_flat.h | 65 +++ res/gamedata/shaders/glr1/iostructs/v_tl.h | 25 + res/gamedata/shaders/glr1/iostructs/v_tl0uv.h | 21 + res/gamedata/shaders/glr1/iostructs/v_tl2uv.h | 29 ++ .../shaders/glr1/iostructs/v_tree_bump.h | 51 ++ .../shaders/glr1/iostructs/v_tree_flat.h | 47 ++ .../shaders/glr1/iostructs/v_tree_shadow.h | 37 ++ res/gamedata/shaders/glr1/iostructs/v_vert.h | 48 ++ .../shaders/glr1/iostructs/v_volume.h | 21 + .../shaders/glr1/iostructs/v_volumetric.h | 41 ++ res/gamedata/shaders/glr1/iostructs/v_water.h | 86 +++ .../shaders/glr1/iostructs/v_waterd.h | 59 +++ res/gamedata/shaders/glr1/iostructs/v_wmark.h | 46 ++ res/gamedata/shaders/glr1/lmap.ps | Bin 0 -> 741 bytes res/gamedata/shaders/glr1/lmap.vs | 29 ++ res/gamedata/shaders/glr1/lmap_dt.ps | Bin 0 -> 907 bytes res/gamedata/shaders/glr1/lmap_dt.vs | 33 ++ res/gamedata/shaders/glr1/lmap_l.ps | Bin 0 -> 541 bytes res/gamedata/shaders/glr1/lmap_l.vs | 24 + res/gamedata/shaders/glr1/lmap_point.vs | 13 + res/gamedata/shaders/glr1/lmap_spot.vs | 13 + res/gamedata/shaders/glr1/lmape.ps | Bin 0 -> 850 bytes res/gamedata/shaders/glr1/lmape.vs | 33 ++ res/gamedata/shaders/glr1/lod.ps | Bin 0 -> 840 bytes res/gamedata/shaders/glr1/lod.vs | 62 +++ res/gamedata/shaders/glr1/model_def_hq.ps | Bin 0 -> 717 bytes res/gamedata/shaders/glr1/model_def_hq.vs | 42 ++ .../shaders/glr1/model_def_lplanes.vs | 29 ++ res/gamedata/shaders/glr1/model_def_lq.ps | Bin 0 -> 433 bytes res/gamedata/shaders/glr1/model_def_lq.vs | 35 ++ res/gamedata/shaders/glr1/model_def_lqs.vs | 19 + res/gamedata/shaders/glr1/model_def_point.vs | 22 + res/gamedata/shaders/glr1/model_def_shadow.vs | 22 + res/gamedata/shaders/glr1/model_def_spot.vs | 22 + res/gamedata/shaders/glr1/model_distort.vs | 29 ++ res/gamedata/shaders/glr1/model_distort2t.vs | 31 ++ .../shaders/glr1/model_distort4ghost.vs | 29 ++ .../shaders/glr1/model_distort4glass.vs | 29 ++ .../shaders/glr1/model_distort_inv.vs | 29 ++ res/gamedata/shaders/glr1/model_env.ps | Bin 0 -> 641 bytes res/gamedata/shaders/glr1/model_env_hq.ps | Bin 0 -> 842 bytes res/gamedata/shaders/glr1/model_env_hq.vs | 42 ++ res/gamedata/shaders/glr1/model_env_lq.ps | Bin 0 -> 526 bytes res/gamedata/shaders/glr1/model_env_lq.vs | 36 ++ res/gamedata/shaders/glr1/model_env_sl.ps | Bin 0 -> 567 bytes res/gamedata/shaders/glr1/model_shadow.ps | Bin 0 -> 235 bytes .../shaders/glr1/models_lightplanes.s | 9 + res/gamedata/shaders/glr1/models_pautina.s | 31 ++ res/gamedata/shaders/glr1/models_selflight.s | 13 + .../shaders/glr1/models_selflight_det.s | 13 + res/gamedata/shaders/glr1/models_selflightl.s | 13 + res/gamedata/shaders/glr1/models_xanomaly.s | 91 ++++ res/gamedata/shaders/glr1/models_xdistort.s | 21 + .../shaders/glr1/models_xdistortcolor.s | 21 + .../shaders/glr1/models_xdistortcolorl.s | 21 + .../shaders/glr1/models_xdistortcolorlinv.s | 21 + .../shaders/glr1/models_xdistortinv.s | 21 + res/gamedata/shaders/glr1/models_xglass.s | 47 ++ res/gamedata/shaders/glr1/models_xglass2.s | 47 ++ res/gamedata/shaders/glr1/models_xlens.s | 47 ++ res/gamedata/shaders/glr1/models_xmonolith.s | 47 ++ res/gamedata/shaders/glr1/models_xwindows.s | 47 ++ res/gamedata/shaders/glr1/p.bat | 12 + res/gamedata/shaders/glr1/p14.bat | 1 + res/gamedata/shaders/glr1/particle.ps | Bin 0 -> 216 bytes res/gamedata/shaders/glr1/particle.vs | 29 ++ res/gamedata/shaders/glr1/particle2t.ps | Bin 0 -> 486 bytes .../shaders/glr1/particle_alphaonly.ps | Bin 0 -> 287 bytes res/gamedata/shaders/glr1/particle_distort.ps | Bin 0 -> 351 bytes res/gamedata/shaders/glr1/particles_xadd.s | 21 + .../shaders/glr1/particles_xdistort.s | 10 + res/gamedata/shaders/glr1/portal.s | 7 + res/gamedata/shaders/glr1/portal.vs | 13 + res/gamedata/shaders/glr1/postprocess.ps | Bin 0 -> 1205 bytes res/gamedata/shaders/glr1/postprocess.s | 9 + res/gamedata/shaders/glr1/postprocess_cm.s | 25 + .../shaders/glr1/postprocess_cm_pre.ps | Bin 0 -> 716 bytes res/gamedata/shaders/glr1/postprocess_d.ps | Bin 0 -> 1354 bytes res/gamedata/shaders/glr1/postprocess_d.s | 10 + res/gamedata/shaders/glr1/postprocess_dcm.s | 26 + res/gamedata/shaders/glr1/selflight.s | 19 + .../shaders/glr1/shared/cloudconfig.h | 11 + res/gamedata/shaders/glr1/shared/common.h | 120 +++++ .../shaders/glr1/shared/waterconfig.h | 56 ++ res/gamedata/shaders/glr1/shared/watermove.h | 26 + res/gamedata/shaders/glr1/shared/wmark.h | 24 + res/gamedata/shaders/glr1/simple.ps | Bin 0 -> 210 bytes res/gamedata/shaders/glr1/simple.vs | 19 + res/gamedata/shaders/glr1/simple_color.ps | Bin 0 -> 101 bytes res/gamedata/shaders/glr1/simple_color.vs | 18 + res/gamedata/shaders/glr1/simple_point.vs | 13 + res/gamedata/shaders/glr1/simple_spot.vs | 13 + res/gamedata/shaders/glr1/skin.h | 252 +++++++++ res/gamedata/shaders/glr1/skin_main.h | 185 +++++++ res/gamedata/shaders/glr1/sky2.ps | Bin 0 -> 460 bytes res/gamedata/shaders/glr1/sky2.vs | 16 + res/gamedata/shaders/glr1/stub_default.ps | Bin 0 -> 339 bytes res/gamedata/shaders/glr1/stub_default.s | 4 + res/gamedata/shaders/glr1/stub_default.vs | 15 + res/gamedata/shaders/glr1/stub_default_ma.ps | Bin 0 -> 492 bytes .../shaders/glr1/stub_notransform_t.vs | 21 + res/gamedata/shaders/glr1/sun2.ps | Bin 0 -> 518 bytes res/gamedata/shaders/glr1/tree_s.vs | 64 +++ res/gamedata/shaders/glr1/tree_s_dt.vs | 69 +++ res/gamedata/shaders/glr1/tree_s_point.vs | 41 ++ res/gamedata/shaders/glr1/tree_s_spot.vs | 41 ++ res/gamedata/shaders/glr1/tree_test.vs | 62 +++ res/gamedata/shaders/glr1/tree_w.vs | 63 +++ res/gamedata/shaders/glr1/tree_w_dt.vs | 68 +++ res/gamedata/shaders/glr1/tree_w_point.vs | 41 ++ res/gamedata/shaders/glr1/tree_w_spot.vs | 41 ++ res/gamedata/shaders/glr1/tree_wave.vs | 63 +++ res/gamedata/shaders/glr1/tree_wave_dt.vs | 68 +++ res/gamedata/shaders/glr1/tree_wave_point.vs | 41 ++ res/gamedata/shaders/glr1/tree_wave_spot.vs | 41 ++ res/gamedata/shaders/glr1/v.bat | 3 + res/gamedata/shaders/glr1/vert.ps | Bin 0 -> 350 bytes res/gamedata/shaders/glr1/vert.vs | 29 ++ res/gamedata/shaders/glr1/vert_dt.ps | Bin 0 -> 512 bytes res/gamedata/shaders/glr1/vert_dt.vs | 35 ++ res/gamedata/shaders/glr1/vert_l.ps | Bin 0 -> 217 bytes res/gamedata/shaders/glr1/vert_l.vs | 22 + res/gamedata/shaders/glr1/vert_point.vs | 13 + res/gamedata/shaders/glr1/vert_spot.vs | 13 + res/gamedata/shaders/glr1/water.ps | Bin 0 -> 710 bytes res/gamedata/shaders/glr1/water.vs | 41 ++ res/gamedata/shaders/glr1/waterd.ps | Bin 0 -> 844 bytes res/gamedata/shaders/glr1/waterd.vs | 27 + res/gamedata/shaders/glr1/wmark.vs | 65 +++ res/gamedata/shaders/glr1/wmark_point.vs | 15 + res/gamedata/shaders/glr1/wmark_spot.vs | 15 + res/gamedata/shaders/glr1/wmarkmult.ps | Bin 0 -> 362 bytes res/gamedata/shaders/glr1/yuv2rgb.ps | Bin 0 -> 856 bytes 250 files changed, 8508 insertions(+) create mode 100755 res/gamedata/shaders/glr1/add_point.ps create mode 100755 res/gamedata/shaders/glr1/add_ppa.ps create mode 100755 res/gamedata/shaders/glr1/add_spot.ps create mode 100755 res/gamedata/shaders/glr1/avg2.ps create mode 100755 res/gamedata/shaders/glr1/avg4.ps create mode 100755 res/gamedata/shaders/glr1/base_lplanes.ps create mode 100755 res/gamedata/shaders/glr1/base_lplanes.vs create mode 100755 res/gamedata/shaders/glr1/blur2.s create mode 100755 res/gamedata/shaders/glr1/blur4.s create mode 100755 res/gamedata/shaders/glr1/c.cmd create mode 100755 res/gamedata/shaders/glr1/clouds.ps create mode 100755 res/gamedata/shaders/glr1/clouds.s create mode 100755 res/gamedata/shaders/glr1/clouds.vs create mode 100755 res/gamedata/shaders/glr1/common.h create mode 100755 res/gamedata/shaders/glr1/common_cbuffers.h create mode 100755 res/gamedata/shaders/glr1/common_defines.h create mode 100755 res/gamedata/shaders/glr1/common_functions.h create mode 100755 res/gamedata/shaders/glr1/common_iostructs.h create mode 100755 res/gamedata/shaders/glr1/common_policies.h create mode 100755 res/gamedata/shaders/glr1/common_samplers.h create mode 100755 res/gamedata/shaders/glr1/detail.ps create mode 100755 res/gamedata/shaders/glr1/detail_still.vs create mode 100755 res/gamedata/shaders/glr1/detail_wave.vs create mode 100755 res/gamedata/shaders/glr1/details_lod.s create mode 100755 res/gamedata/shaders/glr1/editor.vs create mode 100755 res/gamedata/shaders/glr1/effects_lightplanes.s create mode 100755 res/gamedata/shaders/glr1/effects_wallmarkblend.s create mode 100755 res/gamedata/shaders/glr1/effects_wallmarkmult.s create mode 100755 res/gamedata/shaders/glr1/effects_wallmarkset.s create mode 100755 res/gamedata/shaders/glr1/effects_water.s create mode 100755 res/gamedata/shaders/glr1/effects_waterryaska.s create mode 100755 res/gamedata/shaders/glr1/effects_waterstuden.s create mode 100755 res/gamedata/shaders/glr1/font2.ps create mode 100755 res/gamedata/shaders/glr1/hud3d.ps create mode 100755 res/gamedata/shaders/glr1/hud3d.vs create mode 100755 res/gamedata/shaders/glr1/hud_crosshair.s create mode 100755 res/gamedata/shaders/glr1/hud_font.ps create mode 100755 res/gamedata/shaders/glr1/hud_font.s create mode 100755 res/gamedata/shaders/glr1/hud_font2.s create mode 100755 res/gamedata/shaders/glr1/hud_movie.s create mode 100755 res/gamedata/shaders/glr1/hud_p3d.s create mode 100755 res/gamedata/shaders/glr1/impl.ps create mode 100755 res/gamedata/shaders/glr1/impl.vs create mode 100755 res/gamedata/shaders/glr1/impl_dt.ps create mode 100755 res/gamedata/shaders/glr1/impl_dt.vs create mode 100755 res/gamedata/shaders/glr1/impl_l.ps create mode 100755 res/gamedata/shaders/glr1/impl_l.vs create mode 100755 res/gamedata/shaders/glr1/impl_point.vs create mode 100755 res/gamedata/shaders/glr1/impl_spot.vs create mode 100755 res/gamedata/shaders/glr1/iostructs/p_aa_aa.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_aa_aa_combine.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_aa_aa_sun.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_accum.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_build.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_bumped.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_bumped_atoc.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_clouds.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_combine.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_dumb.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_filter.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_flat.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_flat_atoc.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_lmape.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_lod.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_lplanes.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_mark_msaa.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_model_def.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_model_env_lq.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_naa_aa_combine.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_particle.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_particle_deffer.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_postpr.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_rain_apply.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_rain_layer.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_rain_patch.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_shadow_aref.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_simple.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_simple_color.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_sky.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_ssao_calc.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_tl.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_tl0uv.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_tl_sun.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_vert.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_volume.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_volume_sun.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_volumetric.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_volumetric_combine.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_water.h create mode 100755 res/gamedata/shaders/glr1/iostructs/p_waterd.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_aa_aa.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_build.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_clouds.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_combine.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_detail.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_dumb.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_editor.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_filter.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_lmape.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_lod.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_lplanes.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_model_bump.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_model_def.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_model_def_lplanes.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_model_distort.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_model_env_lq.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_model_flat.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_model_shadow.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_model_shadow_aref.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_particle.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_particle_flat.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_portal.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_postpr.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_shadow.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_shadow_aref.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_sky.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_static_bump.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_static_flat.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_tl.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_tl0uv.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_tl2uv.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_tree_bump.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_tree_flat.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_tree_shadow.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_vert.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_volume.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_volumetric.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_water.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_waterd.h create mode 100755 res/gamedata/shaders/glr1/iostructs/v_wmark.h create mode 100755 res/gamedata/shaders/glr1/lmap.ps create mode 100755 res/gamedata/shaders/glr1/lmap.vs create mode 100755 res/gamedata/shaders/glr1/lmap_dt.ps create mode 100755 res/gamedata/shaders/glr1/lmap_dt.vs create mode 100755 res/gamedata/shaders/glr1/lmap_l.ps create mode 100755 res/gamedata/shaders/glr1/lmap_l.vs create mode 100755 res/gamedata/shaders/glr1/lmap_point.vs create mode 100755 res/gamedata/shaders/glr1/lmap_spot.vs create mode 100755 res/gamedata/shaders/glr1/lmape.ps create mode 100755 res/gamedata/shaders/glr1/lmape.vs create mode 100755 res/gamedata/shaders/glr1/lod.ps create mode 100755 res/gamedata/shaders/glr1/lod.vs create mode 100755 res/gamedata/shaders/glr1/model_def_hq.ps create mode 100755 res/gamedata/shaders/glr1/model_def_hq.vs create mode 100755 res/gamedata/shaders/glr1/model_def_lplanes.vs create mode 100755 res/gamedata/shaders/glr1/model_def_lq.ps create mode 100755 res/gamedata/shaders/glr1/model_def_lq.vs create mode 100755 res/gamedata/shaders/glr1/model_def_lqs.vs create mode 100755 res/gamedata/shaders/glr1/model_def_point.vs create mode 100755 res/gamedata/shaders/glr1/model_def_shadow.vs create mode 100755 res/gamedata/shaders/glr1/model_def_spot.vs create mode 100755 res/gamedata/shaders/glr1/model_distort.vs create mode 100755 res/gamedata/shaders/glr1/model_distort2t.vs create mode 100755 res/gamedata/shaders/glr1/model_distort4ghost.vs create mode 100755 res/gamedata/shaders/glr1/model_distort4glass.vs create mode 100755 res/gamedata/shaders/glr1/model_distort_inv.vs create mode 100755 res/gamedata/shaders/glr1/model_env.ps create mode 100755 res/gamedata/shaders/glr1/model_env_hq.ps create mode 100755 res/gamedata/shaders/glr1/model_env_hq.vs create mode 100755 res/gamedata/shaders/glr1/model_env_lq.ps create mode 100755 res/gamedata/shaders/glr1/model_env_lq.vs create mode 100755 res/gamedata/shaders/glr1/model_env_sl.ps create mode 100755 res/gamedata/shaders/glr1/model_shadow.ps create mode 100755 res/gamedata/shaders/glr1/models_lightplanes.s create mode 100755 res/gamedata/shaders/glr1/models_pautina.s create mode 100755 res/gamedata/shaders/glr1/models_selflight.s create mode 100755 res/gamedata/shaders/glr1/models_selflight_det.s create mode 100755 res/gamedata/shaders/glr1/models_selflightl.s create mode 100755 res/gamedata/shaders/glr1/models_xanomaly.s create mode 100755 res/gamedata/shaders/glr1/models_xdistort.s create mode 100755 res/gamedata/shaders/glr1/models_xdistortcolor.s create mode 100755 res/gamedata/shaders/glr1/models_xdistortcolorl.s create mode 100755 res/gamedata/shaders/glr1/models_xdistortcolorlinv.s create mode 100755 res/gamedata/shaders/glr1/models_xdistortinv.s create mode 100755 res/gamedata/shaders/glr1/models_xglass.s create mode 100755 res/gamedata/shaders/glr1/models_xglass2.s create mode 100755 res/gamedata/shaders/glr1/models_xlens.s create mode 100755 res/gamedata/shaders/glr1/models_xmonolith.s create mode 100755 res/gamedata/shaders/glr1/models_xwindows.s create mode 100755 res/gamedata/shaders/glr1/p.bat create mode 100755 res/gamedata/shaders/glr1/p14.bat create mode 100755 res/gamedata/shaders/glr1/particle.ps create mode 100755 res/gamedata/shaders/glr1/particle.vs create mode 100755 res/gamedata/shaders/glr1/particle2t.ps create mode 100755 res/gamedata/shaders/glr1/particle_alphaonly.ps create mode 100755 res/gamedata/shaders/glr1/particle_distort.ps create mode 100755 res/gamedata/shaders/glr1/particles_xadd.s create mode 100755 res/gamedata/shaders/glr1/particles_xdistort.s create mode 100755 res/gamedata/shaders/glr1/portal.s create mode 100755 res/gamedata/shaders/glr1/portal.vs create mode 100755 res/gamedata/shaders/glr1/postprocess.ps create mode 100755 res/gamedata/shaders/glr1/postprocess.s create mode 100755 res/gamedata/shaders/glr1/postprocess_cm.s create mode 100755 res/gamedata/shaders/glr1/postprocess_cm_pre.ps create mode 100755 res/gamedata/shaders/glr1/postprocess_d.ps create mode 100755 res/gamedata/shaders/glr1/postprocess_d.s create mode 100755 res/gamedata/shaders/glr1/postprocess_dcm.s create mode 100755 res/gamedata/shaders/glr1/selflight.s create mode 100755 res/gamedata/shaders/glr1/shared/cloudconfig.h create mode 100755 res/gamedata/shaders/glr1/shared/common.h create mode 100755 res/gamedata/shaders/glr1/shared/waterconfig.h create mode 100755 res/gamedata/shaders/glr1/shared/watermove.h create mode 100755 res/gamedata/shaders/glr1/shared/wmark.h create mode 100755 res/gamedata/shaders/glr1/simple.ps create mode 100755 res/gamedata/shaders/glr1/simple.vs create mode 100755 res/gamedata/shaders/glr1/simple_color.ps create mode 100755 res/gamedata/shaders/glr1/simple_color.vs create mode 100755 res/gamedata/shaders/glr1/simple_point.vs create mode 100755 res/gamedata/shaders/glr1/simple_spot.vs create mode 100755 res/gamedata/shaders/glr1/skin.h create mode 100755 res/gamedata/shaders/glr1/skin_main.h create mode 100755 res/gamedata/shaders/glr1/sky2.ps create mode 100755 res/gamedata/shaders/glr1/sky2.vs create mode 100755 res/gamedata/shaders/glr1/stub_default.ps create mode 100755 res/gamedata/shaders/glr1/stub_default.s create mode 100755 res/gamedata/shaders/glr1/stub_default.vs create mode 100644 res/gamedata/shaders/glr1/stub_default_ma.ps create mode 100644 res/gamedata/shaders/glr1/stub_notransform_t.vs create mode 100755 res/gamedata/shaders/glr1/sun2.ps create mode 100755 res/gamedata/shaders/glr1/tree_s.vs create mode 100755 res/gamedata/shaders/glr1/tree_s_dt.vs create mode 100755 res/gamedata/shaders/glr1/tree_s_point.vs create mode 100755 res/gamedata/shaders/glr1/tree_s_spot.vs create mode 100755 res/gamedata/shaders/glr1/tree_test.vs create mode 100755 res/gamedata/shaders/glr1/tree_w.vs create mode 100755 res/gamedata/shaders/glr1/tree_w_dt.vs create mode 100755 res/gamedata/shaders/glr1/tree_w_point.vs create mode 100755 res/gamedata/shaders/glr1/tree_w_spot.vs create mode 100755 res/gamedata/shaders/glr1/tree_wave.vs create mode 100755 res/gamedata/shaders/glr1/tree_wave_dt.vs create mode 100755 res/gamedata/shaders/glr1/tree_wave_point.vs create mode 100755 res/gamedata/shaders/glr1/tree_wave_spot.vs create mode 100755 res/gamedata/shaders/glr1/v.bat create mode 100755 res/gamedata/shaders/glr1/vert.ps create mode 100755 res/gamedata/shaders/glr1/vert.vs create mode 100755 res/gamedata/shaders/glr1/vert_dt.ps create mode 100755 res/gamedata/shaders/glr1/vert_dt.vs create mode 100755 res/gamedata/shaders/glr1/vert_l.ps create mode 100755 res/gamedata/shaders/glr1/vert_l.vs create mode 100755 res/gamedata/shaders/glr1/vert_point.vs create mode 100755 res/gamedata/shaders/glr1/vert_spot.vs create mode 100755 res/gamedata/shaders/glr1/water.ps create mode 100755 res/gamedata/shaders/glr1/water.vs create mode 100755 res/gamedata/shaders/glr1/waterd.ps create mode 100755 res/gamedata/shaders/glr1/waterd.vs create mode 100755 res/gamedata/shaders/glr1/wmark.vs create mode 100755 res/gamedata/shaders/glr1/wmark_point.vs create mode 100755 res/gamedata/shaders/glr1/wmark_spot.vs create mode 100755 res/gamedata/shaders/glr1/wmarkmult.ps create mode 100755 res/gamedata/shaders/glr1/yuv2rgb.ps diff --git a/res/gamedata/shaders/glr1/add_point.ps b/res/gamedata/shaders/glr1/add_point.ps new file mode 100755 index 0000000000000000000000000000000000000000..251ced0b48e75ed3f36b49015bad353e495b4de2 GIT binary patch literal 613 zcmcJMF;BxV5QS&^SDea{gkajxE$YUS4GF{=U0tVGa_lN~LlNS?b8#F<8M@)gI)Bga z-rbG1(wue*7Sgq?v*K;R`Tf5g`Wl|}SsBjV$wRN?8lGS47wq=Rmz*2?pn77QM6aEN z4J=d87W$?>IBh*t1ockuphazylz(#87>9n%e7(h^0=5CK&c!2R$uU%NRtYbcX*rQV zD0;uTL`{o_90I#aOGbSL!#g7X2#ZT00Z~_6*9BQ{&O!qPMTyM=YqUjEOJ`g+azmJr z%PJA-Lx5jObo(u26gGquIK_L2(C|#NNM@4T**(q3esrJAao}f&cqf7nlc1Gw_Om8h V%8a6a2#Gt0ZseVh2-4WU_%}hAv5Eiy literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/add_ppa.ps b/res/gamedata/shaders/glr1/add_ppa.ps new file mode 100755 index 0000000000000000000000000000000000000000..58c36436bff0a60e1d97f02cf3b1c25e226522d9 GIT binary patch literal 500 zcmcJMF>Avx5QXQvUvZ?19ZGDOOfi|_4uOD68cH{z%1SGcC1cAbq2#|;PD+~+I`&50 zckkXk-DxXLUn!bMSJ%$Y-Y1BiZ+qzphOEI4B-k4#d`949x**s+ysXM{TckN83B8I= z{X*Ck!hVobj@VnhcWq6bs2ii&tRU$4D3IoV_gENA{;h&EJ?eupcs_DYPz!B&({aWb zL=+;RHN~)?Rk|lE26GoQwgaE5L?T2onqv~QR0>&#N8RYY3m+ z|9@tDr5kCsYlS0e>)JN?#|Yr|-#)U&XT4VjDr1G4A*+RMc-!+SpRxpZ74KW?aDgei z$A{(9@&&+d9qyEz;p;np6WvC+62ORWswc)u;k0dVj*}F1b9MmOS-nQ@pQP{u?2yPD zUx{8Jo1;_v;*qhW50&vEcXE=J5ol`BUV^?7z-d}Cn#DJJ({}b#NoTvG6e&bFcPXX9 z7=1<&NvQ~DRiztYxU|N0K^ywY9QUbo5S%UYa7|sZh|ass3NxB0C~|Qe;%4qH5Qfh)zhcl!QcIEv_Tu8n^dJ;cqz7+HnywhgZo+HcqZWRBe_)76a;bd?K9>FRftRYHb O@xn_^pRyN$7yJQCMQY*z literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/avg4.ps b/res/gamedata/shaders/glr1/avg4.ps new file mode 100755 index 0000000000000000000000000000000000000000..224cdc677c379165f91a1fe8f34bdbd22be04001 GIT binary patch literal 638 zcmcK2J8Q!*5CGu$?pGY?VmHOMq-2T76n6*|TtbI#!gUp5@C#Wkfs+4T$rK`*$5w%c z<36O*ogS*TtjAA9v$AWNu8j^e#KGvXGz4F~$8RJ!6!o4Hm@-)rz}xftCeL?Sl0qEQ zM=>a$FrToig!_bFCBi4-Oin4{*jD>aH#8JYUn|Wsf9snl8eNMQ1Wi%3vL7Uq3<9$Kr!9rBqD}si@9Zq5Q7pj7gkViZ9eD;2{67C_8`%+s z=~=N$#U{mkWk>t>EIujjD{-mBq=ZxG{z5kz1g*@dTcRMaRnCoM;bXL>bjBmXeyEW6JF(c9sDSJ%gVwxKk|Nm~6_ z$sa3utaQB`88=Kx0YbE^U+QB3%mnKVUpLI@zny@_YkSch&n6|Pm#t|=+vH7734$gn zENP86D=0_fl3X*}fwpk^QtT3^>jQV*qctENNu zaL0Q~?W9RZg$wDe^{%-r*mC~Uo?=Kc((8DT#-}5dK1)uYe6UD^9gPaz4uNj{b_<+u zFsQSps6s_;z5UCJpI&6o_`kh88lUx~47&{Gv_?4CK|84My&JK|nseCT z47KopQBBYZ+yTz%tyj|BvC_-4nf5f9O891 QR9QFS{ICLOUD_FADE) o.color.w = 0 ; + + // generate tcs + float2 d0 = v.dir.xy*2-1; + float2 d1 = v.dir.wz*2-1; + o.tc0 = v.p.xz * CLOUD_TILE0 + d0*timers.z*CLOUD_SPEED0; + o.tc1 = v.p.xz * CLOUD_TILE1 + d1*timers.z*CLOUD_SPEED1; + + return o; +} diff --git a/res/gamedata/shaders/glr1/common.h b/res/gamedata/shaders/glr1/common.h new file mode 100755 index 00000000000..85f554c016b --- /dev/null +++ b/res/gamedata/shaders/glr1/common.h @@ -0,0 +1,138 @@ +#ifndef COMMON_H +#define COMMON_H + +#include "shared\common.h" + +#include "common_iostructs.h" + +uniform float4 L_dynamic_props; // per object, xyz=sun,w=hemi +uniform float4 L_dynamic_color; // dynamic light color (rgb1) - spot/point +uniform float4 L_dynamic_pos; // dynamic light pos+1/range(w) - spot/point +uniform float4x4 L_dynamic_xform; + +uniform float4x4 m_plmap_xform; +uniform float4 m_plmap_clamp [2]; // 0.w = factor + +float calc_fogging (float4 w_pos) { return dot(w_pos,fog_plane); } +float2 calc_detail (float3 w_pos) { + float dtl = distance(w_pos,eye_position)*dt_params.w; + dtl = min(dtl*dtl, 1); + float dt_mul = 1 - dtl; // dt* [1 .. 0 ] + float dt_add = .5 * dtl; // dt+ [0 .. 0.5] + return float2 (dt_mul,dt_add); +} + +float3 calc_reflection (float3 pos_w, float3 norm_w) +{ + return reflect(normalize(pos_w-eye_position), norm_w); +} + +float4 calc_spot (out float4 tc_lmap, out float2 tc_att, float4 w_pos, float3 w_norm) { + float4 s_pos = L_dynamic_xform * w_pos; + tc_lmap = s_pos.xyww; // projected in ps/ttf + tc_att = float2(s_pos.z); // z=distance * (1/range) + float3 L_dir_n = normalize ((w_pos - L_dynamic_pos).xyz); + float L_scale = dot(w_norm,-L_dir_n); + return L_dynamic_color*L_scale*saturate(calc_fogging(w_pos)); +} + +float4 calc_point (out float2 tc_att0, out float2 tc_att1, float4 w_pos, float3 w_norm) { + float3 L_dir_n = normalize ((w_pos - L_dynamic_pos).xyz); + float L_scale = dot (w_norm,-L_dir_n); + float3 L_tc = ((w_pos - L_dynamic_pos).xyz) * L_dynamic_pos.w + .5f; // tc coords + tc_att0 = L_tc.xz; + tc_att1 = L_tc.xy; + return L_dynamic_color*L_scale*saturate(calc_fogging(w_pos)); +} + +float3 calc_sun (float3 norm_w) { return L_sun_color*max(dot((norm_w),-L_sun_dir_w),0); } +float3 calc_model_hemi (float3 norm_w) { return (norm_w.y*0.5+0.5)*L_dynamic_props.w*L_hemi_color.xyz; } +float3 calc_model_lq_lighting (float3 norm_w) { return calc_model_hemi(norm_w) + L_ambient.xyz + L_dynamic_props.xyz*calc_sun(norm_w); } +float3 _calc_model_hemi (float3 norm_w) { return max(0,norm_w.y)*.2*L_hemi_color.xyz; } +float3 _calc_model_lq_lighting (float3 norm_w) { return calc_model_hemi(norm_w) + L_ambient.xyz + .5*calc_sun(norm_w); } +float4 calc_model_lmap (float3 pos_w) { + float3 pos_wc = clamp (pos_w,m_plmap_clamp[0].xyz,m_plmap_clamp[1].xyz); // clamp to BBox + float4 pos_w4c = float4 (pos_wc,1); + float4 plmap = mul (m_plmap_xform,pos_w4c); // calc plmap tc + return plmap.xyww; +} + +struct v_lmap +{ + float4 P; // : POSITION; // (float,float,float,1) + float4 N; // : NORMAL; // (nx,ny,nz,hemi occlusion) + float4 T; // : TANGENT; + float4 B; // : BINORMAL; + float2 uv0; // : TEXCOORD0; // (base) + float2 uv1; // : TEXCOORD1; // (lmap/compressed) +}; +/* +struct v_vert +{ + float4 P; // : POSITION; // (float,float,float,1) + float4 N; // : NORMAL; // (nx,ny,nz,hemi occlusion) + float4 T; // : TANGENT; + float4 B; // : BINORMAL; + float4 color; // : COLOR0; // (r,g,b,dir-occlusion) + float2 uv; // : TEXCOORD0; // (u0,v0) +}; +*/ +struct v_model +{ + float4 P; // : POSITION; // (float,float,float,1) + float3 N; // : NORMAL; // (nx,ny,nz) + float3 T; // : TANGENT; // (nx,ny,nz) + float3 B; // : BINORMAL; // (nx,ny,nz) + float2 tc; // : TEXCOORD0; // (u,v) +#ifdef SKIN_COLOR + float3 rgb_tint; +#endif +}; + +/* +struct v_detail +{ + float4 pos; // : POSITION; // (float,float,float,1) + int4 misc; // : TEXCOORD0; // (u(Q),v(Q),frac,matrix-id) +}; +*/ + +struct vf_spot +{ + float4 hpos; // : POSITION; + float2 tc0; // : TEXCOORD0; // base + float4 tc1; // : TEXCOORD1; // lmap, projected + float2 tc2; // : TEXCOORD2; // att + clipper + float4 color; // : COLOR0; +}; + +struct vf_point +{ + float4 hpos; // : POSITION; + float2 tc0; // : TEXCOORD0; // base + float2 tc1; // : TEXCOORD1; // att1 + clipper + float2 tc2; // : TEXCOORD2; // att2 + clipper + float4 color; // : COLOR0; +}; +////////////////////////////////////////////////////////////////////////////////////////// +uniform sampler2D s_base; +uniform samplerCube s_env; +uniform sampler2D s_lmap; +uniform sampler2D s_hemi; +uniform sampler2D s_att; +uniform sampler2D s_detail; + +#define def_distort float(0.05f) // we get -0.5 .. 0.5 range, this is -512 .. 512 for 1024, so scale it + +float3 v_hemi (float3 n) { return L_hemi_color.xyz/* *(.5f + .5f*n.y) */; } +float3 v_hemi_wrap (float3 n, float w) { return L_hemi_color.xyz/* *(w + (1-w)*n.y) */; } +float3 v_sun (float3 n) { return L_sun_color*max(0,dot(n,-L_sun_dir_w)); } +float3 v_sun_wrap (float3 n, float w) { return L_sun_color*(w+(1-w)*dot(n,-L_sun_dir_w)); } +float3 p_hemi (float2 tc) { + //float3 t_lmh = tex2D (s_hemi, tc); + //return dot (t_lmh,1.h/3.h); + float4 t_lmh = tex2D (s_hemi, tc); + return t_lmh.aaa; +} + +#endif // COMMON_H diff --git a/res/gamedata/shaders/glr1/common_cbuffers.h b/res/gamedata/shaders/glr1/common_cbuffers.h new file mode 100755 index 00000000000..3e1e79f65b8 --- /dev/null +++ b/res/gamedata/shaders/glr1/common_cbuffers.h @@ -0,0 +1,22 @@ +#ifndef common_cbuffers_h_included +#define common_cbuffers_h_included + +#ifndef MSAA_OPTIMIZATION +// Used by dynamic lights and volumetric effects +// TODO: OGL: Use constant buffers. +//cbuffer dynamic_light +//{ + uniform float4 Ldynamic_color; // dynamic light color (rgb1) - spot/point/sun + uniform float4 Ldynamic_pos; // dynamic light pos+1/range(w) - spot/point + uniform float4 Ldynamic_dir; // dynamic light direction - sun +//} +#else +//cbuffer dynamic_light +//{ + uniform float4 Ldynamic_color; // dynamic light color (rgb1) - spot/point/sun + uniform float4 Ldynamic_pos; // dynamic light pos+1/range(w) - spot/point + uniform float4 Ldynamic_dir; // dynamic light direction - sun +//} +#endif + +#endif // common_cbuffers_h_included \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/common_defines.h b/res/gamedata/shaders/glr1/common_defines.h new file mode 100755 index 00000000000..24a95eb35cc --- /dev/null +++ b/res/gamedata/shaders/glr1/common_defines.h @@ -0,0 +1,22 @@ +#ifndef common_defines_h_included +#define common_defines_h_included + +////////////////////////////////////////////////////////////////////////////////////////// +// Defines // +#define def_gloss float(2.0/255.0) +#define def_aref float(200.0/255.0) +#define def_dbumph float(0.333) +#define def_virtualh float(0.05) // 5cm +#define def_distort float(0.05) // we get -0.5 .. 0.5 range, this is -512 .. 512 for 1024, so scale it +#define def_hdr float(9.0) // hight luminance range float(3.0) +#define def_hdr_clip float(0.75) // + +#define LUMINANCE_VECTOR float3(0.3, 0.38, 0.22) + +////////////////////////////////////////////////////////////////////////////////////////// +#ifndef SMAP_size +#define SMAP_size 1024.0 +#endif +////////////////////////////////////////////////////////////////////////////////////////// + +#endif // common_defines_h_included \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/common_functions.h b/res/gamedata/shaders/glr1/common_functions.h new file mode 100755 index 00000000000..4ae2e4629be --- /dev/null +++ b/res/gamedata/shaders/glr1/common_functions.h @@ -0,0 +1,491 @@ +#ifndef common_functions_h_included +#define common_functions_h_included + +// contrast function +float Contrast(float Input, float ContrastPower) +{ + //piecewise contrast function + bool IsAboveHalf = Input > 0.5 ; + float ToRaise = saturate(2*(IsAboveHalf ? (1.0 - Input) : Input)); + float Output = 0.5*pow(ToRaise, ContrastPower); + Output = IsAboveHalf ? (1.0 - Output) : Output; + return Output; +} + +#ifdef USE_SHOC_RESOURCES +void tonemap( out float4 low, out float4 high, float3 rgb, float scale) +{ + rgb = rgb*scale; + + low = rgb.xyzz; + high = low/def_hdr; // 8x dynamic range +} +#else // USE_SHOC_RESOURCES +void tonemap( out float4 low, out float4 high, float3 rgb, float scale) +{ + rgb = rgb*scale; + + const float fWhiteIntensity = 1.7; + const float fWhiteIntensitySQR = fWhiteIntensity*fWhiteIntensity; + + low = ( (rgb*(1.0+rgb/fWhiteIntensitySQR)) / (rgb+1.0) ).xyzz; + high = rgb.xyzz/def_hdr; // 8x dynamic range +} +#endif // USE_SHOC_RESOURCES + +float4 combine_bloom( float3 low, float4 high) +{ + return float4( low + high.rgb*high.a, 1.0 ); +} + +float calc_fogging( float4 w_pos ) +{ + return dot(w_pos,fog_plane); +} + +float2 unpack_tc_base( float2 tc, float du, float dv ) +{ + return (tc.xy + float2 (du,dv))*(32.0/32768.0); //!Increase from 32bit to 64bit floating point +} + +float3 calc_sun_r1( float3 norm_w ) +{ + return L_sun_color*saturate(dot((norm_w),-L_sun_dir_w)); +} + +float3 calc_model_hemi_r1( float3 norm_w ) +{ + return max(0.0,norm_w.y)*L_hemi_color.rgb; +} + +float3 calc_model_lq_lighting( float3 norm_w ) +{ + return L_material.x*calc_model_hemi_r1(norm_w) + L_ambient.rgb + L_material.y*calc_sun_r1(norm_w); +} + +float3 unpack_normal( float3 v ) { return 2*v-1; } +float3 unpack_normal( float4 v ) { return 2*v.xyz-1; } +float3 unpack_bx2( float3 v ) { return 2*v-1; } +float3 unpack_bx2( float4 v ) { return 2*v.xyz-1; } +float3 unpack_bx4( float3 v ) { return 4*v-2; } //!reduce the amount of stretching from 4*v-2 and increase precision +float3 unpack_bx4( float4 v ) { return 4*v.xyz-2; } +float2 unpack_tc_lmap( float2 tc ) { return tc*(1.0/32768.0); } // [-1 .. +1 ] +float4 unpack_color( float4 c ) { return c.bgra; } +float4 unpack_D3DCOLOR( float4 c ) { return c.bgra; } +float3 unpack_D3DCOLOR( float3 c ) { return c.bgr; } + +float3 p_hemi(float2 tc) +{ + float4 t_lmh = tex2D(s_hemi, tc); + +#ifdef USE_SHOC_RESOURCES + float r_lmh = (1.0/3.0); + return float3(dot(t_lmh.rgb, float3(r_lmh, r_lmh, r_lmh))); +#else // USE_SHOC_RESOURCES + return float3(t_lmh.a); +#endif // USE_SHOC_RESOURCES +} + +float get_hemi(float4 lmh) +{ +#ifdef USE_SHOC_RESOURCES + float r_lmh = (1.0/3.0); + return dot(lmh.rgb, float3(r_lmh, r_lmh, r_lmh)); +#else // USE_SHOC_RESOURCES + return lmh.a; +#endif // USE_SHOC_RESOURCES +} + +float get_sun(float4 lmh) +{ +#ifdef USE_SHOC_RESOURCES + return lmh.a; +#else // USE_SHOC_RESOURCES + return lmh.g; +#endif // USE_SHOC_RESOURCES +} + +float3 v_hemi(float3 n) +{ + return L_hemi_color.rgb*(0.5 + 0.5*n.y); +} + +float3 v_sun(float3 n) +{ + return L_sun_color*dot(n,-L_sun_dir_w); +} + +float3 calc_reflection( float3 pos_w, float3 norm_w ) +{ + return reflect(normalize(pos_w-eye_position), norm_w); +} + +#define USABLE_BIT_1 uint(0x00002000) +#define USABLE_BIT_2 uint(0x00004000) +#define USABLE_BIT_3 uint(0x00008000) +#define USABLE_BIT_4 uint(0x00010000) +#define USABLE_BIT_5 uint(0x00020000) +#define USABLE_BIT_6 uint(0x00040000) +#define USABLE_BIT_7 uint(0x00080000) +#define USABLE_BIT_8 uint(0x00100000) +#define USABLE_BIT_9 uint(0x00200000) +#define USABLE_BIT_10 uint(0x00400000) +#define USABLE_BIT_11 uint(0x00800000) // At least two of those four bit flags must be mutually exclusive (i.e. all 4 bits must not be set together) +#define USABLE_BIT_12 uint(0x01000000) // This is because setting 0x47800000 sets all 5 FP16 exponent bits to 1 which means infinity +#define USABLE_BIT_13 uint(0x02000000) // This will be translated to a +/-MAX_FLOAT in the FP16 render target (0xFBFF/0x7BFF), overwriting the +#define USABLE_BIT_14 uint(0x04000000) // mantissa bits where other bit flags are stored. +#define USABLE_BIT_15 uint( 1 << 31) // = uint(0x80000000) // fix for integrated Intel cards +#define MUST_BE_SET uint(0x40000000) // This flag *must* be stored in the floating-point representation of the bit flag to store + +/* +float2 gbuf_pack_normal( float3 norm ) +{ + float2 res; + + res = 0.5 * ( norm.xy + float2( 1, 1 ) ) ; + res.x *= ( norm.z < 0 ? -1.0 : 1.0 ); + + return res; +} + +float3 gbuf_unpack_normal( float2 norm ) +{ + float3 res; + + res.xy = ( 2.0 * abs( norm ) ) - float2(1,1); + + res.z = ( norm.x < 0 ? -1.0 : 1.0 ) * sqrt( abs( 1 - res.x * res.x - res.y * res.y ) ); + + return res; +} +*/ + +// Holger Gruen AMD - I change normal packing and unpacking to make sure N.z is accessible without ALU cost +// this help the HDAO compute shader to run more efficiently +float2 gbuf_pack_normal( float3 norm ) +{ + float2 res; + + res.x = norm.z; + res.y = 0.5 * ( norm.x + 1.0 ) ; + res.y *= ( norm.y < 0.0 ? -1.0 : 1.0 ); + + return res; +} + +float3 gbuf_unpack_normal( float2 norm ) +{ + float3 res; + + res.z = norm.x; + res.x = ( 2.0 * abs( norm.y ) ) - 1.0; + res.y = ( norm.y < 0 ? -1.0 : 1.0 ) * sqrt( abs( 1 - res.x * res.x - res.z * res.z ) ); + + return res; +} + +float gbuf_pack_hemi_mtl( float hemi, float mtl ) +{ + uint packed_mtl = uint( ( mtl / 1.333333333 ) * 31.0 ); +// uint packed_hemi = ( MUST_BE_SET + ( uint( hemi * 255.0 ) << 13 ) + ( ( packed_mtl & uint( 31 ) ) << 21 ) ); + // Clamp hemi max value + uint packed_hemi = ( MUST_BE_SET + ( uint( saturate(hemi) * 255.9 ) << 13 ) + ( ( packed_mtl & uint( 31 ) ) << 21 ) ); + + if( ( packed_hemi & USABLE_BIT_13 ) == 0 ) + packed_hemi |= USABLE_BIT_14; + + if( ( packed_mtl & uint( 16 ) ) != 0 ) + packed_hemi |= USABLE_BIT_15; + + return asfloat( packed_hemi ); +} + +float gbuf_unpack_hemi( float mtl_hemi ) +{ +// return float( ( asuint( mtl_hemi ) >> 13 ) & uint(255) ) * (1.0/255.0); + return float( ( asuint( mtl_hemi ) >> 13 ) & uint(255) ) * (1.0/254.8); +} + +float gbuf_unpack_mtl( float mtl_hemi ) +{ + uint packed_mtl = asuint( mtl_hemi ); + uint packed_hemi = ( ( packed_mtl >> 21 ) & uint(15) ) + ( ( packed_mtl & USABLE_BIT_15 ) == 0 ? 0 : 16 ); + return float( packed_hemi ) * (1.0/31.0) * 1.333333333; +} + +#ifndef EXTEND_F_DEFFER +f_deffer pack_gbuffer( float4 norm, float4 pos, float4 col ) +#else +f_deffer pack_gbuffer( float4 norm, float4 pos, float4 col, uint imask ) +#endif +{ + f_deffer res; + +#ifndef GBUFFER_OPTIMIZATION + res.position = pos; + res.Ne = norm; + res.C = col; +#else + res.position = float4( gbuf_pack_normal( norm.xyz ), pos.z, gbuf_pack_hemi_mtl( norm.w, pos.w ) ); + res.C = col; +#endif + +#ifdef EXTEND_F_DEFFER + res.mask = imask; +#endif + + return res; +} + +#ifdef GBUFFER_OPTIMIZATION +gbuffer_data gbuffer_load_data( float2 tc, float4 pos2d, uint iSample ) +{ + gbuffer_data gbd; + + gbd.P = float3(0,0,0); + gbd.hemi = 0; + gbd.mtl = 0; + gbd.C = float3(0,0,0); + gbd.N = float3(0,0,0); + +#ifndef USE_MSAA + float4 P = tex2D( s_position, tc ); +#else + float4 P = texelFetch( s_position, int2( pos2d ), int(iSample) ); +#endif + + // 3d view space pos reconstruction math + // center of the plane (0,0) or (0.5,0.5) at distance 1 is eyepoint(0,0,0) + lookat (assuming |lookat| ==1 + // left/right = (0,0,1) -/+ tan(fHorzFOV/2) * (1,0,0 ) + // top/bottom = (0,0,1) +/- tan(fVertFOV/2) * (0,1,0 ) + // lefttop = ( -tan(fHorzFOV/2), tan(fVertFOV/2), 1 ) + // righttop = ( tan(fHorzFOV/2), tan(fVertFOV/2), 1 ) + // leftbottom = ( -tan(fHorzFOV/2), -tan(fVertFOV/2), 1 ) + // rightbottom = ( tan(fHorzFOV/2), -tan(fVertFOV/2), 1 ) + gbd.P = float3( P.z * ( pos2d.xy * pos_decompression_params.zw - pos_decompression_params.xy ), P.z ); + + // reconstruct N + gbd.N = gbuf_unpack_normal( P.xy ); + + // reconstruct material + gbd.mtl = gbuf_unpack_mtl( P.w ); + + // reconstruct hemi + gbd.hemi = gbuf_unpack_hemi( P.w ); + +#ifndef USE_MSAA + float4 C = tex2D( s_diffuse, tc ); +#else + float4 C = texelFetch( s_diffuse, int2( pos2d ), int(iSample) ); +#endif + + gbd.C = C.xyz; + gbd.gloss = C.w; + + return gbd; +} + +gbuffer_data gbuffer_load_data( float2 tc, float4 pos2d ) +{ + return gbuffer_load_data( tc, pos2d, 0 ); +} + +gbuffer_data gbuffer_load_data_offset( float2 tc, float2 OffsetTC, float4 pos2d ) +{ + float4 delta = float4( ( OffsetTC - tc ) * pos_decompression_params2.xy, 0, 0 ); + + return gbuffer_load_data( OffsetTC, pos2d + delta, 0 ); +} + +gbuffer_data gbuffer_load_data_offset( float2 tc, float2 OffsetTC, float4 pos2d, uint iSample ) +{ + float4 delta = float4( ( OffsetTC - tc ) * pos_decompression_params2.xy, 0, 0 ); + + return gbuffer_load_data( OffsetTC, pos2d + delta, iSample ); +} + +#else // GBUFFER_OPTIMIZATION +gbuffer_data gbuffer_load_data( float2 tc, uint iSample ) +{ + gbuffer_data gbd; + +#ifndef USE_MSAA + float4 P = tex2D( s_position, tc ); +#else + float4 P = texelFetch( s_position, int2( tc * pos_decompression_params2.xy ), int(iSample) ); +#endif + + gbd.P = P.xyz; + gbd.mtl = P.w; + +#ifndef USE_MSAA + float4 N = tex2D( s_normal, tc ); +#else + float4 N = texelFetch( s_normal, int2( tc * pos_decompression_params2.xy ), int(iSample) ); +#endif + + gbd.N = N.xyz; + gbd.hemi = N.w; + +#ifndef USE_MSAA + float4 C = tex2D( s_diffuse, tc ); +#else + float4 C = texelFetch( s_diffuse, int2( tc * pos_decompression_params2.xy ), int(iSample) ); +#endif + + + gbd.C = C.xyz; + gbd.gloss = C.w; + + return gbd; +} + +gbuffer_data gbuffer_load_data( float2 tc ) +{ + return gbuffer_load_data( tc, 0 ); +} + +gbuffer_data gbuffer_load_data_offset( float2 tc, float2 OffsetTC, uint iSample ) +{ + return gbuffer_load_data( OffsetTC, iSample ); +} + +#endif // GBUFFER_OPTIMIZATION + +////////////////////////////////////////////////////////////////////////// +// Aplha to coverage code +#if ( defined( MSAA_ALPHATEST_DX10_1_ATOC ) || defined( MSAA_ALPHATEST_DX10_1 ) ) + +#if MSAA_SAMPLES == 2 +uint alpha_to_coverage ( float alpha, float2 pos2d ) +{ + uint mask; + uint pos = uint(pos2d.x) | uint( pos2d.y); + if( alpha < 0.3333 ) + mask = 0; + else if( alpha < 0.6666 ) + mask = 1 << ( pos & 1 ); + else + mask = 3; + + return mask; +} +#endif + +#if MSAA_SAMPLES == 4 +uint alpha_to_coverage ( float alpha, float2 pos2d ) +{ + uint mask; + + float off = float( ( uint(pos2d.x) | uint( pos2d.y) ) & 3 ); + alpha = saturate( alpha - off * ( ( 0.2 / 4.0 ) / 3.0 ) ); + if( alpha < 0.40 ) + { + if( alpha < 0.20 ) + mask = 0; + else if( alpha < 0.40 ) // only one bit set + mask = 1; + } + else + { + if( alpha < 0.60 ) // 2 bits set => 1100 0110 0011 1001 1010 0101 + { + mask = 3; + } + else if( alpha < 0.8 ) // 3 bits set => 1110 0111 1011 1101 + mask = 7; + else + mask = 0xf; + } + + return mask; +} +#endif + +#if MSAA_SAMPLES == 8 +uint alpha_to_coverage ( float alpha, float2 pos2d ) +{ + uint mask; + + float off = float( ( uint(pos2d.x) | uint( pos2d.y) ) & 3 ); + alpha = saturate( alpha - off * ( ( 0.1111 / 8.0 ) / 3.0 ) ); + if( alpha < 0.4444 ) + { + if( alpha < 0.2222 ) + { + if( alpha < 0.1111 ) + mask = 0; + else // only one bit set 0.2222 + mask = 1; + } + else + { + if( alpha < 0.3333 ) // 2 bits set0=> 10000001 + 11000000 .. 00000011 : 8 // 0.2222 + // set1=> 10100000 .. 00000101 + 10000010 + 01000001 : 8 + // set2=> 10010000 .. 00001001 + 10000100 + 01000010 + 00100001 : 8 + // set3=> 10001000 .. 00010001 + 10001000 + 01000100 + 00100010 + 00010001 : 8 + { + mask = 3; + } + else // 3 bits set0 => 11100000 .. 00000111 + 10000011 + 11000001 : 8 ? 0.4444 // 0.3333 + // set1 => 10110000 .. 00001011 + 10000101 + 11000010 + 01100001: 8 + // set2 => 11010000 .. 00001101 + 10000110 + 01000011 + 10100001: 8 + // set3 => 10011000 .. 00010011 + 10001001 + 11000100 + 01100010 + 00110001 : 8 + // set4 => 11001000 .. 00011001 + 10001100 + 01000110 + 00100011 + 10010001 : 8 + { + mask = 0x7; + } + } + } + else + { + if( alpha < 0.6666 ) + { + if( alpha < 0.5555 ) // 4 bits set0 => 11110000 .. 00001111 + 10000111 + 11000011 + 11100001 : 8 // 0.5555 + // set1 => 11011000 .. 00011011 + 10001101 + 11000110 + 01100011 + 10110001 : 8 + // set2 => 11001100 .. 00110011 + 10011001 : 4 make 8 + // set3 => 11000110 + 01100011 + 10110001 + 11011000 + 01101100 + 00110110 + 00011011 + 10001101 : 8 + // set4 => 10111000 .. 00010111 + 10001011 + 11000101 + 11100010 + 01110001 : 8 + // set5 => 10011100 .. 00100111 + 10010011 + 11001001 + 11100100 + 01110010 + 00111001 : 8 + // set6 => 10101010 .. 01010101 : 2 make 8 + // set7 => 10110100 + 01011010 + 00101101 + 10010110 + 01001011 + 10100101 + 11010010 + 01101001 : 8 + // set8 => 10011010 + 01001101 + 10100110 + 01010011 + 10101001 + 11010100 + 01101010 + 00110101 : 8 + { + mask = 0xf; + } + else // 5 bits set0 => 11111000 01111100 00111110 00011111 10001111 11000111 11100011 11110001 : 8 // 0.6666 + // set1 => 10111100 : 8 + // set2 => 10011110 : 8 + // set3 => 11011100 : 8 + // set4 => 11001110 : 8 + // set5 => 11011010 : 8 + // set6 => 10110110 : 8 + { + mask = 0x1F; + } + } + else + { + if( alpha < 0.7777 ) // 6 bits set0 => 11111100 01111110 00111111 10011111 11001111 11100111 11110011 11111001 : 8 + // set1 => 10111110 : 8 + // set2 => 11011110 : 8 + { + mask = 0x3F; + } + else if( alpha < 0.8888 ) // 7 bits set0 => 11111110 :8 + { + mask = 0x7F; + } + else // all 8 bits set + mask = 0xFF; + } + } + + return mask; +} +#endif +#endif + + + +#endif // common_functions_h_included diff --git a/res/gamedata/shaders/glr1/common_iostructs.h b/res/gamedata/shaders/glr1/common_iostructs.h new file mode 100755 index 00000000000..c92113efe39 --- /dev/null +++ b/res/gamedata/shaders/glr1/common_iostructs.h @@ -0,0 +1,473 @@ +#ifndef common_iostructs_h_included +#define common_iostructs_h_included + +#include "shared\common.h" + +//////////////////////////////////////////////////////////////// +// This file contains io structs: +// v_name : input for vertex shader. +// v2p_name: output for vertex shader. +// p_name : input for pixel shader. +//////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////// +// TL0uv +struct v_TL0uv_positiont +{ + float4 P ; // POSITIONT; + float4 Color ; // COLOR; +}; + +struct v_TL0uv +{ + float4 P ; // POSITION; + float4 Color ; // COLOR; +}; + +struct v2p_TL0uv +{ + float4 Color ; // COLOR; + float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +struct p_TL0uv +{ + float4 Color ; // COLOR; +// float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +//////////////////////////////////////////////////////////////// +// TL +struct v_TL_positiont +{ + float4 P ; // POSITIONT; + float2 Tex0 ; // TEXCOORD0; + float4 Color ; // COLOR; +}; + +struct v_TL +{ + float4 P ; // POSITION; + float2 Tex0 ; // TEXCOORD0; + float4 Color ; // COLOR; +}; + +struct v2p_TL +{ + float2 Tex0 ; // TEXCOORD0; + float4 Color ; // COLOR; + float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +struct p_TL +{ + float2 Tex0 ; // TEXCOORD0; + float4 Color ; // COLOR; +// float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +//////////////////////////////////////////////////////////////// +// TL2uv +struct v_TL2uv +{ + float4 P ; // POSITIONT; + float2 Tex0 ; // TEXCOORD0; + float2 Tex1 ; // TEXCOORD1; + float4 Color ; // COLOR; +}; + +struct v2p_TL2uv +{ + float2 Tex0 ; // TEXCOORD0; + float2 Tex1 ; // TEXCOORD1; + float4 Color ; // COLOR; + float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +struct p_TL2uv +{ + float2 Tex0 ; // TEXCOORD0; + float2 Tex1 ; // TEXCOORD1; + float4 Color ; // COLOR; +// float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; +//////////////////////////////////////////////////////////////// +// postpr +struct v_postpr +{ + float4 P ; // POSITIONT; + float2 Tex0 ; // TEXCOORD0; // base1 (duality) + float2 Tex1 ; // TEXCOORD1; // base2 (duality) + float2 Tex2 ; // TEXCOORD2; // base (noise) + float4 Color ; // COLOR0; // multiplier, color.w = noise_amount + float4 Gray ; // COLOR1; // (.3,.3,.3.,amount) +}; + +struct v2p_postpr +{ + float2 Tex0 ; // TEXCOORD0; // base1 (duality) + float2 Tex1 ; // TEXCOORD1; // base2 (duality) + float2 Tex2 ; // TEXCOORD2; // base (noise) + float4 Color ; // COLOR0; // multiplier, color.w = noise_amount + float4 Gray ; // COLOR1; // (.3,.3,.3.,amount) + float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +struct p_postpr +{ + float2 Tex0 ; // TEXCOORD0; // base1 (duality) + float2 Tex1 ; // TEXCOORD1; // base2 (duality) + float2 Tex2 ; // TEXCOORD2; // base (noise) + float4 Color ; // COLOR0; // multiplier, color.w = noise_amount + float4 Gray ; // COLOR1; // (.3,.3,.3.,amount) +// float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; +//////////////////////////////////////////////////////////////// +// build (bloom_build) +struct v_build +{ + float4 P ; // POSITIONT; + float2 Tex0 ; // TEXCOORD0; + float2 Tex1 ; // TEXCOORD1; + float2 Tex2 ; // TEXCOORD2; + float2 Tex3 ; // TEXCOORD3; +}; + +struct v2p_build +{ + float2 Tex0 ; // TEXCOORD0; + float2 Tex1 ; // TEXCOORD1; + float2 Tex2 ; // TEXCOORD2; + float2 Tex3 ; // TEXCOORD3; + float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +struct p_build +{ + float2 Tex0 ; // TEXCOORD0; + float2 Tex1 ; // TEXCOORD1; + float2 Tex2 ; // TEXCOORD2; + float2 Tex3 ; // TEXCOORD3; +// float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; +//////////////////////////////////////////////////////////////// +// filter (bloom_filter) +struct v_filter +{ + float4 P ; // POSITIONT; + float4 Tex0 ; // TEXCOORD0; + float4 Tex1 ; // TEXCOORD1; + float4 Tex2 ; // TEXCOORD2; + float4 Tex3 ; // TEXCOORD3; + float4 Tex4 ; // TEXCOORD4; + float4 Tex5 ; // TEXCOORD5; + float4 Tex6 ; // TEXCOORD6; + float4 Tex7 ; // TEXCOORD7; +}; + +struct v2p_filter +{ + float4 Tex0 ; // TEXCOORD0; + float4 Tex1 ; // TEXCOORD1; + float4 Tex2 ; // TEXCOORD2; + float4 Tex3 ; // TEXCOORD3; + float4 Tex4 ; // TEXCOORD4; + float4 Tex5 ; // TEXCOORD5; + float4 Tex6 ; // TEXCOORD6; + float4 Tex7 ; // TEXCOORD7; + float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +struct p_filter +{ + float4 Tex0 ; // TEXCOORD0; + float4 Tex1 ; // TEXCOORD1; + float4 Tex2 ; // TEXCOORD2; + float4 Tex3 ; // TEXCOORD3; + float4 Tex4 ; // TEXCOORD4; + float4 Tex5 ; // TEXCOORD5; + float4 Tex6 ; // TEXCOORD6; + float4 Tex7 ; // TEXCOORD7; +// float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +//////////////////////////////////////////////////////////////// +// aa_AA +struct v_aa_AA +{ + float4 P ; // POSITIONT; + float2 Tex0 ; // TEXCOORD0; + float2 Tex1 ; // TEXCOORD1; + float2 Tex2 ; // TEXCOORD2; + float2 Tex3 ; // TEXCOORD3; + float2 Tex4 ; // TEXCOORD4; + float4 Tex5 ; // TEXCOORD5; + float4 Tex6 ; // TEXCOORD6; +}; + +struct v2p_aa_AA +{ + float2 Tex0 ; // TEXCOORD0; + float2 Tex1 ; // TEXCOORD1; + float2 Tex2 ; // TEXCOORD2; + float2 Tex3 ; // TEXCOORD3; + float2 Tex4 ; // TEXCOORD4; + float4 Tex5 ; // TEXCOORD5; + float4 Tex6 ; // TEXCOORD6; + float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +struct p_aa_AA +{ + float2 Tex0 ; // TEXCOORD0; + float2 Tex1 ; // TEXCOORD1; + float2 Tex2 ; // TEXCOORD2; + float2 Tex3 ; // TEXCOORD3; + float2 Tex4 ; // TEXCOORD4; + float4 Tex5 ; // TEXCOORD5; + float4 Tex6 ; // TEXCOORD6; +// float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +struct p_aa_AA_sun +{ + float2 tc ; // TEXCOORD0; + float2 unused ; // TEXCOORD1; + float2 LT ; // TEXCOORD2; + float2 RT ; // TEXCOORD3; + float2 LB ; // TEXCOORD4; + float2 RB ; // TEXCOORD5; +// float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +//////////////////////////////////////////////////////////////// +// dumb +struct v_dumb +{ + float4 P ; // POSITION; // Clip-space position (for rasterization) +}; + +struct v2p_dumb +{ + float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +}; + +//////////////////////////////////////////////////////////////// +// Volume +struct v2p_volume +{ + float4 tc ; // TEXCOORD0; +#ifdef USE_SJITTER + float4 tcJ ; // TEXCOORD1; +#endif + float4 hpos ; // SV_Position; // Clip-space position (for rasterization) +}; +struct p_volume +{ + float4 tc ; // TEXCOORD0; +#ifdef USE_SJITTER + float4 tcJ ; // TEXCOORD1; +#endif +// float4 hpos ; // SV_Position; // Clip-space position (for rasterization) +}; +//////////////////////////////////////////////////////////////// +// Static +struct v_static +{ + float4 Nh ; // NORMAL; // (nx,ny,nz,hemi occlusion) + float4 T ; // TANGENT; // tangent + float4 B ; // BINORMAL; // binormal + float2 tc ; // TEXCOORD0; // (u,v) +#ifdef USE_LM_HEMI + float2 lmh ; // TEXCOORD1; // (lmu,lmv) +#endif +// float4 color ; // COLOR0; // (r,g,b,dir-occlusion) // Swizzle before use!!! + float4 P ; // POSITION; // (float,float,float,1) +}; + +struct v_static_color +{ + float4 Nh ; // NORMAL; // (nx,ny,nz,hemi occlusion) + float4 T ; // TANGENT; // tangent + float4 B ; // BINORMAL; // binormal + float2 tc ; // TEXCOORD0; // (u,v) +#ifdef USE_LM_HEMI + float2 lmh ; // TEXCOORD1; // (lmu,lmv) +#endif + float4 color ; // COLOR0; // (r,g,b,dir-occlusion) // Swizzle before use!!! + float4 P ; // POSITION; // (float,float,float,1) +}; + +//////////////////////////////////////////////////////////////// +// defer +#ifndef GBUFFER_OPTIMIZATION +struct f_deffer +{ + float4 position; // SV_Target0; // px,py,pz, m-id + float4 Ne ; // SV_Target1; // nx,ny,nz, hemi + float4 C ; // SV_Target2; // r, g, b, gloss +#ifdef EXTEND_F_DEFFER + uint mask ; // SV_COVERAGE; +#endif +}; +#else +struct f_deffer +{ + float4 position; // SV_Target0; // xy=encoded normal, z = pz, w = encoded(m-id,hemi) + float4 C ; // SV_Target1; // r, g, b, gloss +#ifdef EXTEND_F_DEFFER + uint mask ; // SV_COVERAGE; +#endif +}; +#endif + +struct gbuffer_data +{ + float3 P; // position.( mtl or sun ) + float mtl; // material id + float3 N; // normal + float hemi; // AO + float3 C; + float gloss; +}; + +//////////////////////////////////////////////////////////////// +// Defer bumped +struct v2p_bumped +{ +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) + float4 tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else + float2 tcdh ; // TEXCOORD0; // Texture coordinates +#endif + float4 position; // TEXCOORD1; // position + hemi + float3 M1 ; // TEXCOORD2; // nmap 2 eye - 1 + float3 M2 ; // TEXCOORD3; // nmap 2 eye - 2 + float3 M3 ; // TEXCOORD4; // nmap 2 eye - 3 +#ifdef USE_TDETAIL + float2 tcdbump ; // TEXCOORD5; // d-bump +#endif +#ifdef USE_LM_HEMI + float2 lmh ; // TEXCOORD6; // lm-hemi +#endif + float4 hpos ; // SV_Position; +}; + +struct p_bumped +{ +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) + float4 tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else + float2 tcdh ; // TEXCOORD0; // Texture coordinates +#endif + float4 position; // TEXCOORD1; // position + hemi + float3 M1 ; // TEXCOORD2; // nmap 2 eye - 1 + float3 M2 ; // TEXCOORD3; // nmap 2 eye - 2 + float3 M3 ; // TEXCOORD4; // nmap 2 eye - 3 +#ifdef USE_TDETAIL + float2 tcdbump ; // TEXCOORD5; // d-bump +#endif +#ifdef USE_LM_HEMI + float2 lmh ; // TEXCOORD6; // lm-hemi +#endif +}; +//////////////////////////////////////////////////////////////// +// Defer flat +struct v2p_flat +{ +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) + float4 tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else + float2 tcdh ; // TEXCOORD0; // Texture coordinates +#endif + float4 position; // TEXCOORD1; // position + hemi + float3 N ; // TEXCOORD2; // Eye-space normal (for lighting) +#ifdef USE_TDETAIL + float2 tcdbump ; // TEXCOORD3; // d-bump +#endif +#ifdef USE_LM_HEMI + float2 lmh ; // TEXCOORD4; // lm-hemi +#endif + float4 hpos ; // SV_Position; +}; + +struct p_flat +{ +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) + float4 tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else + float2 tcdh ; // TEXCOORD0; // Texture coordinates +#endif + float4 position; // TEXCOORD1; // position + hemi + float3 N ; // TEXCOORD2; // Eye-space normal (for lighting) +#ifdef USE_TDETAIL + float2 tcdbump ; // TEXCOORD3; // d-bump +#endif +#ifdef USE_LM_HEMI + float2 lmh ; // TEXCOORD4; // lm-hemi +#endif +}; + +//////////////////////////////////////////////////////////////// +// Shadow +struct v_shadow_direct_aref +{ + float4 P ; // POSITION; // (float,float,float,1) + float4 tc ; // TEXCOORD0; // (u,v,frac,???) +}; + +struct v_shadow_direct +{ + float4 P ; // POSITION; // (float,float,float,1) +}; + + +struct v2p_shadow_direct_aref +{ + float2 tc0 ; // TEXCOORD1; // Diffuse map for aref + float4 hpos ; // SV_Position; // Clip-space position (for rasterization) +}; + +struct v2p_shadow_direct +{ + float4 hpos ; // SV_Position; // Clip-space position (for rasterization) +}; + +struct p_shadow_direct_aref +{ + float2 tc0 ; // TEXCOORD1; // Diffuse map for aref +}; + +//////////////////////////////////////////////////////////////// +// Model +/* +struct v_model +{ + float4 P ; // POSITION; // (float,float,float,1) + float3 N ; // NORMAL; // (nx,ny,nz) + float3 T ; // TANGENT; // (nx,ny,nz) + float3 B ; // BINORMAL; // (nx,ny,nz) + float2 tc ; // TEXCOORD0; // (u,v) +}; +*/ + +//////////////////////////////////////////////////////////////// +// Tree +struct v_tree +{ + float4 P ; // POSITION; // (float,float,float,1) + float4 Nh ; // NORMAL; // (nx,ny,nz) + float3 T ; // TANGENT; // tangent + float3 B ; // BINORMAL; // binormal + float4 tc ; // TEXCOORD0; // (u,v,frac,???) +}; + +//////////////////////////////////////////////////////////////// +// Details +struct v_detail +{ + float4 pos ; // POSITION; // (float,float,float,1) + float4 misc ; // TEXCOORD0; // (u(Q),v(Q),frac,matrix-id) +}; + +#endif // common_iostructs_h_included \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/common_policies.h b/res/gamedata/shaders/glr1/common_policies.h new file mode 100755 index 00000000000..bd77da3d37c --- /dev/null +++ b/res/gamedata/shaders/glr1/common_policies.h @@ -0,0 +1,39 @@ +#ifndef common_policies_h_included +#define common_policies_h_included + +// Define default sample index for MSAA +#ifndef ISAMPLE +#define ISAMPLE 0 +#endif // ISAMPLE + +// redefine sample index +#ifdef MSAA_OPTIMIZATION +#undef ISAMPLE +#define ISAMPLE iSample +#endif // MSAA_OPTIMIZATION + +///////////////////////////////////////////////////////////////////////////// +// GLD_P - gbuffer_load_data +#ifdef GBUFFER_OPTIMIZATION + #define GLD_P( _tc, _pos2d, _iSample ) _tc, _pos2d, _iSample +#else // GBUFFER_OPTIMIZATION + #define GLD_P( _tc, _pos2d, _iSample ) _tc, _iSample +#endif // GBUFFER_OPTIMIZATION + +///////////////////////////////////////////////////////////////////////////// +// CS_P +#ifdef USE_MSAA +# ifdef GBUFFER_OPTIMIZATION +# define CS_P( _P, _N, _tc0, _tcJ, _pos2d, _iSample ) _P, _N, _tc0, _tcJ, _pos2d, _iSample +# else // GBUFFER_OPTIMIZATION +# define CS_P( _P, _N, _tc0, _tcJ, _pos2d, _iSample ) _P, _N, _tc0, _tcJ, _iSample +# endif // GBUFFER_OPTIMIZATION +#else +# ifdef GBUFFER_OPTIMIZATION +# define CS_P( _P, _N, _tc0, _tcJ, _pos2d, _iSample ) _P, _N, _tc0, _tcJ, _pos2d +# else // GBUFFER_OPTIMIZATION +# define CS_P( _P, _N, _tc0, _tcJ, _pos2d, _iSample ) _P, _N, _tc0, _tcJ +# endif +#endif + +#endif // common_policies_h_included \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/common_samplers.h b/res/gamedata/shaders/glr1/common_samplers.h new file mode 100755 index 00000000000..5efd9259673 --- /dev/null +++ b/res/gamedata/shaders/glr1/common_samplers.h @@ -0,0 +1,77 @@ +#ifndef common_samplers_h_included +#define common_samplers_h_included + +#define Texture2D uniform sampler2D +#define Texture3D uniform sampler3D +#define Texture2DMS uniform sampler2DMS +#define TextureCube uniform samplerCube +#define Texture2DShadow uniform sampler2DShadow + +////////////////////////////////////////////////////////////////////////////////////////// +// Geometry phase / deferring // + +//sampler smp_nofilter; // Use D3DTADDRESS_CLAMP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT +//sampler smp_rtlinear; // Use D3DTADDRESS_CLAMP, D3DTEXF_LINEAR, D3DTEXF_NONE, D3DTEXF_LINEAR +//sampler smp_linear; // Use D3DTADDRESS_WRAP, D3DTEXF_LINEAR, D3DTEXF_LINEAR, D3DTEXF_LINEAR +//sampler smp_base; // Use D3DTADDRESS_WRAP, D3DTEXF_ANISOTROPIC, D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC + +Texture2D s_base; // smp_base +#ifdef USE_MSAA +Texture2DMS s_generic; // smp_generic +#else +Texture2D s_generic; +#endif +Texture2D s_bump; // +Texture2D s_bumpX; // +Texture2D s_detail; // +Texture2D s_detailBump; // +Texture2D s_detailBumpX; // Error for bump detail +//Texture2D s_bumpD; // +Texture2D s_hemi; // + +Texture2D s_mask; // + +Texture2D s_dt_r; // +Texture2D s_dt_g; // +Texture2D s_dt_b; // +Texture2D s_dt_a; // + +Texture2D s_dn_r; // +Texture2D s_dn_g; // +Texture2D s_dn_b; // +Texture2D s_dn_a; // + +////////////////////////////////////////////////////////////////////////////////////////// +// Lighting/shadowing phase // + +//sampler smp_material; + +//uniform sampler2D s_depth; // +#ifdef USE_MSAA +Texture2DMS s_position; // smp_nofilter or Load +Texture2DMS s_normal; // smp_nofilter or Load +#else +Texture2D s_position; // smp_nofilter or Load +Texture2D s_normal; // smp_nofilter or Load +#endif +Texture2D s_lmap; // 2D/???cube projector lightmap +Texture3D s_material; // smp_material +//uniform sampler1D s_attenuate; // + + +////////////////////////////////////////////////////////////////////////////////////////// +// Combine phase // +#ifdef USE_MSAA +Texture2DMS s_diffuse; // rgb.a = diffuse.gloss +Texture2DMS s_accumulator; // rgb.a = diffuse.specular +#else +Texture2D s_diffuse; // rgb.a = diffuse.gloss +Texture2D s_accumulator; // rgb.a = diffuse.specular +#endif +//uniform sampler2D s_generic; // +Texture2D s_bloom; // +Texture2D s_image; // used in various post-processing +Texture2D s_tonemap; // actually MidleGray / exp(Lw + eps) + + +#endif // #ifndef common_samplers_h_included \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/detail.ps b/res/gamedata/shaders/glr1/detail.ps new file mode 100755 index 0000000000000000000000000000000000000000..3cf53198891c6629deb7b2b23bc8ce41483d426b GIT binary patch literal 350 zcmcJK!D_-l6h+tfeZ@sLQ6!1cm7yzj5h$cc7u|(%I$|K1NHQrx@!va{d_!mX=Dhpv zS=LrJX%TShpY9*EEL*Rd=wr!+^B@TvwQoRJ+o zfMfYyUea7%xrikH_Ixxy>ZfUBYPTm^Rom(@RNHEch`u@tu5e)J<28cC9tD1m??{yLDbe(yp$+{bzpf_&pEg9}33JV*~`LXgzFZl!K C-B>dK literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/detail_still.vs b/res/gamedata/shaders/glr1/detail_still.vs new file mode 100755 index 00000000000..7fec3044e95 --- /dev/null +++ b/res/gamedata/shaders/glr1/detail_still.vs @@ -0,0 +1,37 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION; + float4 C : COLOR0; + float2 tc : TEXCOORD0; +}; + +uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient} +uniform float4 array [200] : register(c10); + +vf main (v_detail v) +{ + vf o; + + // index + int i = v.misc.w; + float4 m0 = array[i+0]; + float4 m1 = array[i+1]; + float4 m2 = array[i+2]; + float4 c0 = array[i+3]; + + // Transform to world coords + float4 pos; + pos.x = dot (m0, v.pos); + pos.y = dot (m1, v.pos); + pos.z = dot (m2, v.pos); + pos.w = 1; + + // Final out + o.hpos = mul (m_WVP,pos); + o.C = c0; + o.tc.xy = (v.misc * consts).xy; + + return o; +} diff --git a/res/gamedata/shaders/glr1/detail_wave.vs b/res/gamedata/shaders/glr1/detail_wave.vs new file mode 100755 index 00000000000..54f183079ee --- /dev/null +++ b/res/gamedata/shaders/glr1/detail_wave.vs @@ -0,0 +1,51 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION; + float4 C : COLOR0; + float2 tc : TEXCOORD0; +}; + +uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient} +uniform float4 wave; // cx,cy,cz,tm +uniform float4 dir2D; +uniform float4 array [200] : register(c10); + +vf main (v_detail v) +{ + vf o; + + // index + int i = v.misc.w; + float4 m0 = array[i+0]; + float4 m1 = array[i+1]; + float4 m2 = array[i+2]; + float4 c0 = array[i+3]; + + // Transform to world coords + float4 pos; + pos.x = dot (m0, v.pos); + pos.y = dot (m1, v.pos); + pos.z = dot (m2, v.pos); + pos.w = 1; + + // + float base = m1.w; + float dp = calc_cyclic (dot(pos,wave)); + float H = pos.y - base; // height of vertex (scaled) + float frac = v.misc.z*consts.x; // fractional + float inten = H * dp; + float2 result = calc_xz_wave (dir2D.xz*inten,frac); + pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1); + o.hpos = mul (m_WVP,pos); + + // Fake lighting + float dpc = max (0.f, dp); + o.C = c0 * (consts.w+consts.z*dpc*frac); + + // final xform, color, tc + o.tc.xy = (v.misc * consts).xy; + + return o; +} diff --git a/res/gamedata/shaders/glr1/details_lod.s b/res/gamedata/shaders/glr1/details_lod.s new file mode 100755 index 00000000000..028d3a7ac03 --- /dev/null +++ b/res/gamedata/shaders/glr1/details_lod.s @@ -0,0 +1,23 @@ +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("lod","lod") + : blend (false, blend.one, blend.zero) + : aref (true, 200) + : zb (true, true) + : fog (true) + shader:sampler ("s_base0") :texture (t_base) + shader:sampler ("s_base1") :texture (t_base) + shader:sampler ("s_hemi0") :texture (t_base .. "_nm") + shader:sampler ("s_hemi1") :texture (t_base .. "_nm") +end + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("lod","lod") + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,8) + : zb (true,false) + : fog (true) + shader:sampler ("s_base0") :texture (t_base) + shader:sampler ("s_base1") :texture (t_base) + shader:sampler ("s_hemi0") :texture (t_base .. "_nm") + shader:sampler ("s_hemi1") :texture (t_base .. "_nm") +end diff --git a/res/gamedata/shaders/glr1/editor.vs b/res/gamedata/shaders/glr1/editor.vs new file mode 100755 index 00000000000..f1b48d7bc38 --- /dev/null +++ b/res/gamedata/shaders/glr1/editor.vs @@ -0,0 +1,21 @@ +#include "common.h" +#include "iostructs\v_editor.h" + +/* +struct vf +{ + float4 P; //: POSITION ; + float4 C; //: COLOR0 ; +}; +*/ + +uniform float4 tfactor; +v2p _main (vf i) +{ + v2p o; + + o.P = mul(m_WVP, i.P); // xform, input in world coords + o.C = tfactor*i.C; + + return o; +} diff --git a/res/gamedata/shaders/glr1/effects_lightplanes.s b/res/gamedata/shaders/glr1/effects_lightplanes.s new file mode 100755 index 00000000000..0bdbe58b252 --- /dev/null +++ b/res/gamedata/shaders/glr1/effects_lightplanes.s @@ -0,0 +1,9 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("base_lplanes","base_lplanes") + : fog (false) + : zb (true,false) + : blend (true,blend.srcalpha,blend.one) + : aref (true,0) + : sorting (2, false) + shader:sampler ("s_base") :texture (t_base) +end diff --git a/res/gamedata/shaders/glr1/effects_wallmarkblend.s b/res/gamedata/shaders/glr1/effects_wallmarkblend.s new file mode 100755 index 00000000000..674d964587b --- /dev/null +++ b/res/gamedata/shaders/glr1/effects_wallmarkblend.s @@ -0,0 +1,17 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("wmark", "vert") + : sorting (2, false) + : blend (true,blend.zero,blend.one) + : aref (true,0) + : zb (true,false) + : fog (true) + shader:sampler ("s_base") :texture (t_base) +end + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "wmark_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "wmark_point") +end diff --git a/res/gamedata/shaders/glr1/effects_wallmarkmult.s b/res/gamedata/shaders/glr1/effects_wallmarkmult.s new file mode 100755 index 00000000000..1ab0d66d0d5 --- /dev/null +++ b/res/gamedata/shaders/glr1/effects_wallmarkmult.s @@ -0,0 +1,19 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("wmark", "wmarkmult") + : sorting (2, false) + : blend (true,blend.destcolor,blend.srccolor) + : aref (false,0) + : zb (true,true) + : fog (true) + : wmark (true) + shader:sampler ("s_base") :texture (t_base) +end + + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "wmark_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "wmark_point") +end \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/effects_wallmarkset.s b/res/gamedata/shaders/glr1/effects_wallmarkset.s new file mode 100755 index 00000000000..bf032f6e9e2 --- /dev/null +++ b/res/gamedata/shaders/glr1/effects_wallmarkset.s @@ -0,0 +1,16 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("wmark", "vert") + : sorting (1, false) + : aref (false,0) + : zb (true,true) + : fog (true) + shader:sampler ("s_base") :texture (t_base) +end + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "wmark_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "wmark_point") +end diff --git a/res/gamedata/shaders/glr1/effects_water.s b/res/gamedata/shaders/glr1/effects_water.s new file mode 100755 index 00000000000..1120f17537d --- /dev/null +++ b/res/gamedata/shaders/glr1/effects_water.s @@ -0,0 +1,29 @@ +local tex_base = "water\\water_water_r1" +local tex_env = "sky\\sky_5_cube" +local tex_dist = "water\\water_dudv" +local tex_dist2 = "water\\water_dudv" + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("water","water") + : sorting (2, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : zb (true,false) + : distort (true) + : fog (true) + shader:sampler ("s_base") :texture (tex_base) + shader:sampler ("s_env") :texture (tex_env) : clamp() +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("waterd","waterd") + : sorting (2, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (tex_base) + shader:sampler ("s_distort0") :texture (tex_dist) + shader:sampler ("s_distort1") :texture (tex_dist2) +end + diff --git a/res/gamedata/shaders/glr1/effects_waterryaska.s b/res/gamedata/shaders/glr1/effects_waterryaska.s new file mode 100755 index 00000000000..80c81a3cc3b --- /dev/null +++ b/res/gamedata/shaders/glr1/effects_waterryaska.s @@ -0,0 +1,29 @@ +local tex_base = "water\\water_ryaska1" +local tex_env = "sky\\sky_5_cube" +local tex_dist = "water\\water_dudv" +local tex_dist2 = "water\\water_dudv" + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("water","water") + : sorting (2, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : zb (true,false) + : distort (true) + : fog (true) + shader:sampler ("s_base") :texture (tex_base) + shader:sampler ("s_env") :texture (tex_env) : clamp() +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("waterd","waterd") + : sorting (2, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (tex_base) + shader:sampler ("s_distort0") :texture (tex_dist) + shader:sampler ("s_distort1") :texture (tex_dist2) +end + diff --git a/res/gamedata/shaders/glr1/effects_waterstuden.s b/res/gamedata/shaders/glr1/effects_waterstuden.s new file mode 100755 index 00000000000..6aeb6c818e3 --- /dev/null +++ b/res/gamedata/shaders/glr1/effects_waterstuden.s @@ -0,0 +1,29 @@ +local tex_base = "water\\water_studen" +local tex_env = "sky\\sky_5_cube" +local tex_dist = "water\\water_dudv" +local tex_dist2 = "water\\water_dudv" + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("water","water") + : sorting (2, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : zb (true,false) + : distort (true) + : fog (true) + shader:sampler ("s_base") :texture (tex_base) + shader:sampler ("s_env") :texture (tex_env) : clamp() +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("waterd","waterd") + : sorting (2, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (tex_base) + shader:sampler ("s_distort0") :texture (tex_dist) + shader:sampler ("s_distort1") :texture (tex_dist2) +end + diff --git a/res/gamedata/shaders/glr1/font2.ps b/res/gamedata/shaders/glr1/font2.ps new file mode 100755 index 0000000000000000000000000000000000000000..bdf0def48ba37a6c0e9f28c79b083a3e19a72630 GIT binary patch literal 384 zcmcJKF^_^k5QXcRU-9BKV3ZX?C9%>gOfJEgE9?kzdyxdtEX#=+|N9MS=q%l7=DnGH z`|U?wWkvI&G0Ki*d91v{h`F|=$t>tEIPr}^hqU+&KsKArLEoRdWgKr;vxt)dikv#>KqqTY z{@_LuNXBbr>|+Y)p3Y@(E>Gt=IM;~f&Uw)1PHWqk3g)rg3sPgJr*!;DU#`3`Rxdd2 F{14EiU0?tJ literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/hud3d.ps b/res/gamedata/shaders/glr1/hud3d.ps new file mode 100755 index 0000000000000000000000000000000000000000..acf26d9d453b4adfbbcc675d9fe5454bcf98322c GIT binary patch literal 183 zcmYj~u?mAQ6h-IvzT#mQg(4zOl}_3rP#Uog-6TyT3YtJnN}=@M8#{GA_nxzxw4D7z zQ6$Z>7@dw0;_9rI4*b+Vm36)G4&O*Hih0NhoXh|Y)SYe>=WU&p2*YfID+rnmH2lgs z#xEs)O2q9H$RZ|9G5sltQ4-b_Kl3)|fA)eb9LcFyUPHY0cd@EHOG7XT5v!cHnr!gm E7lAx9?*IS* literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/hud3d.vs b/res/gamedata/shaders/glr1/hud3d.vs new file mode 100755 index 00000000000..f35296c2786 --- /dev/null +++ b/res/gamedata/shaders/glr1/hud3d.vs @@ -0,0 +1,27 @@ +#include "common.h" + + +struct ui_vert_in +{ + float4 P : POSITION; + float4 color : COLOR0; + float2 uv : TEXCOORD0; +}; + +struct ui_vert_out +{ + half2 tc0 : TEXCOORD0; + float4 P : POSITION; +}; + + +ui_vert_out main (ui_vert_in v) +{ + ui_vert_out O; + + O.tc0 = v.uv; + O.P = v.P; + O.P.w = 1; + O.P = mul( m_WVP, O.P ); + return O; +} diff --git a/res/gamedata/shaders/glr1/hud_crosshair.s b/res/gamedata/shaders/glr1/hud_crosshair.s new file mode 100755 index 00000000000..71a2bceac32 --- /dev/null +++ b/res/gamedata/shaders/glr1/hud_crosshair.s @@ -0,0 +1,6 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("null","simple_color") + : fog (false) + : zb (false,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) +end diff --git a/res/gamedata/shaders/glr1/hud_font.ps b/res/gamedata/shaders/glr1/hud_font.ps new file mode 100755 index 0000000000000000000000000000000000000000..68fd5911ebaf44d32fd6cacfb6aec91ac56e9001 GIT binary patch literal 175 zcmYMrI}5@v6b0b<=2u+Wr4q zzUh-Pg0DMAC^Kzk?PM%t7$UL24L-sGLoebID$l`7Mu6~wUY(LPz|e)scoPw@$K_SW z9PV{I3A&hcf-h?HvGCd+dmsqrYA;zHHODcmzz`SR%Yd1E9>zI`||w4 wdVX@b{;mgYGc&m}2_w!797bLBQ9=*{ovQT$8bviNV)#rj3`dyCm?56UFFB>cW&i*H literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/impl.vs b/res/gamedata/shaders/glr1/impl.vs new file mode 100755 index 00000000000..c85368c33a6 --- /dev/null +++ b/res/gamedata/shaders/glr1/impl.vs @@ -0,0 +1,26 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; + float2 tc1 : TEXCOORD1; + float3 c0 : COLOR0; // c0=hemi, c0.a = dt* + float3 c1 : COLOR1; // c1=sun, c1.a = dt+ + float fog : FOG; +}; + +vf main (v_lmap v) +{ + vf o; + + float3 N = unpack_normal (v.N); + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc + o.tc1 = o.tc0; // copy tc + o.c0 = v_hemi (N); // hemi + o.c1 = v_sun (N); // sun + o.fog = calc_fogging (v.P); // fog, input in world coords + + return o; +} diff --git a/res/gamedata/shaders/glr1/impl_dt.ps b/res/gamedata/shaders/glr1/impl_dt.ps new file mode 100755 index 0000000000000000000000000000000000000000..625d7e0b7afc1ce9ea12660234c287f8980d8986 GIT binary patch literal 894 zcmcJNF>k^!5QXRSuQ<^KQV1mN1nLAGkSbAC9lAxvHDJkcP~ucnRsVbM98*H~W=Ui} zzxVuIZj4j5eb+cpRasUpJq(0seBCOK@R1+Imq0j3yUP*0n#~d5_3>@F*}SY~3z$xE zD;wRHWPM2%B({{tz9jEU@*sKFUK%T~%en_j0$6UIHZPRIF$Z0mF{)WAF+mX;kt&-5 z#wUm=kHt;v#)v8-@hyt)g%Hz!d&nA}%}HCql7xV5T4IZaiR;fG?2gq>I5B-kW!%z-J;;S#FFhqu~Si1ynF8))X)d0C+qzE z-RC>)r0L!jj%00Z?UHIFgb!^e1Hxz4h;M;VmF6Qu2y(tcfY;}@O`adN^EJ$7Xl&Ws zLeg7EIzXbx0!RX2lkf8b(V1TjB3l{KfGk;!?tiSd>0hLAz7WS|FG~ zzF>ILo{rQBW23KO!XrIg8ARZ+*k_l>Io@L*Fe!&7QG3+3F2E21=vvk5 zu(9u4jNAJ%pIvz>Yg4zshMa)x_C;xrTDgD^cumb0P6O0Jt4Q4;#&%&Gb5ElQ?S2tI Dr7@;n literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/impl_l.vs b/res/gamedata/shaders/glr1/impl_l.vs new file mode 100755 index 00000000000..74c35e682b4 --- /dev/null +++ b/res/gamedata/shaders/glr1/impl_l.vs @@ -0,0 +1,22 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; + float2 tc1 : TEXCOORD1; + float3 c0 : COLOR0; +}; + +vf main (v_lmap v) +{ + vf o; + + + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc + o.tc1 = o.tc0; // copy tc + o.c0 = v_hemi(unpack_normal(v.N)); // just ambient + + return o; +} diff --git a/res/gamedata/shaders/glr1/impl_point.vs b/res/gamedata/shaders/glr1/impl_point.vs new file mode 100755 index 00000000000..205393593b2 --- /dev/null +++ b/res/gamedata/shaders/glr1/impl_point.vs @@ -0,0 +1,13 @@ +#include "common.h" + +vf_point main (v_lmap v) +{ + vf_point o; + + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc +// o.tc0 = unpack_tc_base(v.tc0); // copy tc + o.color = calc_point (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere + + return o; +} diff --git a/res/gamedata/shaders/glr1/impl_spot.vs b/res/gamedata/shaders/glr1/impl_spot.vs new file mode 100755 index 00000000000..dce5b2706bb --- /dev/null +++ b/res/gamedata/shaders/glr1/impl_spot.vs @@ -0,0 +1,13 @@ +#include "common.h" + +vf_spot main (v_lmap v) +{ + vf_spot o; + + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc +// o.tc0 = unpack_tc_base(v.tc0); // copy tc + o.color = calc_spot (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere + + return o; +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_aa_aa.h b/res/gamedata/shaders/glr1/iostructs/p_aa_aa.h new file mode 100755 index 00000000000..923bf490e37 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_aa_aa.h @@ -0,0 +1,26 @@ + +out vec4 SV_Target; + +layout(location = TEXCOORD0) in float2 p_aa_AA_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 p_aa_AA_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float2 p_aa_AA_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) in float2 p_aa_AA_Tex3 ; // TEXCOORD3; +layout(location = TEXCOORD4) in float2 p_aa_AA_Tex4 ; // TEXCOORD4; +layout(location = TEXCOORD5) in float4 p_aa_AA_Tex5 ; // TEXCOORD5; +layout(location = TEXCOORD6) in float4 p_aa_AA_Tex6 ; // TEXCOORD6; + +float4 _main ( p_aa_AA I ); + +void main() +{ + p_aa_AA I; + I.Tex0 = p_aa_AA_Tex0; + I.Tex1 = p_aa_AA_Tex1; + I.Tex2 = p_aa_AA_Tex2; + I.Tex3 = p_aa_AA_Tex3; + I.Tex4 = p_aa_AA_Tex4; + I.Tex5 = p_aa_AA_Tex5; + I.Tex6 = p_aa_AA_Tex6; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_aa_aa_combine.h b/res/gamedata/shaders/glr1/iostructs/p_aa_aa_combine.h new file mode 100755 index 00000000000..bfa179380b4 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_aa_aa_combine.h @@ -0,0 +1,40 @@ + +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif // GBUFFER_OPTIMIZATION + +layout(location = TEXCOORD0) in float2 p_aa_AA_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 p_aa_AA_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float2 p_aa_AA_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) in float2 p_aa_AA_Tex3 ; // TEXCOORD3; +layout(location = TEXCOORD4) in float2 p_aa_AA_Tex4 ; // TEXCOORD4; +layout(location = TEXCOORD5) in float4 p_aa_AA_Tex5 ; // TEXCOORD5; +layout(location = TEXCOORD6) in float4 p_aa_AA_Tex6 ; // TEXCOORD6; + +#ifdef GBUFFER_OPTIMIZATION +float4 _main ( v_aa_AA I, float4 pos2d ); +#else // GBUFFER_OPTIMIZATION +float4 _main ( v_aa_AA I ); +#endif // GBUFFER_OPTIMIZATION + +void main() +{ + v_aa_AA I; +#ifdef GBUFFER_OPTIMIZATION + I.P = gl_FragCoord; +#endif // GBUFFER_OPTIMIZATION + I.Tex0 = p_aa_AA_Tex0; + I.Tex1 = p_aa_AA_Tex1; + I.Tex2 = p_aa_AA_Tex2; + I.Tex3 = p_aa_AA_Tex3; + I.Tex4 = p_aa_AA_Tex4; + I.Tex5 = p_aa_AA_Tex5; + I.Tex6 = p_aa_AA_Tex6; + +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main ( I, gl_FragCoord ); +#else // GBUFFER_OPTIMIZATION + SV_Target = _main ( I ); +#endif // GBUFFER_OPTIMIZATION +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_aa_aa_sun.h b/res/gamedata/shaders/glr1/iostructs/p_aa_aa_sun.h new file mode 100755 index 00000000000..b03dd7f46f5 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_aa_aa_sun.h @@ -0,0 +1,54 @@ + +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif +#ifdef MSAA_OPTIMIZATION +in int gl_SampleID; +#endif + +layout(location = TEXCOORD0) in float2 p_aa_AA_sun_tc ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 p_aa_AA_sun_unused ; // TEXCOORD1; +layout(location = TEXCOORD2) in float2 p_aa_AA_sun_LT ; // TEXCOORD2; +layout(location = TEXCOORD3) in float2 p_aa_AA_sun_RT ; // TEXCOORD3; +layout(location = TEXCOORD4) in float2 p_aa_AA_sun_LB ; // TEXCOORD4; +layout(location = TEXCOORD5) in float2 p_aa_AA_sun_RB ; // TEXCOORD5; + +#ifdef MSAA_OPTIMIZATION +#ifdef GBUFFER_OPTIMIZATION +float4 _main ( p_aa_AA_sun I, float4 pos2d, uint iSample ); +#else +float4 _main ( p_aa_AA_sun I, uint iSample ); +#endif +#else +#ifdef GBUFFER_OPTIMIZATION +float4 _main ( p_aa_AA_sun I, float4 pos2d ); +#else +float4 _main ( p_aa_AA_sun I ); +#endif +#endif + +void main() +{ + p_aa_AA_sun I; + I.tc = p_aa_AA_sun_tc; + I.unused = p_aa_AA_sun_unused; + I.LT = p_aa_AA_sun_LT; + I.RT = p_aa_AA_sun_RT; + I.LB = p_aa_AA_sun_LB; + I.RB = p_aa_AA_sun_RB; + +#ifdef MSAA_OPTIMIZATION +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main ( I, gl_FragCoord, gl_SampleID ); +#else + SV_Target = _main ( I, gl_SampleID ); +#endif +#else +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main ( I, gl_FragCoord ); +#else + SV_Target = _main ( I ); +#endif +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_accum.h b/res/gamedata/shaders/glr1/iostructs/p_accum.h new file mode 100755 index 00000000000..b6d69d6dee3 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_accum.h @@ -0,0 +1,41 @@ + +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif +#ifdef MSAA_OPTIMIZATION +in int gl_SampleID; +#endif + +layout(location = TEXCOORD0) in float4 p_accum_omni_tc ; // TEXCOORD0; + +#ifdef MSAA_OPTIMIZATION +#ifdef GBUFFER_OPTIMIZATION +float4 _main ( float4 tc, float4 pos2d, uint iSample ); +#else +float4 _main ( float4 tc, uint iSample ); +#endif +#else +#ifdef GBUFFER_OPTIMIZATION +float4 _main ( float4 tc, float4 pos2d ); +#else +float4 _main ( float4 tc ); +#endif +#endif + +void main() +{ +#ifdef MSAA_OPTIMIZATION +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main ( p_accum_omni_tc, gl_FragCoord, gl_SampleID ); +#else + SV_Target = _main ( p_accum_omni_tc, gl_SampleID ); +#endif +#else +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main ( p_accum_omni_tc, gl_FragCoord ); +#else + SV_Target = _main ( p_accum_omni_tc ); +#endif +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_build.h b/res/gamedata/shaders/glr1/iostructs/p_build.h new file mode 100755 index 00000000000..a475d4cdd92 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_build.h @@ -0,0 +1,20 @@ + +out vec4 SV_Target; + +layout(location = TEXCOORD0) in float2 p_build_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 p_build_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float2 p_build_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) in float2 p_build_Tex3 ; // TEXCOORD3; + +float4 _main ( p_build I ); + +void main() +{ + p_build I; + I.Tex0 = p_build_Tex0; + I.Tex1 = p_build_Tex1; + I.Tex2 = p_build_Tex2; + I.Tex3 = p_build_Tex3; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_bumped.h b/res/gamedata/shaders/glr1/iostructs/p_bumped.h new file mode 100755 index 00000000000..870dd42d66d --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_bumped.h @@ -0,0 +1,67 @@ + +out vec4 SV_Target0; +out vec4 SV_Target1; +#ifndef GBUFFER_OPTIMIZATION +out vec4 SV_Target2; +#endif +#ifdef EXTEND_F_DEFFER +out int gl_SampleMask[]; +#endif +#ifdef MSAA_ALPHATEST_DX10_1_ATOC +in vec4 gl_FragCoord; +#endif + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) in float4 p_bumped_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) in float2 p_bumped_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) in float4 p_bumped_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) in float3 p_bumped_M1 ; // TEXCOORD2; // nmap 2 eye - 1 +layout(location = TEXCOORD3) in float3 p_bumped_M2 ; // TEXCOORD3; // nmap 2 eye - 2 +layout(location = TEXCOORD4) in float3 p_bumped_M3 ; // TEXCOORD4; // nmap 2 eye - 3 +#ifdef USE_TDETAIL +layout(location = TEXCOORD5) in float2 p_bumped_tcdbump; // TEXCOORD5; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD6) in float2 p_bumped_lmh ; // TEXCOORD6; // lm-hemi +#endif + +#ifdef MSAA_ALPHATEST_DX10_1_ATOC +f_deffer _main ( p_bumped I, float4 pos2d ); +#else // MSAA_ALPHATEST_DX10_1_ATOC +f_deffer _main ( p_bumped I ); +#endif // MSAA_ALPHATEST_DX10_1_ATOC + +void main() +{ + p_bumped I; + I.tcdh = p_bumped_tcdh; + I.position = p_bumped_position; + I.M1 = p_bumped_M1; + I.M2 = p_bumped_M2; + I.M3 = p_bumped_M3; +#ifdef USE_TDETAIL + I.tcdbump = p_bumped_tcdbump; +#endif +#ifdef USE_LM_HEMI + I.lmh = p_bumped_lmh; +#endif + +#ifdef MSAA_ALPHATEST_DX10_1_ATOC + f_deffer O = _main ( I, gl_FragCoord ); +#else // MSAA_ALPHATEST_DX10_1_ATOC + f_deffer O = _main ( I ); +#endif // MSAA_ALPHATEST_DX10_1_ATOC + + SV_Target0 = O.position; +#ifdef GBUFFER_OPTIMIZATION + SV_Target1 = O.C; +#else + SV_Target1 = O.Ne; + SV_Target2 = O.C; +#endif +#ifdef EXTEND_F_DEFFER + gl_SampleMask[0] = O.mask; +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_bumped_atoc.h b/res/gamedata/shaders/glr1/iostructs/p_bumped_atoc.h new file mode 100755 index 00000000000..707567f510d --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_bumped_atoc.h @@ -0,0 +1,38 @@ + +out vec4 SV_Target; + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) in float4 p_bumped_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) in float2 p_bumped_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) in float4 p_bumped_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) in float3 p_bumped_M1 ; // TEXCOORD2; // nmap 2 eye - 1 +layout(location = TEXCOORD3) in float3 p_bumped_M2 ; // TEXCOORD3; // nmap 2 eye - 2 +layout(location = TEXCOORD4) in float3 p_bumped_M3 ; // TEXCOORD4; // nmap 2 eye - 3 +#ifdef USE_TDETAIL +layout(location = TEXCOORD5) in float2 p_bumped_tcdbump; // TEXCOORD5; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD6) in float2 p_bumped_lmh ; // TEXCOORD6; // lm-hemi +#endif + +float4 _main ( p_bumped I ); + +void main() +{ + p_bumped I; + I.tcdh = p_bumped_tcdh; + I.position = p_bumped_position; + I.M1 = p_bumped_M1; + I.M2 = p_bumped_M2; + I.M3 = p_bumped_M3; +#ifdef USE_TDETAIL + I.tcdbump = p_bumped_tcdbump; +#endif +#ifdef USE_LM_HEMI + I.lmh = p_bumped_lmh; +#endif + + SV_Target = _main ( I ); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_clouds.h b/res/gamedata/shaders/glr1/iostructs/p_clouds.h new file mode 100755 index 00000000000..f1d8346225d --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_clouds.h @@ -0,0 +1,25 @@ + +out vec4 SV_Target; + +struct v2p +{ + float4 color ; // COLOR0; // rgb. intensity, for SM3 - tonemap prescaled + float2 tc0 ; // TEXCOORD0; + float2 tc1 ; // TEXCOORD1; +}; + +layout(location = COLOR0) in float4 p_clouds_color ; // COLOR0; // rgb. intensity, for SM3 - tonemap prescaled +layout(location = TEXCOORD0) in float2 p_clouds_tc0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 p_clouds_tc1 ; // TEXCOORD1; + +float4 _main ( v2p I ); + +void main() +{ + v2p I; + I.color = p_clouds_color; + I.tc0 = p_clouds_tc0; + I.tc1 = p_clouds_tc1; + + SV_Target = _main ( I ); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_combine.h b/res/gamedata/shaders/glr1/iostructs/p_combine.h new file mode 100755 index 00000000000..1a196e5e93d --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_combine.h @@ -0,0 +1,55 @@ + +out vec4 SV_Target0; +out vec4 SV_Target1; +in vec4 gl_FragCoord; + +#ifdef MSAA_OPTIMIZATION +in int gl_SampleID; +#endif + +struct _input +{ +#ifdef USE_VTF + float4 tc0 ; // TEXCOORD0; // tc.xy, tc.w = tonemap scale +#else // USE_VTF + float2 tc0 ; // TEXCOORD0; // tc.xy +#endif // USE_VTF + float2 tcJ ; // TEXCOORD1; // jitter coords + float4 pos2d ; // SV_Position; +}; + +struct _out +{ + float4 low ; // SV_Target0; + float4 high ; // SV_Target1; +}; + +#ifdef USE_VTF +layout(location = TEXCOORD0) in float4 p_combine_tc0 ; // TEXCOORD0; // tc.xy, tc.w = tonemap scale +#else // USE_VTF +layout(location = TEXCOORD0) in float2 p_combine_tc0 ; // TEXCOORD0; // tc.xy +#endif // USE_VTF +layout(location = TEXCOORD1) in float2 p_combine_tcJ ; // TEXCOORD1; // jitter coords + +#ifndef MSAA_OPTIMIZATION +_out _main ( _input I ); +#else +_out _main ( _input I, uint iSample ); +#endif + +void main() +{ + _input I; + I.tc0 = p_combine_tc0; + I.tcJ = p_combine_tcJ; + I.pos2d = gl_FragCoord; + +#ifndef MSAA_OPTIMIZATION + _out O = _main ( I ); +#else + _out O = _main ( I, gl_SampleID ); +#endif + + SV_Target0 = O.low; + SV_Target1 = O.high; +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_dumb.h b/res/gamedata/shaders/glr1/iostructs/p_dumb.h new file mode 100755 index 00000000000..ef0378ee272 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_dumb.h @@ -0,0 +1,9 @@ + +out vec4 SV_Target; + +float4 _main (); + +void main() +{ + SV_Target = _main (); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_filter.h b/res/gamedata/shaders/glr1/iostructs/p_filter.h new file mode 100755 index 00000000000..d053acc1002 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_filter.h @@ -0,0 +1,28 @@ + +out vec4 SV_Target; + +layout(location = TEXCOORD0) in float4 p_filter_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float4 p_filter_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float4 p_filter_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) in float4 p_filter_Tex3 ; // TEXCOORD3; +layout(location = TEXCOORD4) in float4 p_filter_Tex4 ; // TEXCOORD4; +layout(location = TEXCOORD5) in float4 p_filter_Tex5 ; // TEXCOORD5; +layout(location = TEXCOORD6) in float4 p_filter_Tex6 ; // TEXCOORD6; +layout(location = TEXCOORD7) in float4 p_filter_Tex7 ; // TEXCOORD7; + +float4 _main ( p_filter I ); + +void main() +{ + p_filter I; + I.Tex0 = p_filter_Tex0; + I.Tex1 = p_filter_Tex1; + I.Tex2 = p_filter_Tex2; + I.Tex3 = p_filter_Tex3; + I.Tex4 = p_filter_Tex4; + I.Tex5 = p_filter_Tex5; + I.Tex6 = p_filter_Tex6; + I.Tex7 = p_filter_Tex7; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_flat.h b/res/gamedata/shaders/glr1/iostructs/p_flat.h new file mode 100755 index 00000000000..2066d3afd0d --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_flat.h @@ -0,0 +1,63 @@ + +out vec4 SV_Target0; +out vec4 SV_Target1; +#ifndef GBUFFER_OPTIMIZATION +out vec4 SV_Target2; +#endif +#ifdef EXTEND_F_DEFFER +out int gl_SampleMask[]; +#endif +#ifdef MSAA_ALPHATEST_DX10_1_ATOC +in vec4 gl_FragCoord; +#endif + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) in float4 p_flat_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) in float2 p_flat_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) in float4 p_flat_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) in float3 p_flat_N ; // TEXCOORD2; // Eye-space normal (for lighting) +#ifdef USE_TDETAIL +layout(location = TEXCOORD3) in float2 p_flat_tcdbump ; // TEXCOORD3; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD4) in float2 p_flat_lmh ; // TEXCOORD4; // lm-hemi +#endif + +#ifdef MSAA_ALPHATEST_DX10_1_ATOC +f_deffer _main ( p_flat I, float4 pos2d ); +#else // MSAA_ALPHATEST_DX10_1_ATOC +f_deffer _main ( p_flat I ); +#endif // MSAA_ALPHATEST_DX10_1_ATOC + +void main() +{ + p_flat I; + I.tcdh = p_flat_tcdh; + I.position = p_flat_position; + I.N = p_flat_N; +#ifdef USE_TDETAIL + I.tcdbump = p_flat_tcdbump; +#endif +#ifdef USE_LM_HEMI + I.lmh = p_flat_lmh; +#endif + +#ifdef MSAA_ALPHATEST_DX10_1_ATOC + f_deffer O = _main ( I, gl_FragCoord ); +#else // MSAA_ALPHATEST_DX10_1_ATOC + f_deffer O = _main ( I ); +#endif // MSAA_ALPHATEST_DX10_1_ATOC + + SV_Target0 = O.position; +#ifdef GBUFFER_OPTIMIZATION + SV_Target1 = O.C; +#else + SV_Target1 = O.Ne; + SV_Target2 = O.C; +#endif +#ifdef EXTEND_F_DEFFER + gl_SampleMask[0] = O.mask; +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_flat_atoc.h b/res/gamedata/shaders/glr1/iostructs/p_flat_atoc.h new file mode 100755 index 00000000000..4b30a566a5c --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_flat_atoc.h @@ -0,0 +1,34 @@ + +out vec4 SV_Target; + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) in float4 p_flat_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) in float2 p_flat_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) in float4 p_flat_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) in float3 p_flat_N ; // TEXCOORD2; // Eye-space normal (for lighting) +#ifdef USE_TDETAIL +layout(location = TEXCOORD3) in float2 p_flat_tcdbump ; // TEXCOORD3; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD4) in float2 p_flat_lmh ; // TEXCOORD4; // lm-hemi +#endif + +float4 _main ( p_bumped I ); + +void main() +{ + p_flat I; + I.tcdh = p_flat_tcdh; + I.position = p_flat_position; + I.N = p_flat_N; +#ifdef USE_TDETAIL + I.tcdbump = p_flat_tcdbump; +#endif +#ifdef USE_LM_HEMI + I.lmh = p_flat_lmh; +#endif + + SV_Target = _main ( I ); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_lmape.h b/res/gamedata/shaders/glr1/iostructs/p_lmape.h new file mode 100755 index 00000000000..d1f5ca3e9d2 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_lmape.h @@ -0,0 +1,37 @@ + +out vec4 SV_Target; + +struct v2p +{ + float2 tc0 ; // TEXCOORD0; // base + float2 tc1 ; // TEXCOORD1; // lmap + float2 tc2 ; // TEXCOORD2; // hemi + float3 tc3 ; // TEXCOORD3; // env + float3 c0 ; // COLOR0; + float3 c1 ; // COLOR1; + float fog ; // FOG; +}; + +layout(location = TEXCOORD0) in float2 v2p_lmape_tc0 ; // TEXCOORD0; // base +layout(location = TEXCOORD1) in float2 v2p_lmape_tc1 ; // TEXCOORD1; // lmap +layout(location = TEXCOORD2) in float2 v2p_lmape_tc2 ; // TEXCOORD2; // hemi +layout(location = TEXCOORD3) in float3 v2p_lmape_tc3 ; // TEXCOORD3; // env +layout(location = COLOR0) in float3 v2p_lmape_c0 ; // COLOR0; +layout(location = COLOR1) in float3 v2p_lmape_c1 ; // COLOR1; +layout(location = FOG) in float v2p_lmape_fog ; // FOG; + +float4 _main ( v2p I ); + +void main() +{ + v2p I; + I.tc0 = v2p_lmape_tc0; + I.tc1 = v2p_lmape_tc1; + I.tc2 = v2p_lmape_tc2; + I.tc3 = v2p_lmape_tc3; + I.c0 = v2p_lmape_c0; + I.c1 = v2p_lmape_c1; + I.fog = v2p_lmape_fog; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_lod.h b/res/gamedata/shaders/glr1/iostructs/p_lod.h new file mode 100755 index 00000000000..47e2874e24f --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_lod.h @@ -0,0 +1,68 @@ + +out vec4 SV_Target0; +#ifndef ATOC +out vec4 SV_Target1; +#ifndef GBUFFER_OPTIMIZATION +out vec4 SV_Target2; +#endif // GBUFFER_OPTIMIZATION +#ifdef EXTEND_F_DEFFER +out int gl_SampleMask[]; +#endif // EXTEND_F_DEFFER +#ifdef MSAA_ALPHATEST_DX10_1_ATOC +in vec4 gl_FragCoord; +#endif // MSAA_ALPHATEST_DX10_1_ATOC +#endif // #endif + +struct v2p +{ + float3 Pe ; // TEXCOORD0; + float2 tc0 ; // TEXCOORD1; // base0 + float2 tc1 ; // TEXCOORD2; // base1 + float4 af ; // COLOR1; // alpha&factor //skyloader: COLOR1? maybe COLOR0? +}; + +layout(location = TEXCOORD0) in float3 v2p_lod_Pe ; // TEXCOORD0; // base +layout(location = TEXCOORD1) in float2 v2p_lod_tc0 ; // TEXCOORD1; // lmap +layout(location = TEXCOORD2) in float2 v2p_lod_tc1 ; // TEXCOORD2; // hemi +layout(location = COLOR1) in float4 v2p_lod_af ; // COLOR1; + +#ifdef ATOC +float4 _main ( v2p I ); +#else // ATOC +#ifdef MSAA_ALPHATEST_DX10_1_ATOC +f_deffer _main ( v2p I, float4 pos2d ); +#else // MSAA_ALPHATEST_DX10_1_ATOC +f_deffer _main ( v2p I ); +#endif // MSAA_ALPHATEST_DX10_1_ATOC +#endif // ATOC + +void main() +{ + v2p I; + I.Pe = v2p_lod_Pe; + I.tc0 = v2p_lod_tc0; + I.tc1 = v2p_lod_tc1; + I.af = v2p_lod_af; + +#ifdef ATOC + SV_Target = _main (I); +#else // ATOC +#ifdef MSAA_ALPHATEST_DX10_1_ATOC + f_deffer O = _main (I, gl_FragCoord); +#else + f_deffer O = _main (I); +#endif // MSAA_ALPHATEST_DX10_1_ATOC + +#endif // ATOC + + SV_Target0 = O.position; +#ifdef GBUFFER_OPTIMIZATION + SV_Target1 = O.C; +#else + SV_Target1 = O.Ne; + SV_Target2 = O.C; +#endif // GBUFFER_OPTIMIZATION +#ifdef EXTEND_F_DEFFER + gl_SampleMask[0] = O.mask; +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_lplanes.h b/res/gamedata/shaders/glr1/iostructs/p_lplanes.h new file mode 100755 index 00000000000..7bbe4d25d8a --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_lplanes.h @@ -0,0 +1,22 @@ + +out vec4 SV_Target; + +struct v2p +{ + float2 tc0 ; // TEXCOORD0; // base + float4 c0 ; // COLOR0; // sun +}; + +layout(location = TEXCOORD0) in float2 v2p_lplanes_tc0 ; // TEXCOORD0; // base +layout(location = COLOR0) in float4 v2p_lplanes_c0 ; // COLOR0; // sun + +float4 _main ( v2p I ); + +void main() +{ + v2p I; + I.tc0 = v2p_lplanes_tc0; + I.c0 = v2p_lplanes_c0; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_mark_msaa.h b/res/gamedata/shaders/glr1/iostructs/p_mark_msaa.h new file mode 100755 index 00000000000..ea80ad27afc --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_mark_msaa.h @@ -0,0 +1,32 @@ +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif // GBUFFER_OPTIMIZATION + +struct p_TL2uv_msaa +{ + float2 Tex0 ; // TEXCOORD0; + float2 Tex1 ; // TEXCOORD1; + float4 Color ; // COLOR; +#ifdef GBUFFER_OPTIMIZATION + float4 HPos ; // SV_Position; // Clip-space position (for rasterization) +#endif // GBUFFER_OPTIMIZATION +}; + +layout(location = TEXCOORD0) in float2 p_TL0uv_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 p_TL0uv_Tex1 ; // TEXCOORD1; +layout(location = COLOR) in float4 p_TL0uv_Color ; // COLOR; + +float4 _main ( p_TL2uv_msaa I ); + +void main() +{ + p_TL2uv_msaa I; + I.Tex0 = p_TL0uv_Tex0; + I.Tex1 = p_TL0uv_Tex1; + I.Color = p_TL0uv_Color; +#ifdef GBUFFER_OPTIMIZATION + I.HPos = gl_FragCoord; +#endif // GBUFFER_OPTIMIZATION + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_model_def.h b/res/gamedata/shaders/glr1/iostructs/p_model_def.h new file mode 100755 index 00000000000..4aef87a594a --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_model_def.h @@ -0,0 +1,25 @@ + +out vec4 SV_Target; + +struct v2p +{ + float2 tc0; // TEXCOORD0; // base +// float2 tc1; // TEXCOORD1; // lmap + float3 c0; // COLOR0; // sun +}; + +layout(location = TEXCOORD0) in float2 p_model_tc0 ; // TEXCOORD0; // base +//layout(location = TEXCOORD1) in float2 p_model_tc1 ; // TEXCOORD1; // lmap +layout(location = COLOR0) in float3 p_model_c0 ; // COLOR0; // sun + +float4 _main ( v2p I ); + +void main() +{ + v2p I; + I.tc0 = p_model_tc0; +// I.tc1 = p_model_tc1; + I.c0 = p_model_c0; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_model_env_lq.h b/res/gamedata/shaders/glr1/iostructs/p_model_env_lq.h new file mode 100755 index 00000000000..426921c73a0 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_model_env_lq.h @@ -0,0 +1,28 @@ + +out vec4 SV_Target; + +struct v2p +{ + float2 tc0 ; // TEXCOORD0; // base + float3 tc1 ; // TEXCOORD1; // environment + float3 c0 ; // COLOR0; // sun + float fog ; // FOG; +}; + +layout(location = TEXCOORD0) in float2 v2p_model_tc0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float3 v2p_model_tc1 ; // TEXCOORD1; +layout(location = COLOR0) in float3 v2p_model_c0 ; // COLOR0; +layout(location = FOG) in float v2p_model_fog ; // FOG; + +float4 _main ( v2p I ); + +void main() +{ + v2p I; + I.tc0 = v2p_model_tc0; + I.tc1 = v2p_model_tc1; + I.c0 = v2p_model_c0; + I.fog = v2p_model_fog; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_naa_aa_combine.h b/res/gamedata/shaders/glr1/iostructs/p_naa_aa_combine.h new file mode 100755 index 00000000000..236bdb6c674 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_naa_aa_combine.h @@ -0,0 +1,48 @@ + +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif // GBUFFER_OPTIMIZATION +#ifdef USE_MSAA +out float gl_FragDepth; +#endif + +struct c2_out +{ + float4 Color ; // SV_Target; +#ifdef USE_MSAA + float Depth ; // SV_Depth; +#endif +}; + +layout(location = TEXCOORD0) in float2 p_aa_AA_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 p_aa_AA_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float2 p_aa_AA_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) in float2 p_aa_AA_Tex3 ; // TEXCOORD3; +layout(location = TEXCOORD4) in float2 p_aa_AA_Tex4 ; // TEXCOORD4; +layout(location = TEXCOORD5) in float4 p_aa_AA_Tex5 ; // TEXCOORD5; +layout(location = TEXCOORD6) in float4 p_aa_AA_Tex6 ; // TEXCOORD6; + +c2_out _main ( v2p_aa_AA I ); + +void main() +{ + v2p_aa_AA I; +#ifdef GBUFFER_OPTIMIZATION + I.HPos = gl_FragCoord; +#endif // GBUFFER_OPTIMIZATION + I.Tex0 = p_aa_AA_Tex0; + I.Tex1 = p_aa_AA_Tex1; + I.Tex2 = p_aa_AA_Tex2; + I.Tex3 = p_aa_AA_Tex3; + I.Tex4 = p_aa_AA_Tex4; + I.Tex5 = p_aa_AA_Tex5; + I.Tex6 = p_aa_AA_Tex6; + + c2_out O = _main (I); + + SV_Target = O.Color; +#ifdef USE_MSAA + gl_FragDepth = O.Depth; +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_particle.h b/res/gamedata/shaders/glr1/iostructs/p_particle.h new file mode 100755 index 00000000000..673e043ebb5 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_particle.h @@ -0,0 +1,41 @@ + +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif // GBUFFER_OPTIMIZATION + +struct v2p +{ + float2 tc0 ; // TEXCOORD0; + float4 c ; // COLOR0; + +// Igor: for additional depth dest +#ifdef USE_SOFT_PARTICLES + float4 tctexgen ; // TEXCOORD1; +#endif // USE_SOFT_PARTICLES +#ifdef GBUFFER_OPTIMIZATION + float4 hpos ; // SV_Position; +#endif // USE_SOFT_PARTICLES +}; + +layout(location = TEXCOORD0) in float2 p_particle_tc ; // TEXCOORD0; +layout(location = COLOR0) in float4 p_particle_c ; // COLOR0; +#ifdef USE_SOFT_PARTICLES +layout(location = TEXCOORD1) in float4 p_particle_tctexgen; // TEXCOORD1; +#endif // USE_SOFT_PARTICLES + +float4 _main ( v2p I ); + +void main() +{ + v2p I; + I.tc0 = p_particle_tc; + I.c = p_particle_c; +#ifdef USE_SOFT_PARTICLES + I.tctexgen = p_particle_tctexgen; +#endif // USE_SOFT_PARTICLES +#ifdef GBUFFER_OPTIMIZATION + I.hpos = gl_FragCoord; +#endif // GBUFFER_OPTIMIZATION + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_particle_deffer.h b/res/gamedata/shaders/glr1/iostructs/p_particle_deffer.h new file mode 100755 index 00000000000..93d9e0057d2 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_particle_deffer.h @@ -0,0 +1,71 @@ + +out vec4 SV_Target0; +out vec4 SV_Target1; +#ifndef GBUFFER_OPTIMIZATION +out vec4 SV_Target2; +#endif +#ifdef EXTEND_F_DEFFER +out int gl_SampleMask[]; +#endif +#ifdef MSAA_ALPHATEST_DX10_1_ATOC +in vec4 gl_FragCoord; +#endif + +struct p_particle +{ + float4 color ; // COLOR0; + p_flat base; +}; + +layout(location = COLOR0) in float4 p_particle_color; // COLOR0; +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) in float4 p_flat_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) in float2 p_flat_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) in float4 p_flat_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) in float3 p_flat_N ; // TEXCOORD2; // Eye-space normal (for lighting) +#ifdef USE_TDETAIL +layout(location = TEXCOORD3) in float2 p_flat_tcdbump ; // TEXCOORD3; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD4) in float2 p_flat_lmh ; // TEXCOORD4; // lm-hemi +#endif + +#ifdef MSAA_ALPHATEST_DX10_1_ATOC +f_deffer _main ( p_particle II, float4 pos2d ); +#else // MSAA_ALPHATEST_DX10_1_ATOC +f_deffer _main ( p_particle II ); +#endif // MSAA_ALPHATEST_DX10_1_ATOC + +void main() +{ + p_particle I; + I.color = p_particle_color; + I.base.tcdh = p_flat_tcdh; + I.base.position = p_flat_position; + I.base.N = p_flat_N; +#ifdef USE_TDETAIL + I.base.tcdbump = p_flat_tcdbump; +#endif +#ifdef USE_LM_HEMI + I.base.lmh = p_flat_lmh; +#endif + +#ifdef MSAA_ALPHATEST_DX10_1_ATOC + f_deffer O = _main ( I, gl_FragCoord ); +#else // MSAA_ALPHATEST_DX10_1_ATOC + f_deffer O = _main ( I ); +#endif // MSAA_ALPHATEST_DX10_1_ATOC + + SV_Target0 = O.position; +#ifdef GBUFFER_OPTIMIZATION + SV_Target1 = O.C; +#else + SV_Target1 = O.Ne; + SV_Target2 = O.C; +#endif +#ifdef EXTEND_F_DEFFER + gl_SampleMask[0] = O.mask; +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_postpr.h b/res/gamedata/shaders/glr1/iostructs/p_postpr.h new file mode 100755 index 00000000000..318038e350f --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_postpr.h @@ -0,0 +1,31 @@ + +out vec4 SV_Target; +/* +struct v2p +{ + half4 color;//: COLOR0; // multiplier, color.w = noise_amount + half4 gray;//: COLOR1; // (.3,.3,.3.,amount) + half2 tc0;//: TEXCOORD0; // base1 (duality) + half2 tc1;//: TEXCOORD1; // base2 (duality) + half2 tc2;//: TEXCOORD2; // base (noise) +}; +*/ +layout(location = TEXCOORD0) in float2 p_postpr_Tex0 ; // TEXCOORD0; // base1 (duality) +layout(location = TEXCOORD1) in float2 p_postpr_Tex1 ; // TEXCOORD1; // base2 (duality) +layout(location = TEXCOORD2) in float2 p_postpr_Tex2 ; // TEXCOORD2; // base (noise) +layout(location = COLOR0) in float4 p_postpr_Color ; // COLOR0; // multiplier, color.w = noise_amount +layout(location = COLOR1) in float4 p_postpr_Gray ; // COLOR1; // (.3,.3,.3.,amount) + +float4 _main ( p_postpr I ); + +void main() +{ + p_postpr I; + I.Tex0 = p_postpr_Tex0; + I.Tex1 = p_postpr_Tex1; + I.Tex2 = p_postpr_Tex2; + I.Color = p_postpr_Color; + I.Gray = p_postpr_Gray; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_rain_apply.h b/res/gamedata/shaders/glr1/iostructs/p_rain_apply.h new file mode 100755 index 00000000000..0baaf163ebc --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_rain_apply.h @@ -0,0 +1,23 @@ + +out vec4 SV_Target; +#ifdef MSAA_OPTIMIZATION +in int gl_SampleID; +#endif + +layout(location = TEXCOORD0) in float2 p_rain_tc ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 p_rain_tcJ ; // TEXCOORD1; + +#ifdef MSAA_OPTIMIZATION +float4 _main ( float2 tc, float2 tcJ, uint iSample ); +#else +float4 _main ( float2 tc, float2 tcJ ); +#endif + +void main() +{ +#ifdef MSAA_OPTIMIZATION + SV_Target = _main ( p_rain_tc, p_rain_tcJ, gl_SampleID ); +#else + SV_Target = _main ( p_rain_tc, p_rain_tcJ ); +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_rain_layer.h b/res/gamedata/shaders/glr1/iostructs/p_rain_layer.h new file mode 100755 index 00000000000..00356648cb5 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_rain_layer.h @@ -0,0 +1,23 @@ + +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif + +layout(location = TEXCOORD0) in float2 p_rain_tc ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 p_rain_tcJ ; // TEXCOORD1; + +#ifdef GBUFFER_OPTIMIZATION +float4 _main ( float2 tc, float2 tcJ, float4 pos2d ); +#else +float4 _main ( float2 tc, float2 tcJ ); +#endif + +void main() +{ +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main ( p_rain_tc, p_rain_tcJ, gl_FragCoord ); +#else + SV_Target = _main ( p_rain_tc, p_rain_tcJ ); +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_rain_patch.h b/res/gamedata/shaders/glr1/iostructs/p_rain_patch.h new file mode 100755 index 00000000000..91cfd604ce3 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_rain_patch.h @@ -0,0 +1,43 @@ + +out vec4 SV_Target; +#ifdef MSAA_OPTIMIZATION +in int gl_SampleID; +#endif +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif + +layout(location = TEXCOORD0) in float2 p_rain_tc ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 p_rain_tcJ ; // TEXCOORD1; +layout(location = COLOR) in float4 p_rain_Color; // COLOR; + +#ifdef GBUFFER_OPTIMIZATION +#ifdef MSAA_OPTIMIZATION +float4 _main ( float2 tc, float2 tcJ, float4 Color, float4 pos2d, uint iSample ); +#else +float4 _main ( float2 tc, float2 tcJ, float4 Color, float4 pos2d ); +#endif +#else +#ifdef MSAA_OPTIMIZATION +float4 _main ( float2 tc, float2 tcJ, uint iSample ); +#else +float4 _main ( float2 tc, float2 tcJ ); +#endif +#endif + +void main() +{ +#ifdef GBUFFER_OPTIMIZATION +#ifdef MSAA_OPTIMIZATION + SV_Target = _main ( p_rain_tc, p_rain_tcJ, p_rain_Color, gl_FragCoord, gl_SampleID ); +#else + SV_Target = _main ( p_rain_tc, p_rain_tcJ, p_rain_Color, gl_FragCoord ); +#endif +#else +#ifdef MSAA_OPTIMIZATION + SV_Target = _main ( p_rain_tc, p_rain_tcJ, gl_SampleID ); +#else + SV_Target = _main ( p_rain_tc, p_rain_tcJ ); +#endif +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_shadow_aref.h b/res/gamedata/shaders/glr1/iostructs/p_shadow_aref.h new file mode 100755 index 00000000000..c3551edc300 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_shadow_aref.h @@ -0,0 +1,14 @@ + +out vec4 SV_Target; + +layout(location = TEXCOORD1) in float2 p_shadow_tc0 ; // TEXCOORD1; // Diffuse map for aref + +float4 _main ( p_shadow_direct_aref I ); + +void main() +{ + p_shadow_direct_aref I; + I.tc0 = p_shadow_tc0; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_simple.h b/res/gamedata/shaders/glr1/iostructs/p_simple.h new file mode 100755 index 00000000000..aa0b6bbad07 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_simple.h @@ -0,0 +1,19 @@ + +out vec4 SV_Target; + +struct v2p +{ + float2 tc0 ; // TEXCOORD0; // base +}; + +layout(location = TEXCOORD0) in float2 p_simple_tc0 ; // TEXCOORD0; // base + +float4 _main ( v2p I ); + +void main() +{ + v2p I; + I.tc0 = p_simple_tc0; + + SV_Target = _main ( I ); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_simple_color.h b/res/gamedata/shaders/glr1/iostructs/p_simple_color.h new file mode 100755 index 00000000000..45f7325758c --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_simple_color.h @@ -0,0 +1,11 @@ + +out vec4 SV_Target; + +layout(location = COLOR0) in float4 p_simple_C ; // COLOR0; + +float4 _main ( float4 C ); + +void main() +{ + SV_Target = _main ( p_simple_C ); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_sky.h b/res/gamedata/shaders/glr1/iostructs/p_sky.h new file mode 100755 index 00000000000..1c81ea99279 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_sky.h @@ -0,0 +1,35 @@ + +out vec4 SV_Target0; +//out vec4 SV_Target1; + +struct v2p +{ + float4 factor ; // COLOR0; // for SM3 - factor.rgb - tonemap-prescaled + float3 tc0 ; // TEXCOORD0; + float3 tc1 ; // TEXCOORD1; +}; +struct _out +{ + float4 low ; // SV_Target0; + float4 high ; // SV_Target1; +}; + +layout(location = COLOR0) in float4 p_sky_factor; // COLOR0; // for SM3 - factor.rgb - tonemap-prescaled +layout(location = TEXCOORD0) in float3 p_sky_tc0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float3 p_sky_tc1 ; // TEXCOORD1; + +float4 _main( v2p I ); + +void main() +{ + v2p I; + I.factor = p_sky_factor; + I.tc0 = p_sky_tc0; + I.tc1 = p_sky_tc1; + + float4 O = _main (I); + + SV_Target0 = O; + //SV_Target0 = O.low; + //SV_Target1 = O.high; +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_ssao_calc.h b/res/gamedata/shaders/glr1/iostructs/p_ssao_calc.h new file mode 100755 index 00000000000..12dbd2d115f --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_ssao_calc.h @@ -0,0 +1,44 @@ +out vec4 SV_Target; +in vec4 gl_FragCoord; + +#ifdef MSAA_OPTIMIZATION +in int gl_SampleID; +#endif + +struct _input +{ +#ifdef USE_VTF + float4 tc0 ; // TEXCOORD0; // tc.xy, tc.w = tonemap scale +#else // USE_VTF + float2 tc0 ; // TEXCOORD0; // tc.xy +#endif // USE_VTF + float2 tcJ ; // TEXCOORD1; // jitter coords + float4 pos2d ; // SV_Position; +}; + +#ifdef USE_VTF +layout(location = TEXCOORD0) in float4 p_combine_tc0 ; // TEXCOORD0; // tc.xy, tc.w = tonemap scale +#else // USE_VTF +layout(location = TEXCOORD0) in float2 p_combine_tc0 ; // TEXCOORD0; // tc.xy +#endif // USE_VTF +layout(location = TEXCOORD1) in float2 p_combine_tcJ ; // TEXCOORD1; // jitter coords + +#ifndef MSAA_OPTIMIZATION +float4 _main ( _input I ); +#else +float4 _main ( _input I, uint iSample ); +#endif + +void main() +{ + _input I; + I.tc0 = p_combine_tc0; + I.tcJ = p_combine_tcJ; + I.pos2d = gl_FragCoord; + +#ifndef MSAA_OPTIMIZATION + SV_Target = _main ( I ); +#else + SV_Target = _main ( I, gl_SampleID ); +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_tl.h b/res/gamedata/shaders/glr1/iostructs/p_tl.h new file mode 100755 index 00000000000..577aed1327d --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_tl.h @@ -0,0 +1,22 @@ + +out vec4 SV_Target; + +layout(location = TEXCOORD0) in float2 p_TL_Tex0 ; // TEXCOORD0; +layout(location = COLOR) in float4 p_TL_Color ; // COLOR; + +struct p_TL +{ + float2 Tex0 ; // TEXCOORD0; + float4 Color ; // COLOR; +}; + +float4 _main ( p_TL I ); + +void main() +{ + p_TL I; + I.Tex0 = p_TL_Tex0; + I.Color = p_TL_Color; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_tl0uv.h b/res/gamedata/shaders/glr1/iostructs/p_tl0uv.h new file mode 100755 index 00000000000..24646eeffe3 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_tl0uv.h @@ -0,0 +1,14 @@ + +out vec4 SV_Target; + +layout(location = COLOR) in float4 p_TL0uv_Color ; // COLOR; + +float4 _main ( p_TL0uv I ); + +void main() +{ + p_TL0uv I; + I.Color = p_TL0uv_Color; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_tl_sun.h b/res/gamedata/shaders/glr1/iostructs/p_tl_sun.h new file mode 100755 index 00000000000..0522a886d1e --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_tl_sun.h @@ -0,0 +1,46 @@ + +out vec4 SV_Target; +#ifdef MSAA_OPTIMIZATION +in int gl_SampleID; +#endif +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif + +layout(location = TEXCOORD0) in float2 p_TL_Tex0 ; // TEXCOORD0; +layout(location = COLOR) in float4 p_TL_Color ; // COLOR; + +#ifdef MSAA_OPTIMIZATION +#ifdef GBUFFER_OPTIMIZATION +float4 _main ( p_TL I, float4 pos2d, uint iSample ); +#else +float4 _main ( p_TL I, uint iSample ); +#endif +#else +#ifdef GBUFFER_OPTIMIZATION +float4 _main ( p_TL I, float4 pos2d ); +#else +float4 _main ( p_TL I ); +#endif +#endif + +void main() +{ + p_TL I; + I.Tex0 = p_TL_Tex0; + I.Color = p_TL_Color; + +#ifdef MSAA_OPTIMIZATION +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main ( I, gl_FragCoord, gl_SampleID ); +#else + SV_Target = _main ( I, gl_SampleID ); +#endif +#else +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main ( I, gl_FragCoord ); +#else + SV_Target = _main ( I ); +#endif +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_vert.h b/res/gamedata/shaders/glr1/iostructs/p_vert.h new file mode 100755 index 00000000000..05b69f5be46 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_vert.h @@ -0,0 +1,25 @@ + +out vec4 SV_Target; + +struct v2p +{ + float2 Tex0 ; // TEXCOORD0; + float3 c0 ; // COLOR0; // c0=all lighting + float fog ; // FOG; +}; + +layout(location = TEXCOORD0) in float2 v2p_vert_tc ; // TEXCOORD0; +layout(location = COLOR0) in float3 v2p_vert_c ; // COLOR0; // c0=all lighting +layout(location = FOG) in float v2p_vert_fog ; // FOG; + +float4 _main ( v2p I ); + +void main() +{ + v2p I; + I.Tex0 = v2p_vert_tc; + I.c0 = v2p_vert_c; + I.fog = v2p_vert_fog; + + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_volume.h b/res/gamedata/shaders/glr1/iostructs/p_volume.h new file mode 100755 index 00000000000..42619d4a063 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_volume.h @@ -0,0 +1,50 @@ + +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif +#ifdef MSAA_OPTIMIZATION +in int gl_SampleID; +#endif + +layout(location = TEXCOORD0) in float4 p_volume_tc ; // TEXCOORD0; +#ifdef USE_SJITTER +layout(location = TEXCOORD1) in float4 p_volume_tcJ ; // TEXCOORD1; +#endif + +#ifdef MSAA_OPTIMIZATION +#ifdef GBUFFER_OPTIMIZATION +float4 _main( p_volume I, float4 pos2d, uint iSample ); +#else +float4 _main( p_volume I, uint iSample ); +#endif +#else +#ifdef GBUFFER_OPTIMIZATION +float4 _main( p_volume I, float4 pos2d ); +#else +float4 _main( p_volume I ); +#endif +#endif + +void main() +{ + p_volume I; + I.tc = p_volume_tc; +#ifdef USE_SJITTER + I.tcJ = p_volume_tcJ; +#endif + +#ifdef MSAA_OPTIMIZATION +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main( I, gl_FragCoord, gl_SampleID ); +#else + SV_Target = _main( I, gl_SampleID ); +#endif +#else +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main( I, gl_FragCoord ); +#else + SV_Target = _main( I ); +#endif +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_volume_sun.h b/res/gamedata/shaders/glr1/iostructs/p_volume_sun.h new file mode 100755 index 00000000000..cd918c95014 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_volume_sun.h @@ -0,0 +1,37 @@ + +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif // GBUFFER_OPTIMIZATION +#ifdef MSAA_OPTIMIZATION +in int gl_SampleID; +#endif // MSAA_OPTIMIZATION + +layout(location = TEXCOORD0) in float4 p_volume_tc; // TEXCOORD0; +#ifdef USE_SJITTER +layout(location = TEXCOORD1) in float4 p_volume_tcJ; // TEXCOORD1; +#endif // USE_SJITTER + +#ifdef MSAA_OPTIMIZATION +float4 _main ( v2p_volume I, uint iSample ); +#else +float4 _main ( v2p_volume I ); +#endif + +void main() +{ + v2p_volume I; + I.tc = p_volume_tc; +#ifdef USE_SJITTER + I.tcJ = p_volume_tcJ; +#endif // USE_SJITTER +#ifdef GBUFFER_OPTIMIZATION + I.hpos = gl_FragCoord; +#endif // GBUFFER_OPTIMIZATION + +#ifdef MSAA_OPTIMIZATION + SV_Target = _main ( I, gl_SampleID ); +#else + SV_Target = _main ( I ); +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_volumetric.h b/res/gamedata/shaders/glr1/iostructs/p_volumetric.h new file mode 100755 index 00000000000..488e1aea985 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_volumetric.h @@ -0,0 +1,39 @@ + +out vec4 SV_Target; +#ifdef MSAA_OPTIMIZATION +in int gl_SampleID; +#endif + +struct v2p +{ + float3 lightToPos ; // TEXCOORD0; // light center to plane vector + float3 vPos ; // TEXCOORD1; // position in camera space + float fDensity ; // TEXCOORD2; // plane density along Z axis +// float2 tNoise ; // TEXCOORD3; // projective noise +}; + +layout(location = TEXCOORD0) in float3 v2p_lightToPos ; // TEXCOORD0; // light center to plane vector +layout(location = TEXCOORD1) in float3 v2p_vPos ; // TEXCOORD1; // position in camera space +layout(location = TEXCOORD2) in float v2p_fDensity ; // TEXCOORD2; // plane density along Z axis +//layout(location = TEXCOORD3) in float2 v2p_tNoise ; // TEXCOORD3; // projective noise + +#ifdef MSAA_OPTIMIZATION +float4 _main ( v2p I, uint iSample ); +#else +float4 _main ( v2p I ); +#endif + +void main() +{ + v2p I; + I.lightToPos = v2p_lightToPos; + I.vPos = v2p_vPos; + I.fDensity = v2p_fDensity; +// I.tNoise = v2p_tNoise; + +#ifdef MSAA_OPTIMIZATION + SV_Target = _main ( I, gl_SampleID ); +#else + SV_Target = _main ( I ); +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_volumetric_combine.h b/res/gamedata/shaders/glr1/iostructs/p_volumetric_combine.h new file mode 100755 index 00000000000..6652f50c778 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_volumetric_combine.h @@ -0,0 +1,37 @@ + +out vec4 SV_Target0; +out vec4 SV_Target1; + +struct _input +{ +#ifdef USE_VTF + float4 tc0 ; // TEXCOORD0; // tc.xy, tc.w = tonemap scale +#else // USE_VTF + float2 tc0 ; // TEXCOORD0; // tc.xy +#endif // USE_VTF +}; + +struct _out +{ + float4 low ; // SV_Target0; + float4 high ; // SV_Target1; +}; + +#ifdef USE_VTF +layout(location = TEXCOORD0) in float4 p_volumetric_tc0; // TEXCOORD0; // tc.xy, tc.w = tonemap scale +#else // USE_VTF +layout(location = TEXCOORD0) in float2 p_volumetric_tc0; // TEXCOORD0; // tc.xy +#endif // USE_VTF + +_out _main( _input I ); + +void main() +{ + _input I; + I.tc0 = p_volumetric_tc0; + + _out O = _main ( I ); + + SV_Target0 = O.low; + SV_Target1 = O.high; +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_water.h b/res/gamedata/shaders/glr1/iostructs/p_water.h new file mode 100755 index 00000000000..1aaa32e5a59 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_water.h @@ -0,0 +1,72 @@ + +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif + +struct v2p +{ + float2 tbase ; // TEXCOORD0; // base + float2 tnorm0 ; // TEXCOORD1; // nm0 + float2 tnorm1 ; // TEXCOORD2; // nm1 + float3 M1 ; // TEXCOORD3; + float3 M2 ; // TEXCOORD4; + float3 M3 ; // TEXCOORD5; + float3 v2point ; // TEXCOORD6; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + float4 tctexgen; // TEXCOORD7; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +#if SSR_QUALITY > 0 + float4 position_w; // POSITION0; +#endif + float4 c0 ; // COLOR0; + float fog ; // FOG; +}; + +layout(location = TEXCOORD0) in float2 v2p_water_tbase ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 v2p_water_tnorm0 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float2 v2p_water_tnorm1 ; // TEXCOORD2; +layout(location = TEXCOORD3) in float3 v2p_water_M1 ; // TEXCOORD3; +layout(location = TEXCOORD4) in float3 v2p_water_M2 ; // TEXCOORD4; +layout(location = TEXCOORD5) in float3 v2p_water_M3 ; // TEXCOORD5; +layout(location = TEXCOORD6) in float3 v2p_water_v2point ; // TEXCOORD6; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +layout(location = TEXCOORD7) in float4 v2p_water_tctexgen ; // TEXCOORD7; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +#if SSR_QUALITY > 0 +layout(location = POSITION0) in float4 v2p_water_pos ; // POSITION0; +#endif +layout(location = COLOR0) in float4 v2p_water_c0 ; // COLOR0; +layout(location = FOG) in float v2p_water_fog ; // FOG; + +#ifdef GBUFFER_OPTIMIZATION +float4 _main( v2p I, float4 pos2d ); +#else +float4 _main( v2p I ); +#endif + +void main() +{ + v2p I; + + I.tbase = v2p_water_tbase; + I.tnorm0 = v2p_water_tnorm0; + I.tnorm1 = v2p_water_tnorm1; + I.M1 = v2p_water_M1; + I.M2 = v2p_water_M2; + I.M3 = v2p_water_M3; + I.v2point = v2p_water_v2point; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + I.tctexgen = v2p_water_tctexgen; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +#if SSR_QUALITY > 0 + I.position_w = v2p_water_pos; +#endif + I.c0 = v2p_water_c0; + I.fog = v2p_water_fog; +#ifdef GBUFFER_OPTIMIZATION + SV_Target = _main ( I, gl_FragCoord ); +#else + SV_Target = _main ( I ); +#endif +} diff --git a/res/gamedata/shaders/glr1/iostructs/p_waterd.h b/res/gamedata/shaders/glr1/iostructs/p_waterd.h new file mode 100755 index 00000000000..bf042351770 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/p_waterd.h @@ -0,0 +1,42 @@ + +out vec4 SV_Target; +#ifdef GBUFFER_OPTIMIZATION +in vec4 gl_FragCoord; +#endif + +struct v2p +{ + float2 tbase ; // TEXCOORD0; + float2 tdist0 ; // TEXCOORD1; + float2 tdist1 ; // TEXCOORD2; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + float4 tctexgen; // TEXCOORD3; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +#ifdef GBUFFER_OPTIMIZATION + float4 hpos ; // SV_Position; +#endif +}; + +layout(location = TEXCOORD0) in float2 v2p_waterd_tbase ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 v2p_waterd_tdist0 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float2 v2p_waterd_tdist1 ; // TEXCOORD2; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +layout(location = TEXCOORD3) in float4 v2p_waterd_tctexgen ; // TEXCOORD3; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + +float4 _main ( v2p I ); + +void main() +{ + v2p I; + I.tbase = v2p_waterd_tbase; + I.tdist0 = v2p_waterd_tdist0; + I.tdist1 = v2p_waterd_tdist1; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + I.tctexgen = v2p_waterd_tctexgen; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +#ifdef GBUFFER_OPTIMIZATION + I.hpos = gl_FragCoord; +#endif + SV_Target = _main (I); +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_aa_aa.h b/res/gamedata/shaders/glr1/iostructs/v_aa_aa.h new file mode 100755 index 00000000000..2483255d85a --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_aa_aa.h @@ -0,0 +1,45 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITIONT) in float4 v_aa_AA_P ; // POSITIONT; +layout(location = TEXCOORD0) in float2 v_aa_AA_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 v_aa_AA_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float2 v_aa_AA_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) in float2 v_aa_AA_Tex3 ; // TEXCOORD3; +layout(location = TEXCOORD4) in float2 v_aa_AA_Tex4 ; // TEXCOORD4; +layout(location = TEXCOORD5) in float4 v_aa_AA_Tex5 ; // TEXCOORD5; +layout(location = TEXCOORD6) in float4 v_aa_AA_Tex6 ; // TEXCOORD6; + +layout(location = TEXCOORD0) out float2 v2p_aa_AA_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) out float2 v2p_aa_AA_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) out float2 v2p_aa_AA_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) out float2 v2p_aa_AA_Tex3 ; // TEXCOORD3; +layout(location = TEXCOORD4) out float2 v2p_aa_AA_Tex4 ; // TEXCOORD4; +layout(location = TEXCOORD5) out float4 v2p_aa_AA_Tex5 ; // TEXCOORD5; +layout(location = TEXCOORD6) out float4 v2p_aa_AA_Tex6 ; // TEXCOORD6; + +v2p_aa_AA _main ( v_aa_AA I ); + +void main() +{ + v_aa_AA I; + I.P = v_aa_AA_P; + I.Tex0 = v_aa_AA_Tex0; + I.Tex1 = v_aa_AA_Tex1; + I.Tex2 = v_aa_AA_Tex2; + I.Tex3 = v_aa_AA_Tex3; + I.Tex4 = v_aa_AA_Tex4; + I.Tex5 = v_aa_AA_Tex5; + I.Tex6 = v_aa_AA_Tex6; + + v2p_aa_AA O = _main (I); + + v2p_aa_AA_Tex0 = O.Tex0; + v2p_aa_AA_Tex1 = O.Tex1; + v2p_aa_AA_Tex2 = O.Tex2; + v2p_aa_AA_Tex3 = O.Tex3; + v2p_aa_AA_Tex4 = O.Tex4; + v2p_aa_AA_Tex5 = O.Tex5; + v2p_aa_AA_Tex6 = O.Tex6; + gl_Position = O.HPos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_build.h b/res/gamedata/shaders/glr1/iostructs/v_build.h new file mode 100755 index 00000000000..7447bf2e6bf --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_build.h @@ -0,0 +1,33 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITIONT) in float4 v_build_P ; // POSITIONT; +layout(location = TEXCOORD0) in float2 v_build_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 v_build_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float2 v_build_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) in float2 v_build_Tex3 ; // TEXCOORD3; + +layout(location = TEXCOORD0) out float2 v2p_build_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) out float2 v2p_build_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) out float2 v2p_build_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) out float2 v2p_build_Tex3 ; // TEXCOORD3; + +v2p_build _main ( v_build I ); + +void main() +{ + v_build I; + I.P = v_build_P; + I.Tex0 = v_build_Tex0; + I.Tex1 = v_build_Tex1; + I.Tex2 = v_build_Tex2; + I.Tex3 = v_build_Tex3; + + v2p_build O = _main (I); + + v2p_build_Tex0 = O.Tex0; + v2p_build_Tex1 = O.Tex1; + v2p_build_Tex2 = O.Tex2; + v2p_build_Tex3 = O.Tex3; + gl_Position = O.HPos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_clouds.h b/res/gamedata/shaders/glr1/iostructs/v_clouds.h new file mode 100755 index 00000000000..9170158302a --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_clouds.h @@ -0,0 +1,42 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct vi +{ + float4 p ; // POSITION; + float4 dir ; // COLOR0; // dir0,dir1(w<->z) + float4 color ; // COLOR1; // rgb. intensity +}; + +struct vf +{ + float4 color ; // COLOR0; // rgb. intensity, for SM3 - tonemap-prescaled, HI-res + float2 tc0 ; // TEXCOORD0; + float2 tc1 ; // TEXCOORD1; + float4 hpos ; // SV_Position; +}; + +layout(location = POSITION) in float4 v_clouds_p ; // POSITION; +layout(location = COLOR0) in float4 v_clouds_dir ; // COLOR0; // dir0,dir1(w<->z) +layout(location = COLOR1) in float4 v_clouds_color ; // COLOR1; // rgb. intensity + +layout(location = COLOR0) out float4 v2p_clouds_color ; // COLOR0; // rgb. intensity, for SM3 - tonemap-prescaled, HI-res +layout(location = TEXCOORD0) out float2 v2p_clouds_tc0 ; // TEXCOORD0; +layout(location = TEXCOORD1) out float2 v2p_clouds_tc1 ; // TEXCOORD1; + +vf _main (vi v); + +void main() +{ + vi I; + I.p = v_clouds_p; + I.dir = v_clouds_dir; + I.color = v_clouds_color; + + vf O = _main (I); + + v2p_clouds_color = O.color; + v2p_clouds_tc0 = O.tc0; + v2p_clouds_tc1 = O.tc1; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_combine.h b/res/gamedata/shaders/glr1/iostructs/v_combine.h new file mode 100755 index 00000000000..013cad61fb1 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_combine.h @@ -0,0 +1,44 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct _in +{ + float4 P ; // POSITIONT; // xy=pos, zw=tc0 + float2 tcJ ; // TEXCOORD0; // jitter coords +}; + +struct v2p +{ +#ifdef USE_VTF + float4 tc0 ; // TEXCOORD0; // tc.xy, tc.w = tonemap scale +#else // USE_VTF + float2 tc0 ; // TEXCOORD0; // tc.xy +#endif // USE_VTF + float2 tcJ ; // TEXCOORD1; // jitter coords + float4 hpos ; // SV_Position; +}; + +layout(location = POSITIONT) in float4 v_combine_P ; // POSITIONT; // xy=pos, zw=tc0 +layout(location = TEXCOORD0) in float2 v_combine_tcJ ; // TEXCOORD0; // jitter coords + +#ifdef USE_VTF +layout(location = TEXCOORD0) out float4 v2p_combine_tc0 ; // TEXCOORD0; // tc.xy, tc.w = tonemap scale +#else // USE_VTF +layout(location = TEXCOORD0) out float2 v2p_combine_tc0 ; // TEXCOORD0; // tc.xy +#endif // USE_VTF +layout(location = TEXCOORD1) out float2 v2p_combine_tcJ ; // TEXCOORD1; // jitter coords + +v2p _main (_in v); + +void main() +{ + _in I; + I.P = v_combine_P; + I.tcJ = v_combine_tcJ; + + v2p O = _main (I); + + v2p_combine_tc0 = O.tc0; + v2p_combine_tcJ = O.tcJ; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_detail.h b/res/gamedata/shaders/glr1/iostructs/v_detail.h new file mode 100755 index 00000000000..f275389418d --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_detail.h @@ -0,0 +1,41 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_detail_pos ; // POSITION; // (float,float,float,1) +layout(location = TEXCOORD0) in float4 v_detail_misc ; // TEXCOORD0; // (u(Q),v(Q),frac,matrix-id) + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) out float4 v2p_flat_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) out float2 v2p_flat_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) out float4 v2p_flat_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) out float3 v2p_flat_N ; // TEXCOORD2; // Eye-space normal (for lighting) +#ifdef USE_TDETAIL +layout(location = TEXCOORD3) out float2 v2p_flat_tcdbump; // TEXCOORD3; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD4) out float2 v2p_flat_lmh ; // TEXCOORD4; // lm-hemi +#endif + +v2p_flat _main (v_detail v); + +void main() +{ + v_detail I; + I.pos = v_detail_pos; + I.misc = v_detail_misc; + + v2p_flat O = _main (I); + + v2p_flat_tcdh = O.tcdh; + v2p_flat_position = O.position; + v2p_flat_N = O.N; +#ifdef USE_TDETAIL + v2p_flat_tcdbump = O.tcdbump; +#endif +#ifdef USE_LM_HEMI + v2p_flat_lmh = O.lmh; +#endif + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_dumb.h b/res/gamedata/shaders/glr1/iostructs/v_dumb.h new file mode 100755 index 00000000000..fef0b166b95 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_dumb.h @@ -0,0 +1,16 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_dumb_P ; // POSITION; // Clip-space position (for rasterization) + +v2p_dumb _main ( v_dumb I ); + +void main() +{ + v_dumb I; + I.P = v_dumb_P; + + v2p_dumb O = _main (I); + + gl_Position = O.HPos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_editor.h b/res/gamedata/shaders/glr1/iostructs/v_editor.h new file mode 100755 index 00000000000..efb62a40e3c --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_editor.h @@ -0,0 +1,33 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct vf +{ + float4 C ; // COLOR0; + float4 P ; // POSITION; +}; + +struct v2p +{ + float4 C ; // COLOR0; + float4 P ; // SV_Position; +}; + +layout(location = COLOR0) in float4 v_editor_C ; // COLOR0; +layout(location = POSITION) in float4 v_editor_P ; // POSITION; + +layout(location = COLOR0) out float4 v2p_editor_C ; // COLOR0; + +v2p _main (vf i); + +void main() +{ + vf I; + I.C = v_editor_C; + I.P = v_editor_P; + + v2p O = _main (I); + + v2p_editor_C = O.C; + gl_Position = O.P; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_filter.h b/res/gamedata/shaders/glr1/iostructs/v_filter.h new file mode 100755 index 00000000000..c2da1e72afb --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_filter.h @@ -0,0 +1,49 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITIONT) in float4 v_filter_P ; // POSITIONT; +layout(location = TEXCOORD0) in float4 v_filter_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float4 v_filter_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float4 v_filter_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) in float4 v_filter_Tex3 ; // TEXCOORD3; +layout(location = TEXCOORD4) in float4 v_filter_Tex4 ; // TEXCOORD4; +layout(location = TEXCOORD5) in float4 v_filter_Tex5 ; // TEXCOORD5; +layout(location = TEXCOORD6) in float4 v_filter_Tex6 ; // TEXCOORD6; +layout(location = TEXCOORD7) in float4 v_filter_Tex7 ; // TEXCOORD7; + +layout(location = TEXCOORD0) out float4 v2p_filter_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) out float4 v2p_filter_Tex1 ; // TEXCOORD1; +layout(location = TEXCOORD2) out float4 v2p_filter_Tex2 ; // TEXCOORD2; +layout(location = TEXCOORD3) out float4 v2p_filter_Tex3 ; // TEXCOORD3; +layout(location = TEXCOORD4) out float4 v2p_filter_Tex4 ; // TEXCOORD4; +layout(location = TEXCOORD5) out float4 v2p_filter_Tex5 ; // TEXCOORD5; +layout(location = TEXCOORD6) out float4 v2p_filter_Tex6 ; // TEXCOORD6; +layout(location = TEXCOORD7) out float4 v2p_filter_Tex7 ; // TEXCOORD7; + +v2p_filter _main ( v_filter I ); + +void main() +{ + v_filter I; + I.P = v_filter_P; + I.Tex0 = v_filter_Tex0; + I.Tex1 = v_filter_Tex1; + I.Tex2 = v_filter_Tex2; + I.Tex3 = v_filter_Tex3; + I.Tex4 = v_filter_Tex4; + I.Tex5 = v_filter_Tex5; + I.Tex6 = v_filter_Tex6; + I.Tex7 = v_filter_Tex7; + + v2p_filter O = _main (I); + + v2p_filter_Tex0 = O.Tex0; + v2p_filter_Tex1 = O.Tex1; + v2p_filter_Tex2 = O.Tex2; + v2p_filter_Tex3 = O.Tex3; + v2p_filter_Tex4 = O.Tex4; + v2p_filter_Tex5 = O.Tex5; + v2p_filter_Tex6 = O.Tex6; + v2p_filter_Tex7 = O.Tex7; + gl_Position = O.HPos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_lmape.h b/res/gamedata/shaders/glr1/iostructs/v_lmape.h new file mode 100755 index 00000000000..6d8de5ca081 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_lmape.h @@ -0,0 +1,58 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v2p +{ + float4 hpos ; // SV_Position; + float2 tc0 ; // TEXCOORD0; // base + float2 tc1 ; // TEXCOORD1; // lmap + float2 tc2 ; // TEXCOORD2; // hemi + float3 tc3 ; // TEXCOORD3; // env + float3 c0 ; // COLOR0; + float3 c1 ; // COLOR1; + float fog ; // FOG; +}; + +layout(location = POSITION) in float4 v_static_P ; // POSITION; // (float,float,float,1) +layout(location = NORMAL) in float4 v_static_N ; // NORMAL; // (nx,ny,nz,hemi occlusion) +layout(location = TANGENT) in float4 v_static_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float4 v_static_B ; // BINORMAL; // binormal +layout(location = TEXCOORD0) in float2 v_static_tc ; // TEXCOORD0; // (u,v) +#ifdef USE_LM_HEMI +layout(location = TEXCOORD1) in float2 v_static_lmh ; // TEXCOORD1; // (lmu,lmv) +#endif + + +layout(location = TEXCOORD0) out float2 v2p_lmape_tc0 ; // TEXCOORD0; // base +layout(location = TEXCOORD1) out float2 v2p_lmape_tc1 ; // TEXCOORD1; // lmap +layout(location = TEXCOORD2) out float2 v2p_lmape_tc2 ; // TEXCOORD2; // hemi +layout(location = TEXCOORD3) out float3 v2p_lmape_tc3 ; // TEXCOORD3; // env +layout(location = COLOR0) out float3 v2p_lmape_c0 ; // COLOR0; +layout(location = COLOR1) out float3 v2p_lmape_c1 ; // COLOR1; +layout(location = FOG) out float v2p_lmape_fog ; // FOG; + +v2p _main ( v_static I ); + +void main() +{ + v_static I; + I.P = v_static_P; + I.Nh = v_static_N; + I.T = v_static_T; + I.B = v_static_B; + I.tc = v_static_tc; +#ifdef USE_LM_HEMI + I.lmh = v_static_lmh; +#endif + + v2p O = _main (I); + + v2p_lmape_tc0 = O.tc0; + v2p_lmape_tc1 = O.tc1; + v2p_lmape_tc2 = O.tc2; + v2p_lmape_tc3 = O.tc3; + v2p_lmape_c0 = O.c0; + v2p_lmape_c1 = O.c1; + v2p_lmape_fog = O.fog; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_lod.h b/res/gamedata/shaders/glr1/iostructs/v_lod.h new file mode 100755 index 00000000000..146faac4d2c --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_lod.h @@ -0,0 +1,63 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v_lod +{ + float3 pos0 ; // POSITION0; + float3 pos1 ; // POSITION1; + float3 n0 ; // NORMAL0; + float3 n1 ; // NORMAL1; + float2 tc0 ; // TEXCOORD0; + float2 tc1 ; // TEXCOORD1; + float4 rgbh0 ; // TEXCOORD2; // rgb.h + float4 rgbh1 ; // TEXCOORD3; // rgb.h + float4 sun_af ; // COLOR0; // x=sun_0, y=sun_1, z=alpha, w=factor +}; +struct v2p +{ + float4 hpos ; // SV_Position; + float3 Pe ; // TEXCOORD0; + float2 tc0 ; // TEXCOORD1; // base0 + float2 tc1 ; // TEXCOORD2; // base1 + float4 af ; // COLOR1; // alpha&factor //skyloader: COLOR1? maybe COLOR0? +}; + +layout(location = POSITION0) in float3 v_lod_pos0 ; // POSITION0; +layout(location = POSITION1) in float3 v_lod_pos1 ; // POSITION1; +layout(location = NORMAL0) in float3 v_lod_n0 ; // NORMAL0; +layout(location = NORMAL1) in float3 v_lod_n1 ; // NORMAL1; +layout(location = TEXCOORD0) in float2 v_lod_tc0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 v_lod_tc1 ; // TEXCOORD1; +layout(location = TEXCOORD2) in float4 v_lod_rgbh0 ; // TEXCOORD2; // rgb.h +layout(location = TEXCOORD3) in float4 v_lod_rgbh1 ; // TEXCOORD3; // rgb.h +layout(location = COLOR0) in float4 v_lod_sun_af ; // COLOR0; // x=sun_0, y=sun_1, z=alpha, w=factor + + +layout(location = TEXCOORD0) out float3 v2p_lod_Pe ; // TEXCOORD0; // base +layout(location = TEXCOORD1) out float2 v2p_lod_tc0 ; // TEXCOORD1; // lmap +layout(location = TEXCOORD2) out float2 v2p_lod_tc1 ; // TEXCOORD2; // hemi +layout(location = COLOR1) out float4 v2p_lod_af ; // COLOR1; + +v2p _main ( v_lod I ); + +void main() +{ + v_lod I; + I.pos0 = v_lod_pos0; + I.pos1 = v_lod_pos1; + I.n0 = v_lod_n0; + I.n1 = v_lod_n1; + I.tc0 = v_lod_tc0; + I.tc1 = v_lod_tc1; + I.rgbh0 = v_lod_rgbh0; + I.rgbh1 = v_lod_rgbh1; + I.sun_af = v_lod_sun_af; + + v2p O = _main (I); + + v2p_lod_Pe = O.Pe; + v2p_lod_tc0 = O.tc0; + v2p_lod_tc1 = O.tc1; + v2p_lod_af = O.af; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_lplanes.h b/res/gamedata/shaders/glr1/iostructs/v_lplanes.h new file mode 100755 index 00000000000..6234ab37ba2 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_lplanes.h @@ -0,0 +1,43 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v2p +{ + float4 hpos ; // SV_Position; + float2 tc0 ; // TEXCOORD0; // base + float4 c0 ; // COLOR0; // color +}; + +layout(location = POSITION) in float4 v_static_P ; // POSITION; // (float,float,float,1) +layout(location = NORMAL) in float4 v_static_N ; // NORMAL; // (nx,ny,nz,hemi occlusion) +layout(location = TANGENT) in float4 v_static_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float4 v_static_B ; // BINORMAL; // binormal +layout(location = TEXCOORD0) in float2 v_static_tc ; // TEXCOORD0; // (u,v) +#ifdef USE_LM_HEMI +layout(location = TEXCOORD1) in float2 v_static_lmh ; // TEXCOORD1; // (lmu,lmv) +#endif + + +layout(location = TEXCOORD0) out float2 v2p_lplanes_tc0 ; // TEXCOORD0; // base +layout(location = COLOR0) out float4 v2p_lplanes_c0 ; // COLOR0; // color + +v2p _main ( v_static v ); + +void main() +{ + v_static I; + I.P = v_static_P; + I.Nh = v_static_N; + I.T = v_static_T; + I.B = v_static_B; + I.tc = v_static_tc; +#ifdef USE_LM_HEMI + I.lmh = v_static_lmh; +#endif + + v2p O = _main (I); + + v2p_lplanes_tc0 = O.tc0; + v2p_lplanes_c0 = O.c0; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_model_bump.h b/res/gamedata/shaders/glr1/iostructs/v_model_bump.h new file mode 100755 index 00000000000..206d6f0061f --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_model_bump.h @@ -0,0 +1,104 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_model_P ; // POSITION; // (float,float,float,1) +#ifdef SKIN_0 +layout(location = NORMAL) in float3 v_model_N ; // NORMAL; // (nx,ny,nz) +#else +layout(location = NORMAL) in float4 v_model_N ; // NORMAL; // (nx,ny,nz,index) +#endif +#if defined(SKIN_3) || defined(SKIN_4) +layout(location = TANGENT) in float4 v_model_T ; // TANGENT; // (nx,ny,nz,weight0) +layout(location = BINORMAL) in float4 v_model_B ; // BINORMAL; // (nx,ny,nz,weight1) +#else +layout(location = TANGENT) in float3 v_model_T ; // TANGENT; // (nx,ny,nz) +layout(location = BINORMAL) in float3 v_model_B ; // BINORMAL; // (nx,ny,nz) +#endif +#if defined(SKIN_2) || defined(SKIN_3) +layout(location = TEXCOORD0) in float4 v_model_tc ; // TEXCOORD0; // (u,v) +#else +layout(location = TEXCOORD0) in float2 v_model_tc ; // TEXCOORD0; // (u,v) +#endif +#ifdef SKIN_4 +layout(location = TEXCOORD1) in float4 v_model_ind ; // (x=m-index0, y=m-index1, z=m-index2, w=m-index3) +#endif + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) out float4 v2p_bumped_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) out float2 v2p_bumped_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) out float4 v2p_bumped_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) out float3 v2p_bumped_M1 ; // TEXCOORD2; // nmap 2 eye - 1 +layout(location = TEXCOORD3) out float3 v2p_bumped_M2 ; // TEXCOORD3; // nmap 2 eye - 2 +layout(location = TEXCOORD4) out float3 v2p_bumped_M3 ; // TEXCOORD4; // nmap 2 eye - 3 +#ifdef USE_TDETAIL +layout(location = TEXCOORD5) out float2 v2p_bumped_tcdbump; // TEXCOORD5; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD6) out float2 v2p_bumped_lmh ; // TEXCOORD6; // lm-hemi +#endif + +v2p_bumped _main( v_model I ); + +void main() +{ +#ifdef SKIN_NONE + v_model I; +#endif +#ifdef SKIN_0 + v_model_skinned_0 I; +#endif +#ifdef SKIN_1 + v_model_skinned_1 I; +#endif +#ifdef SKIN_2 + v_model_skinned_2 I; +#endif +#ifdef SKIN_3 + v_model_skinned_3 I; +#endif +#ifdef SKIN_4 + v_model_skinned_4 I; + I.ind = v_model_ind; +#endif + + I.P = v_model_P; + I.N = v_model_N; + I.T = v_model_T; + I.B = v_model_B; + I.tc = v_model_tc; + + v2p_bumped O; +#ifdef SKIN_NONE + O = _main(I); +#endif +#ifdef SKIN_0 + O = _main(skinning_0(I)); +#endif +#ifdef SKIN_1 + O = _main(skinning_1(I)); +#endif +#ifdef SKIN_2 + O = _main(skinning_2(I)); +#endif +#ifdef SKIN_3 + O = _main(skinning_3(I)); +#endif +#ifdef SKIN_4 + O = _main(skinning_4(I)); +#endif + + v2p_bumped_tcdh = O.tcdh; + v2p_bumped_position = O.position; + v2p_bumped_M1 = O.M1; + v2p_bumped_M2 = O.M2; + v2p_bumped_M3 = O.M3; +#ifdef USE_TDETAIL + v2p_bumped_tcdbump = O.tcdbump; +#endif +#ifdef USE_LM_HEMI + v2p_bumped_lmh = O.lmh; +#endif + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_model_def.h b/res/gamedata/shaders/glr1/iostructs/v_model_def.h new file mode 100755 index 00000000000..3d1eedd0e07 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_model_def.h @@ -0,0 +1,92 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v2p +{ + float2 tc0 ; // TEXCOORD0; // base + float3 c0 ; // COLOR0; // color + float fog ; // FOG; + float4 hpos ; // SV_Position; +}; + +layout(location = POSITION) in float4 v_model_P ; // POSITION; // (float,float,float,1) +#ifdef SKIN_0 +layout(location = NORMAL) in float3 v_model_N ; // NORMAL; // (nx,ny,nz) +#else +layout(location = NORMAL) in float4 v_model_N ; // NORMAL; // (nx,ny,nz,index) +#endif +#if defined(SKIN_3) || defined(SKIN_4) +layout(location = TANGENT) in float4 v_model_T ; // TANGENT; // (nx,ny,nz,weight0) +layout(location = BINORMAL) in float4 v_model_B ; // BINORMAL; // (nx,ny,nz,weight1) +#else +layout(location = TANGENT) in float3 v_model_T ; // TANGENT; // (nx,ny,nz) +layout(location = BINORMAL) in float3 v_model_B ; // BINORMAL; // (nx,ny,nz) +#endif +#if defined(SKIN_2) || defined(SKIN_3) +layout(location = TEXCOORD0) in float4 v_model_tc ; // TEXCOORD0; // (u,v) +#else +layout(location = TEXCOORD0) in float2 v_model_tc ; // TEXCOORD0; // (u,v) +#endif +#ifdef SKIN_4 +layout(location = TEXCOORD1) in float4 v_model_ind ; // (x=m-index0, y=m-index1, z=m-index2, w=m-index3) +#endif + +layout(location = TEXCOORD0) out float2 v2p_model_tc0 ; // TEXCOORD0; // base +layout(location = COLOR0) out float3 v2p_model_c0 ; // COLOR0; // color +layout(location = FOG) out float v2p_model_fog ; // FOG; + +v2p _main(v_model v); + +void main() +{ +#ifdef SKIN_NONE + v_model I; +#endif +#ifdef SKIN_0 + v_model_skinned_0 I; +#endif +#ifdef SKIN_1 + v_model_skinned_1 I; +#endif +#ifdef SKIN_2 + v_model_skinned_2 I; +#endif +#ifdef SKIN_3 + v_model_skinned_3 I; +#endif +#ifdef SKIN_4 + v_model_skinned_4 I; + I.ind = v_model_ind; +#endif + + I.P = v_model_P; + I.N = v_model_N; + I.T = v_model_T; + I.B = v_model_B; + I.tc = v_model_tc; + + v2p O; +#ifdef SKIN_NONE + O = _main(I); +#endif +#ifdef SKIN_0 + O = _main(skinning_0(I)); +#endif +#ifdef SKIN_1 + O = _main(skinning_1(I)); +#endif +#ifdef SKIN_2 + O = _main(skinning_2(I)); +#endif +#ifdef SKIN_3 + O = _main(skinning_3(I)); +#endif +#ifdef SKIN_4 + O = _main(skinning_4(I)); +#endif + + v2p_model_tc0 = O.tc0; + v2p_model_c0 = O.c0; + v2p_model_fog = O.fog; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_model_def_lplanes.h b/res/gamedata/shaders/glr1/iostructs/v_model_def_lplanes.h new file mode 100755 index 00000000000..f557fee768e --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_model_def_lplanes.h @@ -0,0 +1,90 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v2p +{ + float2 tc0 ; // TEXCOORD0; // base + float3 c0 ; // COLOR0; // color + float4 hpos ; // SV_Position; +}; + +layout(location = POSITION) in float4 v_model_P ; // POSITION; // (float,float,float,1) +#ifdef SKIN_0 +layout(location = NORMAL) in float3 v_model_N ; // NORMAL; // (nx,ny,nz) +#else +layout(location = NORMAL) in float4 v_model_N ; // NORMAL; // (nx,ny,nz,index) +#endif +#if defined(SKIN_3) || defined(SKIN_4) +layout(location = TANGENT) in float4 v_model_T ; // TANGENT; // (nx,ny,nz,weight0) +layout(location = BINORMAL) in float4 v_model_B ; // BINORMAL; // (nx,ny,nz,weight1) +#else +layout(location = TANGENT) in float3 v_model_T ; // TANGENT; // (nx,ny,nz) +layout(location = BINORMAL) in float3 v_model_B ; // BINORMAL; // (nx,ny,nz) +#endif +#if defined(SKIN_2) || defined(SKIN_3) +layout(location = TEXCOORD0) in float4 v_model_tc ; // TEXCOORD0; // (u,v) +#else +layout(location = TEXCOORD0) in float2 v_model_tc ; // TEXCOORD0; // (u,v) +#endif +#ifdef SKIN_4 +layout(location = TEXCOORD1) in float4 v_model_ind ; // (x=m-index0, y=m-index1, z=m-index2, w=m-index3) +#endif + + +layout(location = TEXCOORD0) out float2 v2p_model_tc0 ; // TEXCOORD0; // base +layout(location = COLOR0) out float3 v2p_model_c0 ; // COLOR0; // color + +v2p _main ( v_model v ); + +void main() +{ +#ifdef SKIN_NONE + v_model I; +#endif +#ifdef SKIN_0 + v_model_skinned_0 I; +#endif +#ifdef SKIN_1 + v_model_skinned_1 I; +#endif +#ifdef SKIN_2 + v_model_skinned_2 I; +#endif +#ifdef SKIN_3 + v_model_skinned_3 I; +#endif +#ifdef SKIN_4 + v_model_skinned_4 I; + I.ind = v_model_ind; +#endif + + I.P = v_model_P; + I.N = v_model_N; + I.T = v_model_T; + I.B = v_model_B; + I.tc = v_model_tc; + + v2p O; +#ifdef SKIN_NONE + O = _main(I); +#endif +#ifdef SKIN_0 + O = _main(skinning_0(I)); +#endif +#ifdef SKIN_1 + O = _main(skinning_1(I)); +#endif +#ifdef SKIN_2 + O = _main(skinning_2(I)); +#endif +#ifdef SKIN_3 + O = _main(skinning_3(I)); +#endif +#ifdef SKIN_4 + O = _main(skinning_4(I)); +#endif + + v2p_model_tc0 = O.tc0; + v2p_model_c0 = O.c0; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_model_distort.h b/res/gamedata/shaders/glr1/iostructs/v_model_distort.h new file mode 100755 index 00000000000..05676bd5a65 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_model_distort.h @@ -0,0 +1,89 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct vf +{ + float2 tc0 ; // TEXCOORD0; // base + float4 c0 ; // COLOR0; // color + float4 hpos ; // SV_Position; // position +}; + +layout(location = POSITION) in float4 v_model_P ; // POSITION; // (float,float,float,1) +#ifdef SKIN_0 +layout(location = NORMAL) in float3 v_model_N ; // NORMAL; // (nx,ny,nz) +#else +layout(location = NORMAL) in float4 v_model_N ; // NORMAL; // (nx,ny,nz,index) +#endif +#if defined(SKIN_3) || defined(SKIN_4) +layout(location = TANGENT) in float4 v_model_T ; // TANGENT; // (nx,ny,nz,weight0) +layout(location = BINORMAL) in float4 v_model_B ; // BINORMAL; // (nx,ny,nz,weight1) +#else +layout(location = TANGENT) in float3 v_model_T ; // TANGENT; // (nx,ny,nz) +layout(location = BINORMAL) in float3 v_model_B ; // BINORMAL; // (nx,ny,nz) +#endif +#if defined(SKIN_2) || defined(SKIN_3) +layout(location = TEXCOORD0) in float4 v_model_tc ; // TEXCOORD0; // (u,v) +#else +layout(location = TEXCOORD0) in float2 v_model_tc ; // TEXCOORD0; // (u,v) +#endif +#ifdef SKIN_4 +layout(location = TEXCOORD1) in float4 v_model_ind ; // (x=m-index0, y=m-index1, z=m-index2, w=m-index3) +#endif + +layout(location = TEXCOORD0) out float2 vf_model_tc0 ; // TEXCOORD0; +layout(location = COLOR0) out float4 vf_model_c0 ; // COLOR0; + +vf _main (v_model v); + +void main() +{ +#ifdef SKIN_NONE + v_model I; +#endif +#ifdef SKIN_0 + v_model_skinned_0 I; +#endif +#ifdef SKIN_1 + v_model_skinned_1 I; +#endif +#ifdef SKIN_2 + v_model_skinned_2 I; +#endif +#ifdef SKIN_3 + v_model_skinned_3 I; +#endif +#ifdef SKIN_4 + v_model_skinned_4 I; + I.ind = v_model_ind; +#endif + + I.P = v_model_P; + I.N = v_model_N; + I.T = v_model_T; + I.B = v_model_B; + I.tc = v_model_tc; + + vf O; +#ifdef SKIN_NONE + O = _main(I); +#endif +#ifdef SKIN_0 + O = _main(skinning_0(I)); +#endif +#ifdef SKIN_1 + O = _main(skinning_1(I)); +#endif +#ifdef SKIN_2 + O = _main(skinning_2(I)); +#endif +#ifdef SKIN_3 + O = _main(skinning_3(I)); +#endif +#ifdef SKIN_4 + O = _main(skinning_4(I)); +#endif + + vf_model_tc0 = O.tc0; + vf_model_c0 = O.c0; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_model_env_lq.h b/res/gamedata/shaders/glr1/iostructs/v_model_env_lq.h new file mode 100755 index 00000000000..481d53399bd --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_model_env_lq.h @@ -0,0 +1,96 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v2p +{ + float2 tc0 ; // TEXCOORD0; // base + float3 tc1 ; // TEXCOORD1; // environment + float3 c0 ; // COLOR0; // color + float fog ; // FOG; + float4 hpos ; // SV_Position; +}; + +layout(location = POSITION) in float4 v_model_P ; // POSITION; // (float,float,float,1) +#ifdef SKIN_0 +layout(location = NORMAL) in float3 v_model_N ; // NORMAL; // (nx,ny,nz) +#else +layout(location = NORMAL) in float4 v_model_N ; // NORMAL; // (nx,ny,nz,index) +#endif +#if defined(SKIN_3) || defined(SKIN_4) +layout(location = TANGENT) in float4 v_model_T ; // TANGENT; // (nx,ny,nz,weight0) +layout(location = BINORMAL) in float4 v_model_B ; // BINORMAL; // (nx,ny,nz,weight1) +#else +layout(location = TANGENT) in float3 v_model_T ; // TANGENT; // (nx,ny,nz) +layout(location = BINORMAL) in float3 v_model_B ; // BINORMAL; // (nx,ny,nz) +#endif +#if defined(SKIN_2) || defined(SKIN_3) +layout(location = TEXCOORD0) in float4 v_model_tc ; // TEXCOORD0; // (u,v) +#else +layout(location = TEXCOORD0) in float2 v_model_tc ; // TEXCOORD0; // (u,v) +#endif +#ifdef SKIN_4 +layout(location = TEXCOORD1) in float4 v_model_ind ; // (x=m-index0, y=m-index1, z=m-index2, w=m-index3) +#endif + + +layout(location = TEXCOORD0) out float2 v2p_model_tc0 ; // TEXCOORD0; // base +layout(location = TEXCOORD1) out float3 v2p_model_tc1 ; // TEXCOORD1; // environment +layout(location = COLOR0) out float3 v2p_model_c0 ; // COLOR0; // color +layout(location = FOG) out float v2p_model_fog ; // FOG; + +v2p _main ( v_model v ); + +void main() +{ +#ifdef SKIN_NONE + v_model I; +#endif +#ifdef SKIN_0 + v_model_skinned_0 I; +#endif +#ifdef SKIN_1 + v_model_skinned_1 I; +#endif +#ifdef SKIN_2 + v_model_skinned_2 I; +#endif +#ifdef SKIN_3 + v_model_skinned_3 I; +#endif +#ifdef SKIN_4 + v_model_skinned_4 I; + I.ind = v_model_ind; +#endif + + I.P = v_model_P; + I.N = v_model_N; + I.T = v_model_T; + I.B = v_model_B; + I.tc = v_model_tc; + + v2p O; +#ifdef SKIN_NONE + O = _main(I); +#endif +#ifdef SKIN_0 + O = _main(skinning_0(I)); +#endif +#ifdef SKIN_1 + O = _main(skinning_1(I)); +#endif +#ifdef SKIN_2 + O = _main(skinning_2(I)); +#endif +#ifdef SKIN_3 + O = _main(skinning_3(I)); +#endif +#ifdef SKIN_4 + O = _main(skinning_4(I)); +#endif + + v2p_model_tc0 = O.tc0; + v2p_model_tc1 = O.tc1; + v2p_model_c0 = O.c0; + v2p_model_fog = O.fog; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_model_flat.h b/res/gamedata/shaders/glr1/iostructs/v_model_flat.h new file mode 100755 index 00000000000..70ceedb32d7 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_model_flat.h @@ -0,0 +1,100 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_model_P ; // POSITION; // (float,float,float,1) +#ifdef SKIN_0 +layout(location = NORMAL) in float3 v_model_N ; // NORMAL; // (nx,ny,nz) +#else +layout(location = NORMAL) in float4 v_model_N ; // NORMAL; // (nx,ny,nz,index) +#endif +#if defined(SKIN_3) || defined(SKIN_4) +layout(location = TANGENT) in float4 v_model_T ; // TANGENT; // (nx,ny,nz,weight0) +layout(location = BINORMAL) in float4 v_model_B ; // BINORMAL; // (nx,ny,nz,weight1) +#else +layout(location = TANGENT) in float3 v_model_T ; // TANGENT; // (nx,ny,nz) +layout(location = BINORMAL) in float3 v_model_B ; // BINORMAL; // (nx,ny,nz) +#endif +#if defined(SKIN_2) || defined(SKIN_3) +layout(location = TEXCOORD0) in float4 v_model_tc ; // TEXCOORD0; // (u,v) +#else +layout(location = TEXCOORD0) in float2 v_model_tc ; // TEXCOORD0; // (u,v) +#endif +#ifdef SKIN_4 +layout(location = TEXCOORD1) in float4 v_model_ind ; // (x=m-index0, y=m-index1, z=m-index2, w=m-index3) +#endif + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) out float4 v2p_flat_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) out float2 v2p_flat_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) out float4 v2p_flat_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) out float3 v2p_flat_N ; // TEXCOORD2; // Eye-space normal (for lighting) +#ifdef USE_TDETAIL +layout(location = TEXCOORD3) out float2 v2p_flat_tcdbump; // TEXCOORD3; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD4) out float2 v2p_flat_lmh ; // TEXCOORD4; // lm-hemi +#endif + +v2p_flat _main( v_model I ); + +void main() +{ +#ifdef SKIN_NONE + v_model I; +#endif +#ifdef SKIN_0 + v_model_skinned_0 I; +#endif +#ifdef SKIN_1 + v_model_skinned_1 I; +#endif +#ifdef SKIN_2 + v_model_skinned_2 I; +#endif +#ifdef SKIN_3 + v_model_skinned_3 I; +#endif +#ifdef SKIN_4 + v_model_skinned_4 I; + I.ind = v_model_ind; +#endif + + I.P = v_model_P; + I.N = v_model_N; + I.T = v_model_T; + I.B = v_model_B; + I.tc = v_model_tc; + + v2p_flat O; +#ifdef SKIN_NONE + O = _main(I); +#endif +#ifdef SKIN_0 + O = _main(skinning_0(I)); +#endif +#ifdef SKIN_1 + O = _main(skinning_1(I)); +#endif +#ifdef SKIN_2 + O = _main(skinning_2(I)); +#endif +#ifdef SKIN_3 + O = _main(skinning_3(I)); +#endif +#ifdef SKIN_4 + O = _main(skinning_4(I)); +#endif + + v2p_flat_tcdh = O.tcdh; + v2p_flat_position = O.position; + v2p_flat_N = O.N; +#ifdef USE_TDETAIL + v2p_flat_tcdbump = O.tcdbump; +#endif +#ifdef USE_LM_HEMI + v2p_flat_lmh = O.lmh; +#endif + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_model_shadow.h b/res/gamedata/shaders/glr1/iostructs/v_model_shadow.h new file mode 100755 index 00000000000..50e8f20f7d3 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_model_shadow.h @@ -0,0 +1,77 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_model_P ; // POSITION; // (float,float,float,1) +#ifdef SKIN_0 +layout(location = NORMAL) in float3 v_model_N ; // NORMAL; // (nx,ny,nz) +#else +layout(location = NORMAL) in float4 v_model_N ; // NORMAL; // (nx,ny,nz,index) +#endif +#if defined(SKIN_3) || defined(SKIN_4) +layout(location = TANGENT) in float4 v_model_T ; // TANGENT; // (nx,ny,nz,weight0) +layout(location = BINORMAL) in float4 v_model_B ; // BINORMAL; // (nx,ny,nz,weight1) +#else +layout(location = TANGENT) in float3 v_model_T ; // TANGENT; // (nx,ny,nz) +layout(location = BINORMAL) in float3 v_model_B ; // BINORMAL; // (nx,ny,nz) +#endif +#if defined(SKIN_2) || defined(SKIN_3) +layout(location = TEXCOORD0) in float4 v_model_tc ; // TEXCOORD0; // (u,v) +#else +layout(location = TEXCOORD0) in float2 v_model_tc ; // TEXCOORD0; // (u,v) +#endif +#ifdef SKIN_4 +layout(location = TEXCOORD1) in float4 v_model_ind ; // (x=m-index0, y=m-index1, z=m-index2, w=m-index3) +#endif + +v2p_shadow_direct _main( v_model I ); + +void main() +{ +#ifdef SKIN_NONE + v_model I; +#endif +#ifdef SKIN_0 + v_model_skinned_0 I; +#endif +#ifdef SKIN_1 + v_model_skinned_1 I; +#endif +#ifdef SKIN_2 + v_model_skinned_2 I; +#endif +#ifdef SKIN_3 + v_model_skinned_3 I; +#endif +#ifdef SKIN_4 + v_model_skinned_4 I; + I.ind = v_model_ind; +#endif + + I.P = v_model_P; + I.N = v_model_N; + I.T = v_model_T; + I.B = v_model_B; + I.tc = v_model_tc; + + v2p_shadow_direct O; +#ifdef SKIN_NONE + O = _main(I); +#endif +#ifdef SKIN_0 + O = _main(skinning_0(I)); +#endif +#ifdef SKIN_1 + O = _main(skinning_1(I)); +#endif +#ifdef SKIN_2 + O = _main(skinning_2(I)); +#endif +#ifdef SKIN_3 + O = _main(skinning_3(I)); +#endif +#ifdef SKIN_4 + O = _main(skinning_4(I)); +#endif + + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_model_shadow_aref.h b/res/gamedata/shaders/glr1/iostructs/v_model_shadow_aref.h new file mode 100755 index 00000000000..65cb2e414b8 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_model_shadow_aref.h @@ -0,0 +1,80 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_model_P ; // POSITION; // (float,float,float,1) +#ifdef SKIN_0 +layout(location = NORMAL) in float3 v_model_N ; // NORMAL; // (nx,ny,nz) +#else +layout(location = NORMAL) in float4 v_model_N ; // NORMAL; // (nx,ny,nz,index) +#endif +#if defined(SKIN_3) || defined(SKIN_4) +layout(location = TANGENT) in float4 v_model_T ; // TANGENT; // (nx,ny,nz,weight0) +layout(location = BINORMAL) in float4 v_model_B ; // BINORMAL; // (nx,ny,nz,weight1) +#else +layout(location = TANGENT) in float3 v_model_T ; // TANGENT; // (nx,ny,nz) +layout(location = BINORMAL) in float3 v_model_B ; // BINORMAL; // (nx,ny,nz) +#endif +#if defined(SKIN_2) || defined(SKIN_3) +layout(location = TEXCOORD0) in float4 v_model_tc ; // TEXCOORD0; // (u,v) +#else +layout(location = TEXCOORD0) in float2 v_model_tc ; // TEXCOORD0; // (u,v) +#endif +#ifdef SKIN_4 +layout(location = TEXCOORD1) in float4 v_model_ind ; // (x=m-index0, y=m-index1, z=m-index2, w=m-index3) +#endif + +layout(location = TEXCOORD1) out float2 v2p_shadow_tc0 ; // TEXCOORD1; // Diffuse map for aref + +v2p_shadow_direct_aref _main( v_model I ); + +void main() +{ +#ifdef SKIN_NONE + v_model I; +#endif +#ifdef SKIN_0 + v_model_skinned_0 I; +#endif +#ifdef SKIN_1 + v_model_skinned_1 I; +#endif +#ifdef SKIN_2 + v_model_skinned_2 I; +#endif +#ifdef SKIN_3 + v_model_skinned_3 I; +#endif +#ifdef SKIN_4 + v_model_skinned_4 I; + I.ind = v_model_ind; +#endif + + I.P = v_model_P; + I.N = v_model_N; + I.T = v_model_T; + I.B = v_model_B; + I.tc = v_model_tc; + + v2p_shadow_direct_aref O; +#ifdef SKIN_NONE + O = _main(I); +#endif +#ifdef SKIN_0 + O = _main(skinning_0(I)); +#endif +#ifdef SKIN_1 + O = _main(skinning_1(I)); +#endif +#ifdef SKIN_2 + O = _main(skinning_2(I)); +#endif +#ifdef SKIN_3 + O = _main(skinning_3(I)); +#endif +#ifdef SKIN_4 + O = _main(skinning_4(I)); +#endif + + v2p_shadow_tc0 = O.tc0; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_particle.h b/res/gamedata/shaders/glr1/iostructs/v_particle.h new file mode 100755 index 00000000000..45f47466609 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_particle.h @@ -0,0 +1,59 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct vv +{ + float4 P ; // POSITION; + float2 tc ; // TEXCOORD0; + float4 c ; // COLOR0; +}; + +struct v2p +{ + float2 tc ; // TEXCOORD0; + float4 c ; // COLOR0; + +// Igor: for additional depth dest +#ifdef USE_SOFT_PARTICLES + float4 tctexgen ; // TEXCOORD1; +#endif // USE_SOFT_PARTICLES + + float4 hpos ; // SV_Position; +}; + +struct vf +{ + float4 hpos; // : POSITION; + float2 tc; // : TEXCOORD0; + float4 c; // : COLOR0; + float fog; // : FOG; +}; + +layout(location = POSITION) in float4 v_particle_P ; // POSITION; +layout(location = TEXCOORD0) in float2 v_particle_tc ; // TEXCOORD0; +layout(location = COLOR) in float4 v_particle_c ; // COLOR; + +layout(location = TEXCOORD0) out float2 v2p_particle_tc ; // TEXCOORD0; +layout(location = COLOR0) out float4 v2p_particle_c ; // COLOR0; +#ifdef USE_SOFT_PARTICLES +layout(location = TEXCOORD1) out float4 v2p_particle_tctexgen; // TEXCOORD1; +#endif // USE_SOFT_PARTICLES + +vf _main ( vv I ); + +void main() +{ + vv I; + I.P = v_particle_P; + I.tc = v_particle_tc; + I.c = v_particle_c; + + vf O = _main (I); + + v2p_particle_tc = O.tc; + v2p_particle_c = O.c; +#ifdef USE_SOFT_PARTICLES + v2p_particle_tctexgen = O.tctexgen; +#endif + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_particle_flat.h b/res/gamedata/shaders/glr1/iostructs/v_particle_flat.h new file mode 100755 index 00000000000..89f5aac367a --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_particle_flat.h @@ -0,0 +1,58 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct vv +{ + float4 P ; // POSITION; + float2 tc ; // TEXCOORD0; + float4 c ; // COLOR0; +}; + +struct v2p_particle +{ + float4 color ; // COLOR0; + v2p_flat base; +}; + +layout(location = POSITION) in float4 v_particle_P ; // POSITION; +layout(location = TEXCOORD0) in float2 v_particle_tc ; // TEXCOORD0; +layout(location = COLOR) in float4 v_particle_c ; // COLOR; + +layout(location = COLOR0) out float4 v2p_particle_color; // COLOR0; +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) out float4 v2p_flat_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) out float2 v2p_flat_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) out float4 v2p_flat_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) out float3 v2p_flat_N ; // TEXCOORD2; // Eye-space normal (for lighting) +#ifdef USE_TDETAIL +layout(location = TEXCOORD3) out float2 v2p_flat_tcdbump; // TEXCOORD3; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD4) out float2 v2p_flat_lmh ; // TEXCOORD4; // lm-hemi +#endif + +v2p_particle _main ( vv I ); + +void main() +{ + vv I; + I.P = v_particle_P; + I.tc = v_particle_tc; + I.c = v_particle_c; + + v2p_particle O = _main (I); + + v2p_particle_color = O.color; + v2p_flat_tcdh = O.base.tcdh; + v2p_flat_position = O.base.position; + v2p_flat_N = O.base.N; +#ifdef USE_TDETAIL + v2p_flat_tcdbump = O.base.tcdbump; +#endif +#ifdef USE_LM_HEMI + v2p_flat_lmh = O.base.lmh; +#endif + gl_Position = O.base.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_portal.h b/res/gamedata/shaders/glr1/iostructs/v_portal.h new file mode 100755 index 00000000000..63985576bec --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_portal.h @@ -0,0 +1,36 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v_vert +{ + float4 pos ; // POSITION; // (float,float,float,1) + float4 color ; // COLOR0; // (r,g,b,dir-occlusion) +}; + +struct v2p +{ + float4 c ; // COLOR0; + float fog ; // FOG; + float4 hpos ; // SV_Position; +}; + +layout(location = POSITION) in float4 v_portal_pos ; // POSITION; // (float,float,float,1) +layout(location = COLOR0) in float4 v_portal_color ; // COLOR0; // (r,g,b,dir-occlusion) + +layout(location = COLOR0) out float4 v2p_portal_c ; // COLOR0; +layout(location = FOG) out float v2p_portal_fog ; // FOG; + +v2p _main ( v_vert I ); + +void main() +{ + v_vert I; + I.pos = v_portal_pos; + I.color = v_portal_color; + + v2p O = _main (I); + + v2p_portal_c = O.c; + v2p_portal_fog = O.fog; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_postpr.h b/res/gamedata/shaders/glr1/iostructs/v_postpr.h new file mode 100755 index 00000000000..9287e928c67 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_postpr.h @@ -0,0 +1,37 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITIONT) in float4 v_postpr_P ; // POSITIONT; +layout(location = TEXCOORD0) in float2 v_postpr_Tex0 ; // TEXCOORD0; // base1 (duality) +layout(location = TEXCOORD1) in float2 v_postpr_Tex1 ; // TEXCOORD1; // base2 (duality) +layout(location = TEXCOORD2) in float2 v_postpr_Tex2 ; // TEXCOORD2; // base (noise) +layout(location = COLOR0) in float4 v_postpr_Color ; // COLOR0; // multiplier, color.w = noise_amount +layout(location = COLOR1) in float4 v_postpr_Gray ; // COLOR1; // (.3,.3,.3.,amount) + +layout(location = TEXCOORD0) out float2 v2p_postpr_Tex0 ; // TEXCOORD0; // base1 (duality) +layout(location = TEXCOORD1) out float2 v2p_postpr_Tex1 ; // TEXCOORD1; // base2 (duality) +layout(location = TEXCOORD2) out float2 v2p_postpr_Tex2 ; // TEXCOORD2; // base (noise) +layout(location = COLOR0) out float4 v2p_postpr_Color; // COLOR0; // multiplier, color.w = noise_amount +layout(location = COLOR1) out float4 v2p_postpr_Gray ; // COLOR1; // (.3,.3,.3.,amount) + +v2p_postpr _main ( v_postpr I ); + +void main() +{ + v_postpr I; + I.P = v_postpr_P; + I.Tex0 = v_postpr_Tex0; + I.Tex1 = v_postpr_Tex1; + I.Tex2 = v_postpr_Tex2; + I.Color = v_postpr_Color; + I.Gray = v_postpr_Gray; + + v2p_postpr O = _main (I); + + v2p_postpr_Tex0 = O.Tex0; + v2p_postpr_Tex1 = O.Tex1; + v2p_postpr_Tex2 = O.Tex2; + v2p_postpr_Color = O.Color; + v2p_postpr_Gray = O.Gray; + gl_Position = O.HPos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_shadow.h b/res/gamedata/shaders/glr1/iostructs/v_shadow.h new file mode 100755 index 00000000000..9574bd5b5a3 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_shadow.h @@ -0,0 +1,22 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct a2v +{ +// float4 tc0; // TEXCOORD0; // Texture coordinates + float4 P; // POSITION; // Object-space position +}; + +layout(location = POSITION) in float4 v_shadow_P ; // POSITION; // Object-space position + +v2p_shadow_direct _main ( a2v I ); + +void main() +{ + a2v I; + I.P = v_shadow_P; + + v2p_shadow_direct O = _main (I); + + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_shadow_aref.h b/res/gamedata/shaders/glr1/iostructs/v_shadow_aref.h new file mode 100755 index 00000000000..ba5d780d1ed --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_shadow_aref.h @@ -0,0 +1,39 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct a2v +{ + float4 P ; // POSITION; // Object-space position + float2 tc0 ; // TEXCOORD0; // Texture coordinates +}; + +layout(location = NORMAL) in float4 v_static_Nh ; // NORMAL; // (nx,ny,nz,hemi occlusion) +layout(location = TANGENT) in float4 v_static_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float4 v_static_B ; // BINORMAL; // binormal +layout(location = TEXCOORD0) in float2 v_static_tc ; // TEXCOORD0; // (u,v) +#ifdef USE_LM_HEMI +layout(location = TEXCOORD1) in float2 v_static_lmh ; // TEXCOORD1; // (lmu,lmv) +#endif +layout(location = POSITION) in float4 v_static_P ; // POSITION; // (float,float,float,1) + +layout(location = TEXCOORD1) out float2 v2p_shadow_tc0 ; // TEXCOORD1; // Diffuse map for aref + +v2p_shadow_direct_aref _main ( v_static I ); + +void main() +{ + v_static I; + I.Nh = v_static_Nh; + I.T = v_static_T; + I.B = v_static_B; + I.tc = v_static_tc; +#ifdef USE_LM_HEMI + I.lmh = v_static_lmh; +#endif + I.P = v_static_P; + + v2p_shadow_direct_aref O = _main (I); + + v2p_shadow_tc0 = O.tc0; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_sky.h b/res/gamedata/shaders/glr1/iostructs/v_sky.h new file mode 100755 index 00000000000..f93e5636915 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_sky.h @@ -0,0 +1,44 @@ +out gl_PerVertex { vec4 gl_Position; }; + +struct vi +{ + float4 p ; // POSITION; + float4 c ; // COLOR0; + float3 tc0 ; // TEXCOORD0; + float3 tc1 ; // TEXCOORD1; +}; + +struct v2p +{ + float4 c ; // COLOR0; + float3 tc0 ; // TEXCOORD0; + float3 tc1 ; // TEXCOORD1; + float4 hpos ; // SV_Position; +}; + +layout(location = POSITION) in float4 v_sky_p ; // POSITION; +layout(location = COLOR0) in float4 v_sky_c ; // COLOR0; +layout(location = TEXCOORD0) in float3 v_sky_tc0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float3 v_sky_tc1 ; // TEXCOORD1; + +layout(location = COLOR0) out float4 v2p_sky_c ; // COLOR0; +layout(location = TEXCOORD0) out float3 v2p_sky_tc0 ; // TEXCOORD0; +layout(location = TEXCOORD1) out float3 v2p_sky_tc1 ; // TEXCOORD1; + +v2p _main (vi v); + +void main() +{ + vi I; + I.p = v_sky_p; + I.c = v_sky_c; + I.tc0 = v_sky_tc0; + I.tc1 = v_sky_tc1; + + v2p O = _main (I); + + v2p_sky_c = O.c; + v2p_sky_tc0 = O.tc0; + v2p_sky_tc1 = O.tc1; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_static_bump.h b/res/gamedata/shaders/glr1/iostructs/v_static_bump.h new file mode 100755 index 00000000000..6420c5b50f0 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_static_bump.h @@ -0,0 +1,69 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +#define v_in v_static_color +#else +#define v_in v_static +#endif + +layout(location = NORMAL) in float4 v_static_Nh ; // NORMAL; // (nx,ny,nz,hemi occlusion) +layout(location = TANGENT) in float4 v_static_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float4 v_static_B ; // BINORMAL; // binormal +layout(location = TEXCOORD0) in float2 v_static_tc ; // TEXCOORD0; // (u,v) +#ifdef USE_LM_HEMI +layout(location = TEXCOORD1) in float2 v_static_lmh ; // TEXCOORD1; // (lmu,lmv) +#endif +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = COLOR0) in float4 v_static_C ; // COLOR0; // (r,g,b,dir-occlusion) // Swizzle before use!!! +#endif +layout(location = POSITION) in float4 v_static_P ; // POSITION; // (float,float,float,1) + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) out float4 v2p_bumped_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) out float2 v2p_bumped_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) out float4 v2p_bumped_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) out float3 v2p_bumped_M1 ; // TEXCOORD2; // nmap 2 eye - 1 +layout(location = TEXCOORD3) out float3 v2p_bumped_M2 ; // TEXCOORD3; // nmap 2 eye - 2 +layout(location = TEXCOORD4) out float3 v2p_bumped_M3 ; // TEXCOORD4; // nmap 2 eye - 3 +#ifdef USE_TDETAIL +layout(location = TEXCOORD5) out float2 v2p_bumped_tcdbump; // TEXCOORD5; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD6) out float2 v2p_bumped_lmh ; // TEXCOORD6; // lm-hemi +#endif + +v2p_bumped _main( v_in I ); + +void main() +{ + v_in I; + I.Nh = v_static_Nh; + I.T = v_static_T; + I.B = v_static_B; + I.tc = v_static_tc; +#ifdef USE_LM_HEMI + I.lmh = v_static_lmh; +#endif +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) + I.color = v_static_C; +#endif + I.P = v_static_P; + + v2p_bumped O = _main (I); + + v2p_bumped_tcdh = O.tcdh; + v2p_bumped_position = O.position; + v2p_bumped_M1 = O.M1; + v2p_bumped_M2 = O.M2; + v2p_bumped_M3 = O.M3; +#ifdef USE_TDETAIL + v2p_bumped_tcdbump = O.tcdbump; +#endif +#ifdef USE_LM_HEMI + v2p_bumped_lmh = O.lmh; +#endif + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_static_flat.h b/res/gamedata/shaders/glr1/iostructs/v_static_flat.h new file mode 100755 index 00000000000..16246dca0b6 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_static_flat.h @@ -0,0 +1,65 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +#define v_in v_static_color +#else +#define v_in v_static +#endif + +layout(location = NORMAL) in float4 v_static_Nh ; // NORMAL; // (nx,ny,nz,hemi occlusion) +layout(location = TANGENT) in float4 v_static_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float4 v_static_B ; // BINORMAL; // binormal +layout(location = TEXCOORD0) in float2 v_static_tc ; // TEXCOORD0; // (u,v) +#ifdef USE_LM_HEMI +layout(location = TEXCOORD1) in float2 v_static_lmh ; // TEXCOORD1; // (lmu,lmv) +#endif +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = COLOR0) in float4 v_static_C ; // COLOR0; // (r,g,b,dir-occlusion) // Swizzle before use!!! +#endif +layout(location = POSITION) in float4 v_static_P ; // POSITION; // (float,float,float,1) + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) out float4 v2p_flat_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) out float2 v2p_flat_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) out float4 v2p_flat_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) out float3 v2p_flat_N ; // TEXCOORD2; // Eye-space normal (for lighting) +#ifdef USE_TDETAIL +layout(location = TEXCOORD3) out float2 v2p_flat_tcdbump; // TEXCOORD3; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD4) out float2 v2p_flat_lmh ; // TEXCOORD4; // lm-hemi +#endif + +v2p_flat _main( v_in I ); + +void main() +{ + v_in I; + I.Nh = v_static_Nh; + I.T = v_static_T; + I.B = v_static_B; + I.tc = v_static_tc; +#ifdef USE_LM_HEMI + I.lmh = v_static_lmh; +#endif +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) + I.color = v_static_C; +#endif + I.P = v_static_P; + + v2p_flat O = _main (I); + + v2p_flat_tcdh = O.tcdh; + v2p_flat_position = O.position; + v2p_flat_N = O.N; +#ifdef USE_TDETAIL + v2p_flat_tcdbump = O.tcdbump; +#endif +#ifdef USE_LM_HEMI + v2p_flat_lmh = O.lmh; +#endif + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_tl.h b/res/gamedata/shaders/glr1/iostructs/v_tl.h new file mode 100755 index 00000000000..d689420b6aa --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_tl.h @@ -0,0 +1,25 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_TL_P ; // POSITION; +layout(location = TEXCOORD0) in float2 v_TL_Tex0 ; // TEXCOORD0; +layout(location = COLOR) in float4 v_TL_Color ; // COLOR; + +layout(location = TEXCOORD0) out float2 v2p_TL_Tex0 ; // TEXCOORD0; +layout(location = COLOR) out float4 v2p_TL_Color; // COLOR; + +v2p_TL _main ( v_TL I ); + +void main() +{ + v_TL I; + I.P = v_TL_P; + I.Tex0 = v_TL_Tex0; + I.Color = v_TL_Color; + + v2p_TL O = _main (I); + + v2p_TL_Tex0 = O.Tex0; + v2p_TL_Color = O.Color; + gl_Position = O.HPos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_tl0uv.h b/res/gamedata/shaders/glr1/iostructs/v_tl0uv.h new file mode 100755 index 00000000000..e165c51a7c3 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_tl0uv.h @@ -0,0 +1,21 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_TL0uv_P ; // POSITION; +layout(location = COLOR) in float4 v_TL0uv_Color ; // COLOR; + +layout(location = COLOR) out float4 v2p_TL0uv_Color ; // COLOR; + +v2p_TL0uv _main ( v_TL0uv I ); + +void main() +{ + v_TL0uv I; + I.P = v_TL0uv_P; + I.Color = v_TL0uv_Color; + + v2p_TL0uv O = _main (I); + + v2p_TL0uv_Color = O.Color; + gl_Position = O.HPos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_tl2uv.h b/res/gamedata/shaders/glr1/iostructs/v_tl2uv.h new file mode 100755 index 00000000000..97bd7529974 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_tl2uv.h @@ -0,0 +1,29 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITIONT) in float4 v_TL2uv_P ; // POSITIONT; +layout(location = TEXCOORD0) in float2 v_TL2uv_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) in float2 v_TL2uv_Tex1 ; // TEXCOORD1; +layout(location = COLOR) in float4 v_TL2uv_Color ; // COLOR; + +layout(location = TEXCOORD0) out float2 v2p_TL2uv_Tex0 ; // TEXCOORD0; +layout(location = TEXCOORD1) out float2 v2p_TL2uv_Tex1 ; // TEXCOORD1; +layout(location = COLOR) out float4 v2p_TL2uv_Color ; // COLOR; + +v2p_TL2uv _main ( v_TL2uv I ); + +void main() +{ + v_TL2uv I; + I.P = v_TL2uv_P; + I.Tex0 = v_TL2uv_Tex0; + I.Tex1 = v_TL2uv_Tex1; + I.Color = v_TL2uv_Color; + + v2p_TL2uv O = _main (I); + + v2p_TL2uv_Tex0 = O.Tex0; + v2p_TL2uv_Tex1 = O.Tex1; + v2p_TL2uv_Color = O.Color; + gl_Position = O.HPos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_tree_bump.h b/res/gamedata/shaders/glr1/iostructs/v_tree_bump.h new file mode 100755 index 00000000000..95161715a29 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_tree_bump.h @@ -0,0 +1,51 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_tree_P ; // POSITION; // (float,float,float,1) +layout(location = NORMAL) in float4 v_tree_Nh ; // NORMAL; // (nx,ny,nz) +layout(location = TANGENT) in float3 v_tree_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float3 v_tree_B ; // BINORMAL; // binormal +layout(location = TEXCOORD0) in float4 v_tree_tc ; // TEXCOORD0; // (u,v,frac,???) + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) out float4 v2p_bumped_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) out float2 v2p_bumped_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) out float4 v2p_bumped_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) out float3 v2p_bumped_M1 ; // TEXCOORD2; // nmap 2 eye - 1 +layout(location = TEXCOORD3) out float3 v2p_bumped_M2 ; // TEXCOORD3; // nmap 2 eye - 2 +layout(location = TEXCOORD4) out float3 v2p_bumped_M3 ; // TEXCOORD4; // nmap 2 eye - 3 +#ifdef USE_TDETAIL +layout(location = TEXCOORD5) out float2 v2p_bumped_tcdbump; // TEXCOORD5; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD6) out float2 v2p_bumped_lmh ; // TEXCOORD6; // lm-hemi +#endif + +v2p_bumped _main (v_tree I); + +void main() +{ + v_tree I; + I.P = v_tree_P; + I.Nh = v_tree_Nh; + I.T = v_tree_T; + I.B = v_tree_B; + I.tc = v_tree_tc; + + v2p_bumped O = _main (I); + + v2p_bumped_tcdh = O.tcdh; + v2p_bumped_position = O.position; + v2p_bumped_M1 = O.M1; + v2p_bumped_M2 = O.M2; + v2p_bumped_M3 = O.M3; +#ifdef USE_TDETAIL + v2p_bumped_tcdbump = O.tcdbump; +#endif +#ifdef USE_LM_HEMI + v2p_bumped_lmh = O.lmh; +#endif + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_tree_flat.h b/res/gamedata/shaders/glr1/iostructs/v_tree_flat.h new file mode 100755 index 00000000000..fdff4d1b895 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_tree_flat.h @@ -0,0 +1,47 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_tree_P ; // POSITION; // (float,float,float,1) +layout(location = NORMAL) in float4 v_tree_Nh ; // NORMAL; // (nx,ny,nz) +layout(location = TANGENT) in float3 v_tree_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float3 v_tree_B ; // BINORMAL; // binormal +layout(location = TEXCOORD0) in float4 v_tree_tc ; // TEXCOORD0; // (u,v,frac,???) + +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) +layout(location = TEXCOORD0) out float4 v2p_flat_tcdh ; // TEXCOORD0; // Texture coordinates, w=sun_occlusion +#else +layout(location = TEXCOORD0) out float2 v2p_flat_tcdh ; // TEXCOORD0; // Texture coordinates +#endif +layout(location = TEXCOORD1) out float4 v2p_flat_position; // TEXCOORD1; // position + hemi +layout(location = TEXCOORD2) out float3 v2p_flat_N ; // TEXCOORD2; // Eye-space normal (for lighting) +#ifdef USE_TDETAIL +layout(location = TEXCOORD3) out float2 v2p_flat_tcdbump; // TEXCOORD3; // d-bump +#endif +#ifdef USE_LM_HEMI +layout(location = TEXCOORD4) out float2 v2p_flat_lmh ; // TEXCOORD4; // lm-hemi +#endif + +v2p_flat _main (v_tree I); + +void main() +{ + v_tree I; + I.P = v_tree_P; + I.Nh = v_tree_Nh; + I.T = v_tree_T; + I.B = v_tree_B; + I.tc = v_tree_tc; + + v2p_flat O = _main (I); + + v2p_flat_tcdh = O.tcdh; + v2p_flat_position = O.position; + v2p_flat_N = O.N; +#ifdef USE_TDETAIL + v2p_flat_tcdbump = O.tcdbump; +#endif +#ifdef USE_LM_HEMI + v2p_flat_lmh = O.lmh; +#endif + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_tree_shadow.h b/res/gamedata/shaders/glr1/iostructs/v_tree_shadow.h new file mode 100755 index 00000000000..5cff887c80b --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_tree_shadow.h @@ -0,0 +1,37 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_shadow_P ; // POSITION; // (float,float,float,1) +#ifdef USE_AREF +layout(location = TEXCOORD0) in float4 v_shadow_tc ; // TEXCOORD0; // (u,v,frac,???) +#endif // USE_AREF + +#ifdef USE_AREF +layout(location = TEXCOORD1) out float2 v2p_shadow_tc0 ; // TEXCOORD1; // Diffuse map for aref +#endif // USE_AREF + +#ifdef USE_AREF +v2p_shadow_direct_aref _main ( v_shadow_direct_aref I ); +#else // USE_AREF +v2p_shadow_direct _main ( v_shadow_direct I ); +#endif // USE_AREF + +void main() +{ +#ifdef USE_AREF + v_shadow_direct_aref I; + I.tc = v_shadow_tc; +#else // USE_AREF + v_shadow_direct I; +#endif // USE_AREF + I.P = v_shadow_P; + +#ifdef USE_AREF + v2p_shadow_direct_aref O = _main (I); + v2p_shadow_tc0 = O.tc0; +#else // USE_AREF + v2p_shadow_direct O = _main (I); +#endif // USE_AREF + + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_vert.h b/res/gamedata/shaders/glr1/iostructs/v_vert.h new file mode 100755 index 00000000000..b3187f252d0 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_vert.h @@ -0,0 +1,48 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v2p +{ + float4 hpos ; // SV_Position; + float2 Tex0 ; // TEXCOORD0; + float3 c0 ; // COLOR0; // c0=all lighting + float fog ; // FOG; +}; + +layout(location = POSITION) in float4 v_static_color_P ; // POSITION; // (float,float,float,1) +layout(location = NORMAL) in float4 v_static_color_N ; // NORMAL; // (nx,ny,nz,hemi occlusion) +layout(location = TANGENT) in float4 v_static_color_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float4 v_static_color_B ; // BINORMAL; // binormal +layout(location = TEXCOORD0) in float2 v_static_color_tc ; // TEXCOORD0; // (u,v) +#ifdef USE_LM_HEMI +layout(location = TEXCOORD1) in float2 v_static_color_lmh ; // TEXCOORD1; // (lmu,lmv) +#endif +layout(location = COLOR0) in float4 v_static_color_c ; // COLOR0; // (r,g,b,dir-occlusion) + + +layout(location = TEXCOORD0) out float2 v2p_vert_tc ; // TEXCOORD0; +layout(location = COLOR0) out float3 v2p_vert_c ; // COLOR0; // c0=all lighting +layout(location = FOG) out float v2p_vert_fog ; // FOG; + +v2p _main ( v_static_color I ); + +void main() +{ + v_static_color I; + I.P = v_static_color_P; + I.Nh = v_static_color_N; + I.T = v_static_color_T; + I.B = v_static_color_B; + I.tc = v_static_color_tc; +#ifdef USE_LM_HEMI + I.lmh = v_static_color_lmh; +#endif + I.color = v_static_color_c; + + v2p O = _main (I); + + v2p_vert_tc = O.Tex0; + v2p_vert_c = O.c0; + v2p_vert_fog = O.fog; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_volume.h b/res/gamedata/shaders/glr1/iostructs/v_volume.h new file mode 100755 index 00000000000..430951c840d --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_volume.h @@ -0,0 +1,21 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +layout(location = POSITION) in float4 v_volume_P; + +layout(location = TEXCOORD0) out float4 v2p_volume_tc ; // TEXCOORD0; +#ifdef USE_SJITTER +layout(location = TEXCOORD1) out float4 v2p_volume_tcJ ; // TEXCOORD1; +#endif + +v2p_volume _main ( float4 P ); + +void main() +{ + v2p_volume O = _main ( v_volume_P ); + v2p_volume_tc = O.tc; +#ifdef USE_SJITTER + v2p_volume_tcJ = O.tcJ; +#endif + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_volumetric.h b/res/gamedata/shaders/glr1/iostructs/v_volumetric.h new file mode 100755 index 00000000000..01d2f53ff57 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_volumetric.h @@ -0,0 +1,41 @@ + +out gl_PerVertex +{ + vec4 gl_Position; + float gl_ClipDistance[6]; +}; + +struct v2p +{ + float3 lightToPos ; // TEXCOORD0; // light center to plane vector + float3 vPos ; // TEXCOORD1; // position in camera space + float fDensity ; // TEXCOORD2; // plane density alon Z axis +// float2 tNoise ; // TEXCOORD3; // projective noise + float3 clip0 ; // SV_ClipDistance0; + float3 clip1 ; // SV_ClipDistance1; + float4 hpos ; // SV_Position; +}; + +layout(location = POSITION) in float3 v_volumetric_P; + +layout(location = TEXCOORD0) out float3 v2p_lightToPos ; // TEXCOORD0; // light center to plane vector +layout(location = TEXCOORD1) out float3 v2p_vPos ; // TEXCOORD1; // position in camera space +layout(location = TEXCOORD2) out float v2p_fDensity ; // TEXCOORD2; // plane density alon Z axis +//layout(location = TEXCOORD3) out float2 v2p_tNoise ; // TEXCOORD3; // projective noise + +v2p _main ( float3 P ); + +void main() +{ + v2p O = _main ( v_volumetric_P ); + v2p_lightToPos = O.lightToPos; + v2p_vPos = O.vPos; + v2p_fDensity = O.fDensity; +// v2p_tNoise = O.tNoise; + gl_Position = O.hpos; + for (int i=0; i<3; ++i) + { + gl_ClipDistance[i] = O.clip0[i]; + gl_ClipDistance[i+3] = O.clip1[i]; + } +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_water.h b/res/gamedata/shaders/glr1/iostructs/v_water.h new file mode 100755 index 00000000000..bca20111495 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_water.h @@ -0,0 +1,86 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v_vert +{ + float4 P ; // POSITION; // (float,float,float,1) + float4 N ; // NORMAL; // (nx,ny,nz,hemi occlusion) + float4 T ; // TANGENT; + float4 B ; // BINORMAL; + float4 color ; // COLOR0; // (r,g,b,dir-occlusion) + float2 uv ; // TEXCOORD0; // (u0,v0) +}; +struct v2p +{ + float4 hpos ; // SV_Position; + float2 tbase ; // TEXCOORD0; // base + float2 tnorm0 ; // TEXCOORD1; // nm0 + float2 tnorm1 ; // TEXCOORD2; // nm1 + float3 M1 ; // TEXCOORD3; + float3 M2 ; // TEXCOORD4; + float3 M3 ; // TEXCOORD5; + float3 v2point ; // TEXCOORD6; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + float4 tctexgen; // TEXCOORD7; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +#if SSR_QUALITY > 0 + float4 position_w; // POSITION0; +#endif + float4 c0 ; // COLOR0; + float fog ; // FOG; +}; + +layout(location = POSITION) in float4 v_vert_P ; // POSITION; // (float,float,float,1) +layout(location = NORMAL) in float4 v_vert_N ; // NORMAL; // (nx,ny,nz,hemi occlusion) +layout(location = TANGENT) in float4 v_vert_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float4 v_vert_B ; // BINORMAL; // binormal +layout(location = COLOR0) in float4 v_vert_color ; // COLOR0; // (r,g,b,dir-occlusion) +layout(location = TEXCOORD0) in float2 v_vert_uv ; // TEXCOORD0; // (u0,v0) + +layout(location = TEXCOORD0) out float2 v2p_vert_tbase ; // TEXCOORD0; +layout(location = TEXCOORD1) out float2 v2p_vert_tnorm0 ; // TEXCOORD1; +layout(location = TEXCOORD2) out float2 v2p_vert_tnorm1 ; // TEXCOORD2; +layout(location = TEXCOORD3) out float3 v2p_vert_M1 ; // TEXCOORD3; +layout(location = TEXCOORD4) out float3 v2p_vert_M2 ; // TEXCOORD4; +layout(location = TEXCOORD5) out float3 v2p_vert_M3 ; // TEXCOORD5; +layout(location = TEXCOORD6) out float3 v2p_vert_v2point ; // TEXCOORD6; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +layout(location = TEXCOORD7) out float4 v2p_vert_tctexgen ; // TEXCOORD7; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +#if SSR_QUALITY > 0 +layout(location = POSITION0) out float4 v2p_vert_pos ; // POSITION0; +#endif +layout(location = COLOR0) out float4 v2p_vert_c0 ; // COLOR0; +layout(location = FOG) out float v2p_vert_fog ; // FOG; + +v2p _main (v_vert v); + +void main() +{ + v_vert I; + I.P = v_vert_P; + I.N = v_vert_N; + I.T = v_vert_T; + I.B = v_vert_B; + I.color = v_vert_color; + I.uv = v_vert_uv; + + v2p O = _main (I); + + v2p_vert_tbase = O.tbase; + v2p_vert_tnorm0 = O.tnorm0; + v2p_vert_tnorm1 = O.tnorm1; + v2p_vert_M1 = O.M1; + v2p_vert_M2 = O.M2; + v2p_vert_M3 = O.M3; + v2p_vert_v2point= O.v2point; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + v2p_vert_tctexgen = O.tctexgen; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + v2p_vert_c0 = O.c0; + v2p_vert_fog = O.fog; +#if SSR_QUALITY > 0 + v2p_vert_pos = O.position_w; +#endif + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_waterd.h b/res/gamedata/shaders/glr1/iostructs/v_waterd.h new file mode 100755 index 00000000000..51da1513f64 --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_waterd.h @@ -0,0 +1,59 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v_vert +{ + float4 P ; // POSITION; // (float,float,float,1) + float4 N ; // NORMAL; // (nx,ny,nz,hemi occlusion) + float4 T ; // TANGENT; + float4 B ; // BINORMAL; + float4 color ; // COLOR0; // (r,g,b,dir-occlusion) + int2 uv ; // TEXCOORD0; // (u0,v0) +}; +struct v2p +{ + float4 hpos ; // SV_Position; + float2 tbase ; // TEXCOORD0; + float2 tdist0 ; // TEXCOORD1; + float2 tdist1 ; // TEXCOORD2; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + float4 tctexgen; // TEXCOORD3; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +}; + +layout(location = POSITION) in float4 v_vert_P ; // POSITION; // (float,float,float,1) +layout(location = NORMAL) in float4 v_vert_N ; // NORMAL; // (nx,ny,nz,hemi occlusion) +layout(location = TANGENT) in float4 v_vert_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float4 v_vert_B ; // BINORMAL; // binormal +layout(location = COLOR0) in float4 v_vert_color ; // COLOR0; // (r,g,b,dir-occlusion) +layout(location = TEXCOORD0) in int2 v_vert_uv ; // TEXCOORD0; // (u0,v0) + +layout(location = TEXCOORD0) out float2 v2p_vert_tbase ; // TEXCOORD0; +layout(location = TEXCOORD1) out float2 v2p_vert_tdist0 ; // TEXCOORD1; +layout(location = TEXCOORD2) out float2 v2p_vert_tdist1 ; // TEXCOORD2; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) +layout(location = TEXCOORD3) out float4 v2p_vert_tctexgen ; // TEXCOORD3; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + +v2p _main (v_vert v); + +void main() +{ + v_vert I; + I.P = v_vert_P; + I.N = v_vert_N; + I.T = v_vert_T; + I.B = v_vert_B; + I.color = v_vert_color; + I.uv = v_vert_uv; + + v2p O = _main (I); + + v2p_vert_tbase = O.tbase; + v2p_vert_tdist0 = O.tdist0; + v2p_vert_tdist1 = O.tdist1; +#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + v2p_vert_tctexgen = O.tctexgen; +#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER) + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/iostructs/v_wmark.h b/res/gamedata/shaders/glr1/iostructs/v_wmark.h new file mode 100755 index 00000000000..4355a3201cc --- /dev/null +++ b/res/gamedata/shaders/glr1/iostructs/v_wmark.h @@ -0,0 +1,46 @@ + +out gl_PerVertex { vec4 gl_Position; }; + +struct v2p +{ + float4 hpos ; // SV_Position; + float2 tc0 ; // TEXCOORD0; + float3 c0 ; // COLOR0; // c0=all lighting + float fog ; // FOG; +}; + +layout(location = POSITION) in float4 v_static_P ; // POSITION; // (float,float,float,1) +layout(location = NORMAL) in float4 v_static_N ; // NORMAL; // (nx,ny,nz,hemi occlusion) +layout(location = TANGENT) in float4 v_static_T ; // TANGENT; // tangent +layout(location = BINORMAL) in float4 v_static_B ; // BINORMAL; // binormal +layout(location = TEXCOORD0) in float2 v_static_tc ; // TEXCOORD0; // (u,v) +#ifdef USE_LM_HEMI +layout(location = TEXCOORD1) in float2 v_static_lmh ; // TEXCOORD1; // (lmu,lmv) +#endif + + +layout(location = TEXCOORD0) out float2 v2p_wmark_tc0 ; // TEXCOORD0; +layout(location = COLOR0) out float3 v2p_wmark_c0 ; // COLOR0; // c0=all lighting +layout(location = FOG) out float v2p_wmark_fog ; // FOG; + +v2p _main ( v_static v ); + +void main() +{ + v_static I; + I.P = v_static_P; + I.Nh = v_static_N; + I.T = v_static_T; + I.B = v_static_B; + I.tc = v_static_tc; +#ifdef USE_LM_HEMI + I.lmh = v_static_lmh; +#endif + + v2p O = _main (I); + + v2p_wmark_tc0 = O.tc0; + v2p_wmark_c0 = O.c0; + v2p_wmark_fog = O.fog; + gl_Position = O.hpos; +} diff --git a/res/gamedata/shaders/glr1/lmap.ps b/res/gamedata/shaders/glr1/lmap.ps new file mode 100755 index 0000000000000000000000000000000000000000..3de42e4de789f8b36ee1508f3be06c886b74d406 GIT binary patch literal 741 zcmcJM&u)T15XR55Pcg9NH|2oJ2K1C+$ikimOx?v+vpG-Nr;uCEncV@tO5HY3@I_ww1v8D zlv4A5JG2@<%r&)&V_6~O+7xls#6cW@hm;xaaSUq|UzDF%UV)1_Dug$5={4K|c#Tx1 zd!K?GZyp@y^~`ZaxPUmt7q#Y+Ia6G^sU?DatdAM@>&uBUkyJ!jCT7&>M`(f*Wud*F zEGCtFdh8|~^W<~ntU&4ZcrbCDitb5nC8aIv`*t=+yAQF>PbMuKzGCl@Uzq17TY&yf sXH#f9d)gu;))e<7%2%0$6qck=woXBvy0$J5<#&K5Bh!xbHRW|vf7cho{r~^~ literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/lmap.vs b/res/gamedata/shaders/glr1/lmap.vs new file mode 100755 index 00000000000..88ec7165c19 --- /dev/null +++ b/res/gamedata/shaders/glr1/lmap.vs @@ -0,0 +1,29 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; + float2 tc1 : TEXCOORD1; + float2 tch : TEXCOORD2; + float3 c0 : COLOR0; // c0=hemi+v-lights, c0.a = dt* + float3 c1 : COLOR1; // c1=sun, c1.a = dt+ + float fog : FOG; +}; + +vf main (v_lmap v) +{ + vf o; + + float3 N = unpack_normal (v.N); + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc +// o.tc0 = unpack_tc_base (v.tc0); // copy tc + o.tc1 = unpack_tc_lmap (v.uv1); // copy tc + o.tch = o.tc1; + o.c0 = v_hemi(N); // just hemisphere + o.c1 = v_sun(N); // sun + o.fog = calc_fogging (v.P); // fog, input in world coords + + return o; +} diff --git a/res/gamedata/shaders/glr1/lmap_dt.ps b/res/gamedata/shaders/glr1/lmap_dt.ps new file mode 100755 index 0000000000000000000000000000000000000000..c77fb54a034acffb4d3b579ba4b4742987e13a73 GIT binary patch literal 907 zcmcJN!EVAZ42I9nQ&`)jbWmv73AEGL0SSo-?XX)FLI#o27PaX#Y2w{yyJd6_uw2qQ zpY7j&a_>sx+k?eBQx!#3CZ{{4nozeUAbe(L^{o(2+J9sS!ORv2@b>clyxs0rvn5QY zxYvyxBIyuG1@VPG50Pw$WP+S*;fBb3h|C2!*r1(P*vWYW5(DtO-E4Oxgq4_CqA^A# za_Kx>0QO5T5+hhj*aND|QmN^`Eh>$#?#p_`<~<@5+Liga$Ga|C}YpEI7+$3591 z#zilAYA!Za?<> Me%w__Gzq+@9}TJS{r~^~ literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/lmap_dt.vs b/res/gamedata/shaders/glr1/lmap_dt.vs new file mode 100755 index 00000000000..f1617ab110b --- /dev/null +++ b/res/gamedata/shaders/glr1/lmap_dt.vs @@ -0,0 +1,33 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; + float2 tc1 : TEXCOORD1; + float2 tch : TEXCOORD2; + float2 tc2 : TEXCOORD3; + float4 c0 : COLOR0; // c0=hemi+v-lights, c0.a = dt* + float4 c1 : COLOR1; // c1=sun, c1.a = dt+ + float fog : FOG; +}; + +vf main (v_lmap v) +{ + vf o; + + float2 dt = calc_detail (v.P); + float3 N = unpack_normal (v.N); + + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc +// o.tc0 = unpack_tc_base (v.tc0); // copy tc + o.tc1 = unpack_tc_lmap (v.uv1); // copy tc + o.tch = o.tc1; + o.tc2 = o.tc0*dt_params; // dt tc + o.c0 = float4 (v_hemi(N),dt.x); // c0=hemi+v-lights, c0.a = dt* + o.c1 = float4 (v_sun(N),dt.y); // c1=sun, c1.a = dt+ + o.fog = calc_fogging (v.P); // fog, input in world coords + + return o; +} diff --git a/res/gamedata/shaders/glr1/lmap_l.ps b/res/gamedata/shaders/glr1/lmap_l.ps new file mode 100755 index 0000000000000000000000000000000000000000..2c8445b535e0f56721a51e9249c1696958ca5bec GIT binary patch literal 541 zcmcIgy-ve05T4IZaVkp+C4Y2k#MClGsuWZ)uvtzpjU~s45(ia6eRq7P0)2scvd{PZ z-Wk`}`9tHP>AS9Xak~&=^5fiigs*%M-vXgk_A^KDO}asVx0m;ARULL|0ZD?kQ^WO2 zcD<7EN~=2~nB)lp1;Do2SBJC^=R%0&W+zbNt2t>a$p0FlQ^v_*l9|jP!VnHiT*3y~ zP6)~t*We{(LU=~6Px%fYns~A*B35Ch7e`kr1t|qBT~thgbcv{>W~zs*d6=tBaAs3NUIM`Ag`#e*W``dJovSC4Ex>eVBzOMMa8Z4rUp0bse??)J0z-joFk zK=-&5#NrkUA*TQKEH%F6SE&SvGe;=WTqjkN1W5oxw94TIN3cNN$EwKp&%q=l7{Uu0 zc@0+p!-g~Cjc?^0xswP-s{O@LhH*h3XVr1A<;Uxq_-tkj#1~ndAd^&nI-6XdoL~s* zu?7$F>(e0y`<$a)$K= n8E8eG?oqQBS_fFNvNZx~Y1&#Nvd1vw2EQJ6@#Ny6Pkj?V{ literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/lmape.vs b/res/gamedata/shaders/glr1/lmape.vs new file mode 100755 index 00000000000..b37fc7b7d5f --- /dev/null +++ b/res/gamedata/shaders/glr1/lmape.vs @@ -0,0 +1,33 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; + float2 tc1 : TEXCOORD1; + float2 tch : TEXCOORD2; + float3 tc2 : TEXCOORD3; + float3 c0 : COLOR0; // c0=hemi+v-lights, c0.a = dt* + float3 c1 : COLOR1; // c1=sun, c1.a = dt+ + float fog : FOG; +}; + +vf main (v_lmap v) +{ + vf o; + + float3 pos_w = v.P; + float3 norm_w = normalize (unpack_normal(v.N)); + + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc +// o.tc0 = unpack_tc_base (v.tc0); // copy tc + o.tc1 = unpack_tc_lmap (v.uv1); // copy tc + o.tch = o.tc1; + o.tc2 = calc_reflection (pos_w, norm_w); + o.c0 = v_hemi(norm_w); // just hemisphere + o.c1 = v_sun (norm_w); // sun + o.fog = calc_fogging (v.P); // fog, input in world coords + + return o; +} diff --git a/res/gamedata/shaders/glr1/lod.ps b/res/gamedata/shaders/glr1/lod.ps new file mode 100755 index 0000000000000000000000000000000000000000..7e5e42e638354969714ad08e337a0745380740a9 GIT binary patch literal 840 zcmcJNOH0E*6ouD!e#ND3(paXMiEbKPwJr)mq_}Vw;y9s!yvV~Ar2pMJlUS2t-5E$0 zIo~~VICpN+LS@~%#+fSfye#;B##qzVooW$2WW_!iLXwqnD-l}dtq@)wU)N!{+js#i zm-rSp+M6(9#E3H^CX5_0(lUFUr&Aw)#Q0}MFxbaga)+Q+unwQX9px}VRGF3aSxg3z z0{n=lfHAiGw}-6pIX&u(bw!$#b&gG(SDCKm2BC>;QxIGi#Wm4(^OtBQhgR}9EuyN4 zL?pmL+8}Om4lA@((Kf%^vuP0Ef!3;zas$qgaIxjI=Xo$8#V@3=q!^Jl=LKp1SyEn* zm!5{~J$)i4$M>GpWCe~5zA#?{C;TvXw_L%H7s1$!`98q6x#9VN=-%I_Yh>7wKD`&)WlGi6fOy6x(My!)F6jvcZgcuc^FeF5N+-n#$* literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/lod.vs b/res/gamedata/shaders/glr1/lod.vs new file mode 100755 index 00000000000..3d7ac2635a0 --- /dev/null +++ b/res/gamedata/shaders/glr1/lod.vs @@ -0,0 +1,62 @@ +#include "common.h" + +struct vv +{ + float3 pos0 : POSITION0 ; + float3 pos1 : POSITION1 ; + float3 n0 : NORMAL0 ; + float3 n1 : NORMAL1 ; + float2 tc0 : TEXCOORD0 ; + float2 tc1 : TEXCOORD1 ; + float4 rgbh0 : TEXCOORD2; // rgb.h + float4 rgbh1 : TEXCOORD3; // rgb.h + float4 sun_af : COLOR0; // x=sun_0, y=sun_1, z=alpha, w=factor +}; +struct vf +{ + float4 hpos : POSITION; + half2 tc0 : TEXCOORD0; // base0 + half2 tc1 : TEXCOORD1; // base1 + half2 tc2 : TEXCOORD2; // hemi0 + half2 tc3 : TEXCOORD3; // hemi1 + half4 c : COLOR0; // color.alpha + half4 f : COLOR1; // factor + float fog : FOG ; +}; + +#define L_SCALE (1.55) +#define L_SUN_HACK (.7) +vf main (vv v) +{ + vf o; + + // lerp pos + float factor = v.sun_af.w ; + float4 pos = float4 (lerp(v.pos0,v.pos1,factor),1); + o.hpos = mul (m_VP, pos); // xform, input in world coords + + // replicate TCs + o.tc0 = v.tc0; + o.tc1 = v.tc1; + o.tc2 = v.tc0; + o.tc3 = v.tc1; + + // calc normal & lighting + float3 normal = normalize (lerp(v.n0,v.n1,factor)); + normal.y+= 1; + normal = normalize (normal); + float4 rgbh = lerp (v.rgbh0,v.rgbh1,factor) *L_SCALE; + float sun = lerp (v.sun_af.x, v.sun_af.y, factor) *L_SCALE; + float sun_c = 1 + L_SUN_HACK * dot(normal, L_sun_dir_w); // [1+-delta], normal already inverted + + float3 L_rgb = rgbh.rgb; // precalculated RGB lighting + float3 L_hemi = L_hemi_color * rgbh.w; // hemisphere + float3 L_sun = L_sun_color * sun * sun_c; // sun + float3 L_final = L_rgb + L_hemi + L_sun + L_ambient; + + o.c = float4 (L_final,v.sun_af.z); + o.f = factor ; + o.fog = calc_fogging (pos); // fog, input in world coords + + return o ; +} diff --git a/res/gamedata/shaders/glr1/model_def_hq.ps b/res/gamedata/shaders/glr1/model_def_hq.ps new file mode 100755 index 0000000000000000000000000000000000000000..f2751725609218bd28355377ec6cd24419736ed6 GIT binary patch literal 717 zcmcJMv2MaJ5QgXTQ=I4$AOsSaK%JliQl(U=L$}B=Cb8r=spGUr74Kf#Nd$d>W{9Qp zf8X!>?@1^oyEDfLtE;M3Q8^)`HM(O4;VWs#4?!rYyd(&Qt+oj8{_?R;)6-$KgXI!) z+VV$9{3waNL{_vR*kjgUApraIH9c8?Beb0wZ#Tf=@z(abTlu+QwX8MH@j{uYHM#8w zS^nE+(fB5=ToO0+2BD%tWlfvKSquT%NbrbL*rFf7#^cl3fXQ4E2+wHvH90`g`a*b& zY;4orUFOpGBXb2Wi>-|KnMF|=p^Cm~jUeyv%*i8N@QHaJvEbqGQBXGt(PThwqnz9yZ9qJ6W;hx`AML*c@eMA)!OW z{XhC1r@074WxvD`;!Dob)2yc(VwMc!*PS7tx#_e*^jm2Lys~8t)Zi_HW0d>8-y>g`vrgVBo!OC({;f0SWn< zRMQ&v6l3|yvGERU8`=>(la;sf2#JY{v}XP*);@C7Z9(L35N!mS zGj~S!J~VyVP6tk_a_G9Dck30RRAMR>!I6#li$qWtZS@3)rm7~%Lx{82Z0|=n7YJ18 zhXnAx`;4<}pZF1Y9*tu7;iVeHk_(nxU^(6&ah{+`7XHgHTmC8}$8&^;-rWvPeNzph zBUyA~%LPjaWPbaA9)7pco|dM!=EPgHE)#S`)90higFJvW=?o~P4TNM}*Llodwas^} zGkT`for9rAQvAe{^O1PfUM{yVxZr9MJ&|2|Yr3{9!ZZE>7saMi literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/model_env_hq.ps b/res/gamedata/shaders/glr1/model_env_hq.ps new file mode 100755 index 0000000000000000000000000000000000000000..39a143706fc9b6a5fe4dab11100d1f444a35f7b2 GIT binary patch literal 842 zcmcJML2kk@5JlJHQ;gb8fDlMv1?r~20;v*J)k@t(CN*Hmaj4@^q>8)O9*2@1pjpJy z%=iD}H}_H(s`(IjS5#$L>Ev+7SZz&HScFq{WZw+oz|}58u*Gy(jFmHfysq)otO0W3C8n-`bkgX%_KyHlVb z>bex)RiDG6QkB60?s#DJKW;qA?DItQ+mE#4kiUgs(?cwO4nd2E0Ee1-fnr(;A% z?hjV#eY+?GbsHo1^2F@74kV$Z0hPZo^wtpt5ZoAfxs`5{F&;!IV-&W)Axd4#57FzG zyIuK_)=4q$+YrFLeOM!sSt|!ha$+US5u$dm0jk`Y#NHwe|K#iXnw`{Kg?0aCUa1Bb xORNIxI2;MTLYn{?_yH-q@9*}r7FE?)21eM%XhhmAM5Iql9L{}vZoAGG_5;uS=QIES literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/model_env_hq.vs b/res/gamedata/shaders/glr1/model_env_hq.vs new file mode 100755 index 00000000000..0bf2ddeb4b5 --- /dev/null +++ b/res/gamedata/shaders/glr1/model_env_hq.vs @@ -0,0 +1,42 @@ +#include "common.h" +#include "skin.h" + +// #define SKIN_2 + +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; // base + float3 tc1 : TEXCOORD1; // environment + float4 tc2 : TEXCOORD2; // projected lmap + float3 c0 : COLOR0; // sun-color + float4 c1 : COLOR1; // lq-color + factor + float fog : FOG; +}; + +vf _main (v_model v) +{ + vf o; + + float4 pos = v.pos; + float3 pos_w = mul (m_W, pos); + float4 pos_w4 = float4 (pos_w,1); + float3 norm_w = normalize (mul(m_W,v.norm)); + + o.hpos = mul (m_WVP, pos); // xform, input in world coords + o.tc0 = v.tc.xy; // copy tc + o.tc1 = calc_reflection (pos_w, norm_w); + o.tc2 = calc_model_lmap (pos_w); // + o.c0 = calc_sun (norm_w); // sun + o.c1 = float4 (calc_model_lq_lighting(norm_w),m_plmap_clamp[0].w); + o.fog = calc_fogging (pos_w4); // fog, input in world coords +#ifdef SKIN_COLOR + o.c1.rgb *= v.rgb_tint; + o.c1.w = 1; +#endif + return o; +} + +///////////////////////////////////////////////////////////////////////// +#define SKIN_VF vf +#include "skin_main.h" \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/model_env_lq.ps b/res/gamedata/shaders/glr1/model_env_lq.ps new file mode 100755 index 0000000000000000000000000000000000000000..94acb343aa6a2565918c9c3cc2b89e1dff95c3a8 GIT binary patch literal 526 zcmcJL%WA_g5JlIcuNcxz5{#c&#dK3A3q!#rw9uV#TqPFBvXSKwDEaq}WQXPlqRoJG zI9GRGgsSEE!*Nk}ZQCioSui#jJ=O-{68G$vAvBdd#R#Sjw+QgL|IUiyunSWN0z6g& zpOM5O(IXN$gsY3toocx<3@2Lx+WY&sACO*7GIIX0&I$ zz`$5ILR#GLG~hxV8>3Y#l)ayn-A~E_Q?{%_8r>G)yZ~0^Yq@hi-l!kc70n?S1=P8C zRQ^11Ew!OXsu{Q1;CYES`?u#t(_3>A5`8#1LCYFdb$yjqDMaLwqb*ILps=J%F+`Mu zt$bhv&t%0ZTLVOW=)~K^#XDWzcrLgLZT0c8@jTaw!ShnbLw|MMC??0lFMmJ~dR{4o n=^(N}HrmExN!V4d2a8~Y9gHFhhd>nciHXPheX09;F(iqg*Lmg-12hiyc_C31QPW+!yQ+zb0^+R?yw=Rc-`du=nYXsQBS6z& jTt6>;*_U+0MnsDfRoG!0_XqPSG6fw|a6p@js(IxvDvvkN literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/models_lightplanes.s b/res/gamedata/shaders/glr1/models_lightplanes.s new file mode 100755 index 00000000000..e98337dd524 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_lightplanes.s @@ -0,0 +1,9 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_def_lplanes","base_lplanes") + : fog (false) + : zb (true,false) + : blend (true,blend.srcalpha,blend.one) + : aref (true,0) + : sorting (2, false) + shader:sampler ("s_base") :texture (t_base) +end diff --git a/res/gamedata/shaders/glr1/models_pautina.s b/res/gamedata/shaders/glr1/models_pautina.s new file mode 100755 index 00000000000..fab11cda889 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_pautina.s @@ -0,0 +1,31 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_distort4ghost","particle") -- particle_alphaonly + : sorting (3, true) + : blend (true,blend.srccolor,blend.invsrcalpha) + : aref (true,0) + : zb (true,false) + : fog (false) + : distort (false) + shader:sampler ("s_base") :texture (t_base) +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort4ghost","particle_distort") + : sorting (3, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture ("pfx\\pfx_dist_glass") --:texture (t_base) -- ("pfx\\pfx_dist_glass2" +end + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_def_lplanes","base_lplanes") + : fog (false) + : zb (true,false) + : blend (true,blend.srccolor,blend.one) + : aref (true,0) + : sorting (2, true) + shader:sampler ("s_base") :texture (t_base) +end diff --git a/res/gamedata/shaders/glr1/models_selflight.s b/res/gamedata/shaders/glr1/models_selflight.s new file mode 100755 index 00000000000..5069e3636d0 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_selflight.s @@ -0,0 +1,13 @@ +function normal (shader, t_base, t_second, t_detail) + shader :begin ("model_def_lqs","simple") + :fog (true) + shader :sampler ("s_base") :texture (t_base) +end + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "model_def_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "model_def_point") +end diff --git a/res/gamedata/shaders/glr1/models_selflight_det.s b/res/gamedata/shaders/glr1/models_selflight_det.s new file mode 100755 index 00000000000..5069e3636d0 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_selflight_det.s @@ -0,0 +1,13 @@ +function normal (shader, t_base, t_second, t_detail) + shader :begin ("model_def_lqs","simple") + :fog (true) + shader :sampler ("s_base") :texture (t_base) +end + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "model_def_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "model_def_point") +end diff --git a/res/gamedata/shaders/glr1/models_selflightl.s b/res/gamedata/shaders/glr1/models_selflightl.s new file mode 100755 index 00000000000..5069e3636d0 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_selflightl.s @@ -0,0 +1,13 @@ +function normal (shader, t_base, t_second, t_detail) + shader :begin ("model_def_lqs","simple") + :fog (true) + shader :sampler ("s_base") :texture (t_base) +end + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "model_def_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "model_def_point") +end diff --git a/res/gamedata/shaders/glr1/models_xanomaly.s b/res/gamedata/shaders/glr1/models_xanomaly.s new file mode 100755 index 00000000000..ecece0b07a4 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xanomaly.s @@ -0,0 +1,91 @@ + --[[ +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "model_def_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "model_def_point") +end + + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_distort4glass","particle") + : sorting (2,true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : zb (true,true) + : fog (false) + : distort (false) + shader:sampler ("s_base") :texture (t_base) +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort4glass","particle_distort") + : sorting (2, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,true) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture ("pfx\\pfx_dist_glass3") +end + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_env_hq","model_env_sl") + : fog (false) + : zb (true,true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3, false) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") + : clamp() +end +]] + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "model_def_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "model_def_point") +end + + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort4glass","particle_distort") + : sorting (3, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture ("pfx\\pfx_dist_glass3") +end + + +function normal_hq(shader, t_base, t_second, t_detail) + shader:begin ("model_env_hq","model_env_hq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() + shader:sampler ("s_lmap") :texture ("$user$projector") + : clamp () + : f_linear () + : project (true) +end + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_env_lq","model_env_lq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() +end diff --git a/res/gamedata/shaders/glr1/models_xdistort.s b/res/gamedata/shaders/glr1/models_xdistort.s new file mode 100755 index 00000000000..f3430747ee4 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xdistort.s @@ -0,0 +1,21 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_distort","particle_alphaonly") -- particle_alphaonly + : sorting (3, false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort","particle_distort") + : sorting (3, false) + : blend (true,blend.srccolor,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture (t_base) -- "pfx\\pfx_distortion" +end diff --git a/res/gamedata/shaders/glr1/models_xdistortcolor.s b/res/gamedata/shaders/glr1/models_xdistortcolor.s new file mode 100755 index 00000000000..ac8a59e91ea --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xdistortcolor.s @@ -0,0 +1,21 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_distort","particle") -- particle_alphaonly + : sorting (3, false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort","particle_distort") + : sorting (3, false) + : blend (true,blend.srccolor,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture (t_base) -- "pfx\\pfx_distortion" +end \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/models_xdistortcolorl.s b/res/gamedata/shaders/glr1/models_xdistortcolorl.s new file mode 100755 index 00000000000..a2755b22352 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xdistortcolorl.s @@ -0,0 +1,21 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_distort","particle") -- particle_alphaonly + : sorting (2,true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort","particle_distort") + : sorting (3, false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture (t_base) -- "pfx\\pfx_distortion" +end diff --git a/res/gamedata/shaders/glr1/models_xdistortcolorlinv.s b/res/gamedata/shaders/glr1/models_xdistortcolorlinv.s new file mode 100755 index 00000000000..d730e4967d2 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xdistortcolorlinv.s @@ -0,0 +1,21 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_distort_inv","particle") + : sorting (2,true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort","particle_distort") + : sorting (3, false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture (t_base) -- "pfx\\pfx_distortion" +end diff --git a/res/gamedata/shaders/glr1/models_xdistortinv.s b/res/gamedata/shaders/glr1/models_xdistortinv.s new file mode 100755 index 00000000000..489348d9af5 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xdistortinv.s @@ -0,0 +1,21 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_distort_inv","particle_alphaonly") -- particle_alphaonly + : sorting (3, false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort_inv","particle_distort") + : sorting (3, false) + : blend (true,blend.srccolor,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture (t_base) -- "pfx\\pfx_distortion" +end diff --git a/res/gamedata/shaders/glr1/models_xglass.s b/res/gamedata/shaders/glr1/models_xglass.s new file mode 100755 index 00000000000..e8b0add7f0d --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xglass.s @@ -0,0 +1,47 @@ + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "model_def_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "model_def_point") +end + + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort4glass","particle_distort") + : sorting (3, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture ("pfx\\pfx_dist_glass2") +end + + +function normal_hq(shader, t_base, t_second, t_detail) + shader:begin ("model_env_hq","model_env_hq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() + shader:sampler ("s_lmap") :texture ("$user$projector") + : clamp () + : f_linear () + : project (true) +end + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_env_lq","model_env_lq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() +end diff --git a/res/gamedata/shaders/glr1/models_xglass2.s b/res/gamedata/shaders/glr1/models_xglass2.s new file mode 100755 index 00000000000..f9bb3abdcf9 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xglass2.s @@ -0,0 +1,47 @@ + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "model_def_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "model_def_point") +end + + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort4glass","particle_distort") + : sorting (3, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture ("pfx\\pfx_dist_glass3") +end + + +function normal_hq(shader, t_base, t_second, t_detail) + shader:begin ("model_env_hq","model_env_hq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() + shader:sampler ("s_lmap") :texture ("$user$projector") + : clamp () + : f_linear () + : project (true) +end + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_env_lq","model_env_lq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() +end diff --git a/res/gamedata/shaders/glr1/models_xlens.s b/res/gamedata/shaders/glr1/models_xlens.s new file mode 100755 index 00000000000..6a64ac30479 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xlens.s @@ -0,0 +1,47 @@ + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "model_def_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "model_def_point") +end + + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort4glass","particle_distort") + : sorting (3, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture ("pfx\\pfx_dist_lens_base") --(t_base) + shader:sampler ("s_distort") :texture ("pfx\\pfx_dist_lens") +end + + +function normal_hq(shader, t_base, t_second, t_detail) + shader:begin ("model_env_hq","model_env_hq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() + shader:sampler ("s_lmap") :texture ("$user$projector") + : clamp () + : f_linear () + : project (true) +end + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_env_lq","model_env_lq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() +end diff --git a/res/gamedata/shaders/glr1/models_xmonolith.s b/res/gamedata/shaders/glr1/models_xmonolith.s new file mode 100755 index 00000000000..9af7cc6d438 --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xmonolith.s @@ -0,0 +1,47 @@ + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "model_def_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "model_def_point") +end + + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort4glass","particle_distort") + : sorting (3, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture ("pfx\\pfx_dist_glass4") +end + + +function normal_hq(shader, t_base, t_second, t_detail) + shader:begin ("model_env_hq","model_env_hq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() + shader:sampler ("s_lmap") :texture ("$user$projector") + : clamp () + : f_linear () + : project (true) +end + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_env_lq","model_env_lq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() +end diff --git a/res/gamedata/shaders/glr1/models_xwindows.s b/res/gamedata/shaders/glr1/models_xwindows.s new file mode 100755 index 00000000000..ce0c5a973fc --- /dev/null +++ b/res/gamedata/shaders/glr1/models_xwindows.s @@ -0,0 +1,47 @@ + +function l_spot (shader, t_base, t_second, t_detail) + r1_lspot (shader, t_base, "model_def_spot") +end + +function l_point (shader, t_base, t_second, t_detail) + r1_lpoint (shader, t_base, "model_def_point") +end + + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("model_distort4glass","particle_distort") + : sorting (3, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) :distort (false) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture ("pfx\\pfx_dist_glass") +end + + +function normal_hq(shader, t_base, t_second, t_detail) + shader:begin ("model_env_hq","model_env_hq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() + shader:sampler ("s_lmap") :texture ("$user$projector") + : clamp () + : f_linear () + : project (true) +end + +function normal (shader, t_base, t_second, t_detail) + shader:begin ("model_env_lq","model_env_lq") + : fog (true) + : zb (true,false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : aref (true,0) + : sorting (3,true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_env") :texture ("sky\\sky_5_cube") : clamp() +end diff --git a/res/gamedata/shaders/glr1/p.bat b/res/gamedata/shaders/glr1/p.bat new file mode 100755 index 00000000000..f9293fb1d94 --- /dev/null +++ b/res/gamedata/shaders/glr1/p.bat @@ -0,0 +1,12 @@ +rem @C:\DEV\SDK\dx9se4_jun\Utilities\Bin\x86\fxc /nologo /Tps_1_1 /Emain_ps_1_1 /Zpr /Fctest\p11_%1 %1 +rem @C:\DEV\SDK\dx9se4_jun\Utilities\Bin\x86\fxc /nologo /Tps_2_0 /Emain_ps_1_1 /Zpr /Fctest\p20_%1 %1 +rem @C:\DEV\SDK\dx9se4_jun\Utilities\Bin\x86\fxc /nologo /Tps_3_0 /Emain_ps_1_1 /Zpr /Fctest\p30_%1 %1 +rem @C:\tools\NVSpG70\nvshaderperf -a NV30 test\p11_%1 > test\pXX_%1.log +rem @C:\tools\NVSpG70\nvshaderperf -a NV35 test\p11_%1 >> test\pXX_%1.log +rem @C:\tools\NVSpG70\nvshaderperf -a NV40 test\p11_%1 >> test\pXX_%1.log +rem @C:\tools\NVSpG70\nvshaderperf -a G70 test\p11_%1 >> test\pXX_%1.log +rem @rem @C:\tools\NVSpG70\nvshaderperf -a G70 test\p30_%1 >> test\pXX_%1.log + +fxc /nologo /Tps_1_1 /Emain_ps_1_1 /Zpr /Fctest\p11_%1 %1 +fxc /nologo /Tps_2_0 /Emain_ps_1_1 /Zpr /Fctest\p20_%1 %1 +fxc /nologo /Tps_3_0 /Emain_ps_1_1 /Zpr /Fctest\p30_%1 %1 diff --git a/res/gamedata/shaders/glr1/p14.bat b/res/gamedata/shaders/glr1/p14.bat new file mode 100755 index 00000000000..4883290f46e --- /dev/null +++ b/res/gamedata/shaders/glr1/p14.bat @@ -0,0 +1 @@ +@C:\DEV\SDK\dx9se4_apr\Utilities\Bin\x86\fxc /nologo /Tps_1_4 /Emain_ps_1_4 /Zpr /Fctest\1_1a_%1 %1 diff --git a/res/gamedata/shaders/glr1/particle.ps b/res/gamedata/shaders/glr1/particle.ps new file mode 100755 index 0000000000000000000000000000000000000000..d8ae485665015222b3f8cf598ae48450ffcbf0b9 GIT binary patch literal 216 zcmY$+%uCKGO-WTyO3u&C&Ck=zP~uXCi)H2)mlTyImlVeo#1|wMm1HL8q=Hm%>C+4V zjaCTAtVqq_%1F#fGg07-&rQtCRatLCn;aI9Rp=IO6bnemk}8rQTHlc@FQ? z@IPSj8!YZ1RkIzrMs}oPH~_GKo!aO2;$6YkPs89)c&iA>|Lvg~UZyJ-#HneRwFE=u zBDgMVjA6PpYDLzhAnByK#dJl7w?)1kXdw3aLwsMANB5x(c!DNliRIU_j!fqZN}CM( zi>o_!fDcW3#2(1HFHpsU+Jkh$BIN~%|B;j^0L`t_YHcwBOua;5hsRUTWnXa$-g6^A DX)=Pg literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/particle_alphaonly.ps b/res/gamedata/shaders/glr1/particle_alphaonly.ps new file mode 100755 index 0000000000000000000000000000000000000000..4d1599c820f561b538608c98a8b4d2c21445c1db GIT binary patch literal 287 zcmcJKy$XXc6h`NJpW=Ced-xoWN;AcnNK z7o|lztGlLIEZ!1C^#3+{O^<$P^cYWY!ygzpMx+1$ literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/particle_distort.ps b/res/gamedata/shaders/glr1/particle_distort.ps new file mode 100755 index 0000000000000000000000000000000000000000..e87cfb02bf9ee3df1aaff92a6153c00b1d2ef969 GIT binary patch literal 351 zcmcJIOAdlC5J1=MDJHNf##96Dh&wjyJb($QrD&6WNIMu41l|2@QW{SBp$wgz9(=G6g&mCwWdpJ6bwnSq zri1YU4?sFAv?C1e0o9{y2w^{c+j5lqqFz}@GYFZ&30^fWU<18J h)^f?i^|D>672ETwDrPe%oPzs4V_$7SmsWya^bNSGWJ~}6 literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/particles_xadd.s b/res/gamedata/shaders/glr1/particles_xadd.s new file mode 100755 index 00000000000..dcd46328cba --- /dev/null +++ b/res/gamedata/shaders/glr1/particles_xadd.s @@ -0,0 +1,21 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("particle", "particle") + : sorting (3, false) + : blend (true,blend.one,blend.one) + : aref (false,0) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("particle", "particle_distort") + : sorting (3, false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture (t_second) -- "pfx\\pfx_distortion" +end diff --git a/res/gamedata/shaders/glr1/particles_xdistort.s b/res/gamedata/shaders/glr1/particles_xdistort.s new file mode 100755 index 00000000000..fa9a53f18e8 --- /dev/null +++ b/res/gamedata/shaders/glr1/particles_xdistort.s @@ -0,0 +1,10 @@ +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("particle", "particle_distort") + : sorting (3, false) + : blend (true,blend.srcalpha,blend.invsrcalpha) + : zb (true,false) + : fog (false) + : distort (true) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_distort") :texture (t_base) -- "pfx\\pfx_distortion" +end diff --git a/res/gamedata/shaders/glr1/portal.s b/res/gamedata/shaders/glr1/portal.s new file mode 100755 index 00000000000..7bca23b3480 --- /dev/null +++ b/res/gamedata/shaders/glr1/portal.s @@ -0,0 +1,7 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("portal","simple_color") + : fog (true) + : zb (true,false) + : sorting (3, true) + : blend (true,blend.srcalpha,blend.invsrcalpha) +end diff --git a/res/gamedata/shaders/glr1/portal.vs b/res/gamedata/shaders/glr1/portal.vs new file mode 100755 index 00000000000..d47775af790 --- /dev/null +++ b/res/gamedata/shaders/glr1/portal.vs @@ -0,0 +1,13 @@ +#include "common.h" +#include "iostructs\v_portal.h" + +v2p _main (v_vert v) +{ + v2p o; + + o.hpos = mul (m_VP, v.pos); // xform, input in world coords + o.c = v.color; + o.fog = calc_fogging (v.pos); // fog, input in world coords + + return o; +} diff --git a/res/gamedata/shaders/glr1/postprocess.ps b/res/gamedata/shaders/glr1/postprocess.ps new file mode 100755 index 0000000000000000000000000000000000000000..0898d60739f6bd9d998aac432ec4377edce80fe9 GIT binary patch literal 1205 zcmcIj%WC5=6kSVSacMVpV&q4ro0`%^G7N!%45f=%3>d{$5`%3SS#DE?{`*`#oF+6~ zj_ifeJ?EZtAHJ=-vKcD@H>GS_*|Eb7y*=I4a?oll_3)=Jdi?H{iN`bQu7SK{J^f3` zfj7HvKuXz2bx+80^K|zNv+Zz{c4tJU}PwK@_}|W2Zfx>=l2T$f+X- zY!TU)MGhNMuwoeyT_*QH$n*E#%gyF#g>tC2<%38es7Bt@`t1Upo})3pM`zd3**Q8p zp#cJGJ*4kBoyC-nUA>d4g@LzyBUH8mG8D!|l7Agbzlhn?A2HumQWjfP?+>~Y!;n)N z|F?sw;a7bW4fWDR%j=E=FijuU5Ki-65M3ld9zcs@wjw0(bw_LVERIRY)P9@0*&1m2 z8Jaq1>Y&79fz&PE3rrlKz#N(3EMa%J5O~laud1TT9N6xRNnA;d4lEIq{=iK#@}VIi zrRousU Q%FSE(LdiAkC)7Lr2dAb<>Hq)$ literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/postprocess.s b/res/gamedata/shaders/glr1/postprocess.s new file mode 100755 index 00000000000..6c184473b22 --- /dev/null +++ b/res/gamedata/shaders/glr1/postprocess.s @@ -0,0 +1,9 @@ +-- normal pp +function normal (shader, t_base, t_second, t_detail) + shader:begin ("null","postprocess") + : fog (false) + : zb (false,false) + shader:sampler ("s_base0") :texture(t_rt) : clamp() : f_linear () + shader:sampler ("s_base1") :texture(t_rt) : clamp() : f_linear () + shader:sampler ("s_noise") :texture(t_noise) : f_linear () +end diff --git a/res/gamedata/shaders/glr1/postprocess_cm.s b/res/gamedata/shaders/glr1/postprocess_cm.s new file mode 100755 index 00000000000..9e4a4b3340c --- /dev/null +++ b/res/gamedata/shaders/glr1/postprocess_cm.s @@ -0,0 +1,25 @@ +-- normal color mapped pp +function normal (shader, t_base, t_second, t_detail) + shader:begin ("null","postprocess") + : fog (false) + : zb (false,false) +-- shader:sampler ("s_base0") :texture(t_rt) : clamp() : f_linear () +-- shader:sampler ("s_base1") :texture(t_rt) : clamp() : f_linear () + shader:sampler ("s_base0") :texture("$user$rendertarget_color_map") : clamp() : f_linear () + shader:sampler ("s_base1") :texture("$user$rendertarget_color_map") : clamp() : f_linear () + shader:sampler ("s_noise") :texture(t_noise) : f_linear () +end + +function l_special (shader, t_base, t_second, t_detail) + shader:begin ("null","postprocess_cm_pre") + : fog (false) + : zb (false,false) + shader:sampler ("s_distort") :texture(t_distort) : clamp() : f_linear () + shader:sampler ("s_base0") :texture(t_rt) : clamp() : f_linear () + shader:sampler ("s_base1") :texture(t_rt) : clamp() : f_linear () + shader:sampler ("s_noise") :texture(t_noise) : f_linear () +-- shader:sampler ("s_grad0") :texture("grad\\grad_red_yellow") : clamp() : f_linear () +-- shader:sampler ("s_grad1") :texture("grad\\grad_test1") : clamp() : f_linear () + shader:sampler ("s_grad0") :texture("$user$cmap0") : clamp() : f_linear () + shader:sampler ("s_grad1") :texture("$user$cmap1") : clamp() : f_linear () +end diff --git a/res/gamedata/shaders/glr1/postprocess_cm_pre.ps b/res/gamedata/shaders/glr1/postprocess_cm_pre.ps new file mode 100755 index 0000000000000000000000000000000000000000..638b2eb95e391bfd21755be05cb5d9a33a1966f7 GIT binary patch literal 716 zcmcJNKW~FD5XI;7r#K}GsE7hdCzLHqwhkRDAqNbxgt29timK{&ug#yPX@xq)3l`76 z_wLT#@~&+Ais7b|LdY(@Y{>TeAD71JzO?3570T_E_B!c1UP~>|P@!6;vm=5j&eX6Z zU)RzVt>VT?ZCBJr(`wDtYd>5sw5|6DP!^?ZU3paHggoADIct3818d0~TnNfL2yht{ zo-iaI1V$N@W`&~09MG~MI|2mr$Ra$&FKkG{d^!rgt%4&Qu#(oDTgX^9=csNawYwmR zcW#A_nV=m47qnrC$F2e6^dj^XWWnScCGk@jdapTeLDRoz`X4%lx=8m5lq+?rA;R(N s=<8L)@4i3y4czoLVK>w;cBq-{b%$dg`#B{_!`%4+xNCS2@{N3wFAhS|y#N3J literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/postprocess_d.ps b/res/gamedata/shaders/glr1/postprocess_d.ps new file mode 100755 index 0000000000000000000000000000000000000000..26ecaad21f96dc55b546b7eca1fc35f6be7c0da6 GIT binary patch literal 1354 zcmcIk%WB&|6kX4J#U6(xvfp%=P=o`UR1U4SO!UJ?t47?~?IdsLBPhc5&G={oz2mh-=p)7(fJ&m zpV0t;wI0&j-9BbYGEkbzTqn00vQV9B3)mPWmjT0^_3VCgO*BPiHc71ZorbS z#Id(*=E%>BRK;G2!%=s97}hx0|8_7n{17MJP%mAyrRYci(_+CRgwrPBaDBDp0W?45 zTS9`N@OKeB#?SnehVcojb=yE>T@PF%Jn$$CeoEudAuNFLdg6Ngis&MRi{y4>k;@EA zaQVVm9riO$_Ae)Moa`?SamH3aL|Y!XF@};$U1Y`)8pHj@gIy^ZD_Bk)-o61N!lcHU zEf)p8;ma^qLc>B1>sJ)NY}lZ2@p^m;LEXqwuLARs!svqhYN*J>*O;^=^Ky6C2fK3@ zt*|$)tQ=|QO6)x|dQNx&o^7mQRe7AQ;iEGt7y0RId*<5ZJ^S65Kam&>gE8D-Wnbnj z*A$d{j2+U5FJZpPwp9yb$0=jINiy{dg?)-kl9`K7d8VNUipvBpYa2bJcPI01b*ZP5=M^ literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/simple.vs b/res/gamedata/shaders/glr1/simple.vs new file mode 100755 index 00000000000..79107537ea4 --- /dev/null +++ b/res/gamedata/shaders/glr1/simple.vs @@ -0,0 +1,19 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; + float fog : FOG; +}; + +vf main (v_vert v) +{ + vf o; + + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + o.fog = calc_fogging (v.P); // fog, input in world coords + + return o; +} diff --git a/res/gamedata/shaders/glr1/simple_color.ps b/res/gamedata/shaders/glr1/simple_color.ps new file mode 100755 index 0000000000000000000000000000000000000000..29d30c149f153011972019078b883eeedb115bdf GIT binary patch literal 101 zcmY$+%uCKGO-WTyO3u&C&Ck=zP~uXCi)H2)mlTyImlVeo#207g7UZPHC+Fwn7lBl9 prRC%&mY67T#^)wx=5cB$K>5xJnq1XfoJFZ6rA2w1&emMDTmbEkAlm={ literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/simple_color.vs b/res/gamedata/shaders/glr1/simple_color.vs new file mode 100755 index 00000000000..41af65669e7 --- /dev/null +++ b/res/gamedata/shaders/glr1/simple_color.vs @@ -0,0 +1,18 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION ; + float4 C : COLOR0 ; +}; + +uniform float4 tfactor; +vf main (float4 P:POSITION) +{ + vf o; + + o.hpos = mul (m_WVP, P); // xform, input in world coords + o.C = tfactor; + + return o; +} diff --git a/res/gamedata/shaders/glr1/simple_point.vs b/res/gamedata/shaders/glr1/simple_point.vs new file mode 100755 index 00000000000..a7264319441 --- /dev/null +++ b/res/gamedata/shaders/glr1/simple_point.vs @@ -0,0 +1,13 @@ +#include "common.h" + +vf_point main (v_lmap v) +{ + vf_point o; + + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc +// o.tc0 = unpack_tc_base(v.tc0); // copy tc + o.color = calc_point (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere + + return o; +} diff --git a/res/gamedata/shaders/glr1/simple_spot.vs b/res/gamedata/shaders/glr1/simple_spot.vs new file mode 100755 index 00000000000..dce5b2706bb --- /dev/null +++ b/res/gamedata/shaders/glr1/simple_spot.vs @@ -0,0 +1,13 @@ +#include "common.h" + +vf_spot main (v_lmap v) +{ + vf_spot o; + + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc +// o.tc0 = unpack_tc_base(v.tc0); // copy tc + o.color = calc_spot (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere + + return o; +} diff --git a/res/gamedata/shaders/glr1/skin.h b/res/gamedata/shaders/glr1/skin.h new file mode 100755 index 00000000000..796a602b2c8 --- /dev/null +++ b/res/gamedata/shaders/glr1/skin.h @@ -0,0 +1,252 @@ +#ifndef SKIN_H +#define SKIN_H + +#include "common.h" +//RoH & SM+ +struct v_model_skinned_0 +{ + float4 P ; // POSITION; // (float,float,float,1) - quantized // short4 + float3 N ; // NORMAL; // normal // DWORD + float3 T ; // TANGENT; // tangent // DWORD + float3 B ; // BINORMAL; // binormal // DWORD + float2 tc ; // TEXCOORD0;// (u,v) // short2 +}; +struct v_model_skinned_1 // 24 bytes +{ + float4 P ; // POSITION; // (float,float,float,1) - quantized // short4 + float4 N ; // NORMAL; // (nx,ny,nz,index) // DWORD + float3 T ; // TANGENT; // tangent // DWORD + float3 B ; // BINORMAL; // binormal // DWORD + float2 tc ; // TEXCOORD0;// (u,v) // short2 +}; +struct v_model_skinned_2 // 28 bytes +{ + float4 P ; // POSITION; // (float,float,float,1) - quantized // short4 + float4 N ; // NORMAL; // (nx,ny,nz,weight) // DWORD + float3 T ; // TANGENT; // tangent // DWORD + float3 B ; // BINORMAL; // binormal // DWORD + float4 tc ; // TEXCOORD0; // (u,v, w=m-index0, z=m-index1) // short4 +}; + +struct v_model_skinned_3 // 28 bytes +{ + float4 P ; // POSITION; // (float,float,float,1) - quantized // short4 + float4 N ; // NORMAL; // (nx,ny,nz,weight0) // DWORD + float4 T ; // TANGENT; // (tx,ty,tz,weight1) // DWORD + float4 B ; // BINORMAL; // (bx,by,bz,m-index2) // DWORD + float4 tc ; // TEXCOORD0; // (u,v, w=m-index0, z=m-index1) // short4 +}; + +struct v_model_skinned_4 // 28 bytes +{ + float4 P ; // POSITION; // (float,float,float,1) - quantized // short4 + float4 N ; // NORMAL; // (nx,ny,nz,weight0) // DWORD + float4 T ; // TANGENT; // (tx,ty,tz,weight1) // DWORD + float4 B ; // BINORMAL; // (bx,by,bz,weight2) // DWORD + float2 tc ; // TEXCOORD0;// (u,v) // short2 + float4 ind ; // TEXCOORD1;// (x=m-index0, y=m-index1, z=m-index2, w=m-index3) // DWORD +}; + +////////////////////////////////////////////////////////////////////////////////////////// + +float4 u_position (float4 v) { return float4(v.xyz, 1.0); } // -12..+12 //--#SM+#-- + +////////////////////////////////////////////////////////////////////////////////////////// +//uniform float4 sbones_array [256-22] : register(vs,c22); +//tbuffer SkeletonBones +//{ +uniform float4 sbones_array [256-22]; +//} + +float3 skinning_dir (float3 dir, float4 m0, float4 m1, float4 m2) +{ + float3 U = unpack_normal (dir); + return float3 + ( + dot (m0.xyz, U), + dot (m1.xyz, U), + dot (m2.xyz, U) + ); +} +float4 skinning_pos (float4 pos, float4 m0, float4 m1, float4 m2) +{ + float4 P = u_position(pos); // -12..+12 //--#SM+#-- + return float4 + ( + dot (m0, P), + dot (m1, P), + dot (m2, P), + 1 + ); +} + +v_model skinning_0 (v_model_skinned_0 v) +{ + // Swizzle for D3DCOLOUR format + v.N = v.N.zyx; + v.T = v.T.zyx; + v.B = v.B.zyx; + + // skinning + v_model o; + o.P = u_position(v.P); // -12..+12 //--#SM+#-- + o.N = unpack_normal(v.N); + o.T = unpack_normal(v.T); + o.B = unpack_normal(v.B); + o.tc = v.tc; // -16..+16 //--#SM+#-- + return o; +} +v_model skinning_1 (v_model_skinned_1 v) +{ + // Swizzle for D3DCOLOUR format + v.N.xyz = v.N.zyx; + v.T.xyz = v.T.zyx; + v.B.xyz = v.B.zyx; + + // matrices + int mid = int(v.N.w * 255 + 0.3); + float4 m0 = sbones_array[mid+0]; + float4 m1 = sbones_array[mid+1]; + float4 m2 = sbones_array[mid+2]; + + // skinning + v_model o; + o.P = skinning_pos(v.P, m0,m1,m2 ); + o.N = skinning_dir(v.N.xyz, m0,m1,m2 ); + o.T = skinning_dir(v.T.xyz, m0,m1,m2 ); + o.B = skinning_dir(v.B.xyz, m0,m1,m2 ); + o.tc = v.tc; // -16..+16 //--#SM+#-- + return o; +} +v_model skinning_2 (v_model_skinned_2 v) +{ + // Swizzle for D3DCOLOUR format + v.N.xyz = v.N.zyx; + v.T.xyz = v.T.zyx; + v.B.xyz = v.B.zyx; + + // matrices + int id_0 = int(v.tc.z); + float4 m0_0 = sbones_array[id_0+0]; + float4 m1_0 = sbones_array[id_0+1]; + float4 m2_0 = sbones_array[id_0+2]; + int id_1 = int(v.tc.w); + float4 m0_1 = sbones_array[id_1+0]; + float4 m1_1 = sbones_array[id_1+1]; + float4 m2_1 = sbones_array[id_1+2]; + + // lerp + float w = v.N.w; + float4 m0 = lerp(m0_0,m0_1,w); + float4 m1 = lerp(m1_0,m1_1,w); + float4 m2 = lerp(m2_0,m2_1,w); + + // skinning + v_model o; + o.P = skinning_pos(v.P, m0,m1,m2 ); + o.N = skinning_dir(v.N.xyz, m0,m1,m2 ); + o.T = skinning_dir(v.T.xyz, m0,m1,m2 ); + o.B = skinning_dir(v.B.xyz, m0,m1,m2 ); + o.tc = v.tc.xy; // -16..+16 //--#SM+#-- + return o; +} +v_model skinning_3 (v_model_skinned_3 v) +{ + // Swizzle for D3DCOLOUR format + v.N.xyz = v.N.zyx; + v.T.xyz = v.T.zyx; + v.B.xyz = v.B.zyx; + + // matrices + int id_0 = int(v.tc.z); + float4 m0_0 = sbones_array[id_0+0]; + float4 m1_0 = sbones_array[id_0+1]; + float4 m2_0 = sbones_array[id_0+2]; + int id_1 = int(v.tc.w); + float4 m0_1 = sbones_array[id_1+0]; + float4 m1_1 = sbones_array[id_1+1]; + float4 m2_1 = sbones_array[id_1+2]; + int id_2 = int(v.B.w*255+0.3); + float4 m0_2 = sbones_array[id_2+0]; + float4 m1_2 = sbones_array[id_2+1]; + float4 m2_2 = sbones_array[id_2+2]; + + // lerp + float w0 = v.N.w; + float w1 = v.T.w; + float w2 = 1-w0-w1; + float4 m0 = m0_0*w0; + float4 m1 = m1_0*w0; + float4 m2 = m2_0*w0; + + m0 += m0_1*w1; + m1 += m1_1*w1; + m2 += m2_1*w1; + + m0 += m0_2*w2; + m1 += m1_2*w2; + m2 += m2_2*w2; + + // skinning + v_model o; + o.P = skinning_pos(v.P, m0,m1,m2 ); + o.N = skinning_dir(v.N.xyz, m0,m1,m2 ); + o.T = skinning_dir(v.T.xyz, m0,m1,m2 ); + o.B = skinning_dir(v.B.xyz, m0,m1,m2 ); + o.tc = v.tc.xy; // -16..+16 //--#SM+#-- +#ifdef SKIN_COLOR + o.rgb_tint = float3 (2,0,0) ; + if (id_0==id_1) o.rgb_tint = float3(1,2,0); +#endif + return o; +} +v_model skinning_4 (v_model_skinned_4 v) +{ + // Swizzle for D3DCOLOUR format + v.N.xyz = v.N.zyx; + v.T.xyz = v.T.zyx; + v.B.xyz = v.B.zyx; + v.ind.xyz = v.ind.zyx; + + // matrices + int id[4]; + mat3x4 m[4]; // [bone index][matrix row or column???] + + for (int i=0; i<4; ++i) + { + id[i] = int(v.ind[i]*255+0.3); + + for (int j=0; j<3; ++j) + m[i][j] = sbones_array[id[i]+j]; + } + + // lerp + float w[4]; + w[0] = v.N.w; + w[1] = v.T.w; + w[2] = v.B.w; + w[3] = 1-w[0]-w[1]-w[2]; + + float4 m0 = m[0][0]*w[0]; + float4 m1 = m[0][1]*w[0]; + float4 m2 = m[0][2]*w[0]; + + for (int i=1; i<4; ++i) + { + m0 += m[i][0]*w[i]; + m1 += m[i][1]*w[i]; + m2 += m[i][2]*w[i]; + } + + // skinning + v_model o; + o.P = skinning_pos(v.P, m0,m1,m2 ); + o.N = skinning_dir(v.N.xyz, m0,m1,m2 ); + o.T = skinning_dir(v.T.xyz, m0,m1,m2 ); + o.B = skinning_dir(v.B.xyz, m0,m1,m2 ); + o.tc = v.tc; // -16..+16 //--#SM+#-- + + return o; +} + +#endif diff --git a/res/gamedata/shaders/glr1/skin_main.h b/res/gamedata/shaders/glr1/skin_main.h new file mode 100755 index 00000000000..8eb565dc94c --- /dev/null +++ b/res/gamedata/shaders/glr1/skin_main.h @@ -0,0 +1,185 @@ +#ifndef SKIN_MAIN_INCLUDED +#define SKIN_MAIN_INCLUDED + +void main() +{ +#ifdef SKIN_NONE + v_model I; +#endif +#ifdef SKIN_0 + v_model_skinned_0 I; +#endif +#ifdef SKIN_1 + v_model_skinned_1 I; +#endif +#ifdef SKIN_2 + v_model_skinned_2 I; +#endif +#ifdef SKIN_3 + v_model_skinned_3 I; +#endif +#ifdef SKIN_4 + v_model_skinned_4 I; + I.ind = v_model_ind; +#endif + + I.P = v_model_P; + I.N = v_model_N; + I.T = v_model_T; + I.B = v_model_B; + I.tc = v_model_tc; + + v2p O; +#ifdef SKIN_NONE + O = _main(I); +#endif +#ifdef SKIN_0 + O = _main(skinning_0(I)); +#endif +#ifdef SKIN_1 + O = _main(skinning_1(I)); +#endif +#ifdef SKIN_2 + O = _main(skinning_2(I)); +#endif +#ifdef SKIN_3 + O = _main(skinning_3(I)); +#endif +#ifdef SKIN_4 + O = _main(skinning_4(I)); +#endif + + v2p_model_tc0 = O.tc0; + v2p_model_c0 = O.c0; + v2p_model_fog = O.fog; + gl_Position = O.hpos; +} +/* +////////////////////////////////////////////////////// +#ifdef SKIN_LQ +////////////////////////////////////////////////////// + +#ifdef SKIN_NONE +SKIN_VF main(v_model v) { return _main(v); } +#endif + +#ifdef SKIN_0 +SKIN_VF main(v_model_skinned_0 v) { return _main(skinning_0(v)); } +#endif + +#ifdef SKIN_1 +SKIN_VF main(v_model_skinned_1 v) { return _main(skinning_1(v)); } +#endif + +#ifdef SKIN_2 +SKIN_VF main(v_model_skinned_2 v) { return _main(skinning_2(v)); } +#endif + +#ifdef SKIN_3 +SKIN_VF main(v_model_skinned_3 v) { return _main(skinning_3(v)); } +#endif + +#ifdef SKIN_4 +SKIN_VF main(v_model_skinned_4 v) { return _main(skinning_4(v)); } +#endif + +////////////////////////////////////////////////////// +#else // SKIN_LQ +////////////////////////////////////////////////////// + +#ifdef SKIN_NONE +SKIN_VF main(v_model v) { return _main(v); } +#endif + +#ifdef SKIN_0 +SKIN_VF main(v_model_skinned_0 v) { return _main(skinning_0(v)); } +#endif + +#ifdef SKIN_1 +SKIN_VF main(v_model_skinned_1 v) { return _main(skinning_1(v)); } +#endif + +#ifdef SKIN_2 +SKIN_VF main(v_model_skinned_2 v) { return _main(skinning_2(v)); } +#endif + +#ifdef SKIN_3 +SKIN_VF main(v_model_skinned_3 v) { return _main(skinning_3(v)); } +#endif + +#ifdef SKIN_4 +SKIN_VF main(v_model_skinned_4 v) { return _main(skinning_4(v)); } +#endif + +////////////////////////////////////////////////////// +#endif // SKIN_LQ +////////////////////////////////////////////////////// +*/ +#endif // SKIN_MAIN_INCLUDED + +/* +#ifndef SKIN_MAIN_INCLUDED +#define SKIN_MAIN_INCLUDED + +////////////////////////////////////////////////////// +#ifdef SKIN_LQ +////////////////////////////////////////////////////// + +#ifdef SKIN_NONE +SKIN_VF main(v_model v) { return _main(v); } +#endif + +#ifdef SKIN_0 +SKIN_VF main(v_model_skinned_0 v) { return _main(skinning_0(v)); } +#endif + +#ifdef SKIN_1 +SKIN_VF main(v_model_skinned_1 v) { return _main(skinning_1(v)); } +#endif + +#ifdef SKIN_2 +SKIN_VF main(v_model_skinned_2 v) { return _main(skinning_2lq(v)); } +#endif + +#ifdef SKIN_3 +SKIN_VF main(v_model_skinned_3 v) { return _main(skinning_3lq(v)); } +#endif + +#ifdef SKIN_4 +SKIN_VF main(v_model_skinned_4 v) { return _main(skinning_4lq(v)); } +#endif + +////////////////////////////////////////////////////// +#else // SKIN_LQ +////////////////////////////////////////////////////// + +#ifdef SKIN_NONE +SKIN_VF main(v_model v) { return _main(v); } +#endif + +#ifdef SKIN_0 +SKIN_VF main(v_model_skinned_0 v) { return _main(skinning_0(v)); } +#endif + +#ifdef SKIN_1 +SKIN_VF main(v_model_skinned_1 v) { return _main(skinning_1(v)); } +#endif + +#ifdef SKIN_2 +SKIN_VF main(v_model_skinned_2 v) { return _main(skinning_2(v)); } +#endif + +#ifdef SKIN_3 +SKIN_VF main(v_model_skinned_3 v) { return _main(skinning_3(v)); } +#endif + +#ifdef SKIN_4 +SKIN_VF main(v_model_skinned_4 v) { return _main(skinning_4(v)); } +#endif + +////////////////////////////////////////////////////// +#endif // SKIN_LQ +////////////////////////////////////////////////////// + +#endif // SKIN_MAIN_INCLUDED +*/ \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/sky2.ps b/res/gamedata/shaders/glr1/sky2.ps new file mode 100755 index 0000000000000000000000000000000000000000..50b28cd467c11306ae0cf6883287cf99ed815e10 GIT binary patch literal 460 zcmcJLOH0E*5P;9KzhY=FiG)p}o(x_L9s)u|@FtXW-L#AQ2>Z}f@xQwpi;o_>ImelA zUf)t^Cc`7g1v5$+O?L~j{K^UAyba8|hjHzm_NhpM7K5=0U9U#TZ5uWm!KHH5lqFoC z9l`6 fiE77auyCp2kbjAS2w3ie)rj-Ckj362nR_Q6NKArw literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/sky2.vs b/res/gamedata/shaders/glr1/sky2.vs new file mode 100755 index 00000000000..bd1a73fa571 --- /dev/null +++ b/res/gamedata/shaders/glr1/sky2.vs @@ -0,0 +1,16 @@ +#include "common.h" +#include "iostructs\v_sky.h" + +v2p _main (vi v) +{ + v2p o; + + float4 tpos = mul (1000, v.p); + o.hpos = mul (m_WVP, tpos); // xform, input in world coords, 1000 - magic number + o.hpos.z = o.hpos.w; + o.c = v.c; // copy color + o.tc0 = v.tc0; // copy tc + o.tc1 = v.tc1; // copy tc + + return o; +} diff --git a/res/gamedata/shaders/glr1/stub_default.ps b/res/gamedata/shaders/glr1/stub_default.ps new file mode 100755 index 0000000000000000000000000000000000000000..257c7e6ab1b69b4312c6a19962d77cb721c11495 GIT binary patch literal 339 zcmcJJy$ZrG6ou#JDK72Oiq;}J6$jC!;2>I@gb?Gc4Wvy;QYeV;Zi1z&lXpBn-#w9N zx$GYZAy-YK+O!TyG-*N^t9x$Et)u19dt~{yb7(k;0VS!VVs;I*VWNc?{BI~A0T;Mj zY02~xEqReZqwRGI7Kha#21D=6;2esy#36%ZR-}6+mCpU>U}S1Eu>IX|1ujJwyZEA^ ZJK5Fjj8&3*(qv@m=Btc5TsS9h@&QR@Tkrq? literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/stub_default.s b/res/gamedata/shaders/glr1/stub_default.s new file mode 100755 index 00000000000..8115644eabf --- /dev/null +++ b/res/gamedata/shaders/glr1/stub_default.s @@ -0,0 +1,4 @@ +function normal (shader, t_base, t_second, t_detail) + shader:begin ("stub_default","stub_default") + shader:sampler ("s_base") : texture(t_base) : clamp() : f_linear () +end \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/stub_default.vs b/res/gamedata/shaders/glr1/stub_default.vs new file mode 100755 index 00000000000..4c18dc5f53d --- /dev/null +++ b/res/gamedata/shaders/glr1/stub_default.vs @@ -0,0 +1,15 @@ +#include "common.h" +#include "iostructs\v_TL.h" + +////////////////////////////////////////////////////////////////////////////////////////// +// Vertex +v2p_TL _main ( v_TL I) +{ + v2p_TL O; + + O.HPos = mul( m_WVP, I.P); + O.Tex0 = I.Tex0; + O.Color = unpack_D3DCOLOR(I.Color); + + return O; +} \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/stub_default_ma.ps b/res/gamedata/shaders/glr1/stub_default_ma.ps new file mode 100644 index 0000000000000000000000000000000000000000..5941235d6befeb759bc75aece16e854c2a01f453 GIT binary patch literal 492 zcmcIhO>4s-7(VN-cxf+oWHu|?spK%$OJRqxg`EasGusLpMGXYT{`+1V=>|DZ@Zj_D z`aHVSeP@PG1&hvE>w11((B&1=E~YSaDSmj-K4*@u*R2}U5Y%P|Q5jH z$3``*au0$E9!>{B8o)lDA^YTv3mL4Su-P-A5?yo8Om;EPJd%)`=6BRKKQ8Hv_6!Hy oTJdQ7S-z^{l`~i`CEq+6vGnM3*t2JAOr8D28PN%pPM1DR?V1=qWrz?5c^uI{hMRbHdD6{wX^Is=Gfa+i#} zA%8*-REe>x$UU*{J_MHyV*GE*T}`k3nG0N-8>(KGqbXU*ARyX%TShpY9*EEL*Rd=wr!+^B@TvwQoRJ+o zfMfYyUea7%xrikH_Ixxy>ZfUBYPTm^Rom(@RNHEch`u@tu5e)J<28cC9tD1m??{yLDbe(yp$+{bzpf_&pEg9}33JV*~`LXgzFZl!K C-B>dK literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/vert.vs b/res/gamedata/shaders/glr1/vert.vs new file mode 100755 index 00000000000..a6923aae762 --- /dev/null +++ b/res/gamedata/shaders/glr1/vert.vs @@ -0,0 +1,29 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; + float3 c0 : COLOR0; // c0=all lighting + float fog : FOG; +}; + +vf main (v_vert v) +{ + vf o; + + float3 N = unpack_normal (v.N); + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc +// o.tc0 = unpack_tc_base (v.tc); // copy tc + + float3 L_rgb = v.color.xyz; // precalculated RGB lighting + float3 L_hemi = v_hemi(N)*v.N.w; // hemisphere + float3 L_sun = v_sun(N)*v.color.w; // sun + float3 L_final = L_rgb + L_hemi + L_sun + L_ambient; + + o.c0 = L_final; + o.fog = calc_fogging (v.P); // fog, input in world coords + + return o; +} diff --git a/res/gamedata/shaders/glr1/vert_dt.ps b/res/gamedata/shaders/glr1/vert_dt.ps new file mode 100755 index 0000000000000000000000000000000000000000..04e210cc54a7b43fdcc01b30fabb2d66a380a8e0 GIT binary patch literal 512 zcmcJLPiuof5XH|kpJGTaYGrker$|pp4?@8bdgx6y>n0KW6Lc+slJDMiS6aV7_cF`l zH;?z`sqSPmRf;yUZ`;0O*A3#Rhe>LJujGc`NN^R+IU&$8-VuDfe(sCnc!)EIB07mt ztqHy&_=<2QDHsdb7jMNe&X9gZzKA@-M}`>v+cVbmUf)%NbElM`6?IqM#*&vDJTiqT zCm(iXGn(?YdkVUoixRw$R`=up;Eh%Zb7rpMXMbE}?zW~XrA6IXjvLN_TLP!gXj$nX zXEJ7jp2>VT6N}##&UGi6+0b(dEEpty;MRj=b~K&(Nh1tOPeVs!tAS^C*$}#US>`Ep KPE43I5BvdY!G#C_ literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/vert_dt.vs b/res/gamedata/shaders/glr1/vert_dt.vs new file mode 100755 index 00000000000..4ca34d49d91 --- /dev/null +++ b/res/gamedata/shaders/glr1/vert_dt.vs @@ -0,0 +1,35 @@ +#include "common.h" + +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; + float2 tc1 : TEXCOORD1; // detail + float4 c0 : COLOR0; // c0=all lighting + float4 c1 : COLOR1; // ps_1_1 read ports + float fog : FOG; +}; + +vf main (v_vert v) +{ + vf o; + + float3 N = unpack_normal (v.N); + o.hpos = mul (m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc +// o.tc0 = unpack_tc_base (v.tc); // copy tc + o.tc1 = o.tc0*dt_params; // dt tc + + float3 L_rgb = v.color.xyz; // precalculated RGB lighting + float3 L_hemi = v_hemi(N)*v.N.w; // hemisphere + float3 L_sun = v_sun(N)*v.color.w; // sun + float3 L_final = L_rgb + L_hemi + L_sun + L_ambient; + + float2 dt = calc_detail (v.P); + + o.c0 = float4(L_final.x,L_final.y,L_final.z,dt.x); + o.c1 = dt.y; // + o.fog = calc_fogging (v.P); // fog, input in world coords + + return o; +} diff --git a/res/gamedata/shaders/glr1/vert_l.ps b/res/gamedata/shaders/glr1/vert_l.ps new file mode 100755 index 0000000000000000000000000000000000000000..bfb6633da28152bd6c2b0c4e720141035ae8c2cd GIT binary patch literal 217 zcmY$+%uCKGO-WTyO3u&C&Ck=zP~ze$E-5NaE>YktGb-S!=2B4L%t*{hGvQ1&u;O&~ z_wf%hu;!|@=HlYgrx^emtq_n|k($E=wpxKRH!(9WzMweXFy4?;LjmY81y2P{PAdhl Xdw`DQEJ`gYEy`0+@YG8NIgbkfAH^*aB2jztGUUx&T0pJw3{D-4c3RT2tnf?~NTp90U`?XHf{U%HR z=5sJ{M=pqz_2~|bEQn#pEmIFA3*-{?8vKg!k$!6*p5XvA3hB>a6Xv zD2o6*GbQX`3a|od1V`qKSf(>G7h^A=y|{tI7Yz-Ryf literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/water.vs b/res/gamedata/shaders/glr1/water.vs new file mode 100755 index 00000000000..ce7a82a282a --- /dev/null +++ b/res/gamedata/shaders/glr1/water.vs @@ -0,0 +1,41 @@ +#include "common.h" +#include "shared\waterconfig.h" +#include "shared\watermove.h" + +struct vf +{ + float4 hpos : POSITION ; + float2 tbase : TEXCOORD0 ; + float3 tenv : TEXCOORD1 ; + float4 c0 : COLOR0 ; // c0=all lighting, c0.a = refl amount + float fog : FOG; +}; + +vf main (v_vert v) +{ + vf o; + + float4 P = v.P; + float3 N = unpack_normal (v.N); + + P = watermove (P); + + float2 tc_base = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + + float amount ; + float3 tc_refl = waterrefl (amount, P,N); + + o.tbase = tc_base; + o.tenv = tc_refl; + + float3 L_rgb = v.color.xyz; // precalculated RGB lighting + float3 L_hemi = v_hemi(N)*v.N.w; // hemisphere + float3 L_sun = v_sun(N)*v.color.w; // sun + float3 L_final = L_rgb + L_hemi + L_sun + L_ambient; + + o.hpos = mul (m_VP, P); // xform, input in world coords + o.c0 = float4 (L_final,amount); + o.fog = calc_fogging (P); // fog, input in world coords + + return o; +} diff --git a/res/gamedata/shaders/glr1/waterd.ps b/res/gamedata/shaders/glr1/waterd.ps new file mode 100755 index 0000000000000000000000000000000000000000..a73e1f1512390384a3a3ac0cbee3846663bcabdd GIT binary patch literal 844 zcmcJNUu)Yi6vdyVPjP8q?9Ou}FJ(}(r=|~qflC_b9tJ{*mB!$INOBi8`rUW0?4%xy zy-i?aOTTk<&ylXHc3%&rfvbJjG+mn>ulV(4&KnF{h|zXT8Y(wJLMI_-_MC!((+aHK!z&tkG4gdZ(n4ETWKL4Kcfe`{HY{ zIS006UQsrTeF1MyXeDxCA^~9QG^7a-qv>TwOT)Ii_KO&7S9ix$tSRpFFTJsy(4Pn)2O5}iHMW* z^DT>WY+vBl7!WXB_eV{wkwfyPcMeTXN-Tvg!X54g&#m!;Z6WwvqK~j^B9c%9!8iUJ D(dy_7 literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/waterd.vs b/res/gamedata/shaders/glr1/waterd.vs new file mode 100755 index 00000000000..57575056d70 --- /dev/null +++ b/res/gamedata/shaders/glr1/waterd.vs @@ -0,0 +1,27 @@ +#include "common.h" +#include "shared\waterconfig.h" +#include "shared\watermove.h" + +struct vf +{ + float4 hpos : POSITION ; + float2 tbase : TEXCOORD0 ; + float2 tdist0 : TEXCOORD1 ; + float2 tdist1 : TEXCOORD2 ; +}; + +vf main (v_vert v) +{ + vf o; + + float4 P = v.P; + float3 N = unpack_normal (v.N); + P = watermove (P); + + o.tbase = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + o.tdist0 = watermove_tc (o.tbase*W_DISTORT_BASE_TILE_0, P.xz, W_DISTORT_AMP_0); + o.tdist1 = watermove_tc (o.tbase*W_DISTORT_BASE_TILE_1, P.xz, W_DISTORT_AMP_1); + o.hpos = mul (m_VP, P); // xform, input in world coords + + return o; +} diff --git a/res/gamedata/shaders/glr1/wmark.vs b/res/gamedata/shaders/glr1/wmark.vs new file mode 100755 index 00000000000..5559cd877ab --- /dev/null +++ b/res/gamedata/shaders/glr1/wmark.vs @@ -0,0 +1,65 @@ +#include "common.h" +#include "shared\wmark.h" + +// for multiplicative decal + +// For alpha-blend decal +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; + float4 c0 : COLOR0; // c0=all lighting + float fog : FOG; +}; + +vf main (v_vert v) +{ + vf o; + + float3 N = unpack_normal (v.N); + float4 P = wmark_shift (v.P,N); + o.hpos = mul (m_VP, P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + + float3 L_rgb = v.color.xyz; // precalculated RGB lighting + float3 L_hemi = v_hemi(N)*v.N.w; // hemisphere + float3 L_sun = v_sun(N)*v.color.w; // sun + float3 L_final = L_rgb + L_hemi + L_sun + L_ambient; + + o.c0.rgb = L_final; + o.c0.a = calc_fogging (P); // fog, input in world coords + o.fog = 1; // fog, input in world coords + + return o; +} + +/* +// For alpha-blend decal +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; + float3 c0 : COLOR0; // c0=all lighting + float fog : FOG; +}; + +vf main (v_vert v) +{ + vf o; + + float3 N = unpack_normal (v.N); + float4 P = wmark_shift (v.P,N); + o.hpos = mul (m_VP, P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + + float3 L_rgb = v.color.xyz; // precalculated RGB lighting + float3 L_hemi = v_hemi(N)*v.N.w; // hemisphere + float3 L_sun = v_sun(N)*v.color.w; // sun + float3 L_final = L_rgb + L_hemi + L_sun + L_ambient; + + o.c0 = L_final; + o.fog = calc_fogging (P); // fog, input in world coords + + return o; +} +*/ \ No newline at end of file diff --git a/res/gamedata/shaders/glr1/wmark_point.vs b/res/gamedata/shaders/glr1/wmark_point.vs new file mode 100755 index 00000000000..cc188a818f7 --- /dev/null +++ b/res/gamedata/shaders/glr1/wmark_point.vs @@ -0,0 +1,15 @@ +#include "common.h" +#include "shared\wmark.h" + +vf_point main (v_vert v) +{ + vf_point o; + + float3 N = unpack_normal (v.N); + float4 P = wmark_shift (v.P,N); + o.hpos = mul (m_VP, P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + o.color = calc_point (o.tc1,o.tc2,P,N); // just hemisphere + + return o; +} diff --git a/res/gamedata/shaders/glr1/wmark_spot.vs b/res/gamedata/shaders/glr1/wmark_spot.vs new file mode 100755 index 00000000000..dcf6578c91c --- /dev/null +++ b/res/gamedata/shaders/glr1/wmark_spot.vs @@ -0,0 +1,15 @@ +#include "common.h" +#include "shared\wmark.h" + +vf_spot main (v_vert v) +{ + vf_spot o; + + float3 N = unpack_normal (v.N); + float4 P = wmark_shift (v.P,N); + o.hpos = mul (m_VP, P); // xform, input in world coords + o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + o.color = calc_spot (o.tc1,o.tc2,P,N); // just hemisphere + + return o; +} diff --git a/res/gamedata/shaders/glr1/wmarkmult.ps b/res/gamedata/shaders/glr1/wmarkmult.ps new file mode 100755 index 0000000000000000000000000000000000000000..f986e00f143f81c2d5c543b79d17526ecfe9cab1 GIT binary patch literal 362 zcmcJKv1-FG6h-IvzT%NCHW*oPlO-lo(!mgL2pzf^MOAHqtQbiSfs%i(l#oxT1}*2l z%RO(}N;7{eTFA>dUMw3Hh(5Sk27+rf;V%*l!u(VOLGlg3=f~HsZBKh%Ls`;Uc!iI^ z3P5t$(5^kSrw9|3d@GD0qx&If+vB}P#PZ)>tfr&BDT8V8ieMDlc9ZXx-4Zg2I@D19 z+8EWI!^tU6TMFt{?IH7Baw-}Yb@Lh_LgxB&3>f96j8gS`#@V`{*OwQmBBcsynB+`6 N55w$iA~oI-{{S_ETNMBR literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/glr1/yuv2rgb.ps b/res/gamedata/shaders/glr1/yuv2rgb.ps new file mode 100755 index 0000000000000000000000000000000000000000..68f9a1651a770e0162619c78531a0cddbeafbf90 GIT binary patch literal 856 zcmZ{hT~C8B6hNPEe?_A&d|3GG=KW!+|7#P(? zN=FP*WRMh}S7s6qlaFyi>k#w)tK~QfMX07y8EgWY78`a4Cl3IC9=YqK7DVfhkQ6fD z$el?sSx6Pl0`Mat!%`aV07=BY89VpbYgU(2pgY%ZI~{2WPJcEk!Y{2> zaLI3$_sbQ9A?g1vbOIvABzWD&fnB60Oc0DVAXbkO25$&*+;!;D2f-qE Date: Tue, 10 May 2022 02:29:45 +0300 Subject: [PATCH 4/9] Big commit, define changes to match glr1 and r1/dx9 --- src/Layers/xrRender/Blender_Recorder.cpp | 4 +-- src/Layers/xrRender/Blender_Recorder.h | 2 +- src/Layers/xrRender/Blender_Recorder_R2.cpp | 2 +- .../Blender_Recorder_StandartBinding.cpp | 4 +-- src/Layers/xrRender/ColorMapManager.cpp | 6 ++-- src/Layers/xrRender/D3DXRenderBase.cpp | 6 ++-- src/Layers/xrRender/D3DXRenderBase.h | 8 ++--- src/Layers/xrRender/Debug/dxPixEventWrapper.h | 2 +- src/Layers/xrRender/DetailManager.h | 4 +-- .../xrRender/DetailManager_Decompress.cpp | 2 +- src/Layers/xrRender/DetailManager_VS.cpp | 2 +- src/Layers/xrRender/FProgressive.cpp | 4 +-- src/Layers/xrRender/FTreeVisual.cpp | 6 ++-- src/Layers/xrRender/FVF.h | 2 +- src/Layers/xrRender/FVisual.cpp | 4 +-- src/Layers/xrRender/HOM.cpp | 2 +- src/Layers/xrRender/LightTrack.cpp | 24 +++++++------- src/Layers/xrRender/LightTrack.h | 4 +-- src/Layers/xrRender/Light_DB.cpp | 6 ++-- src/Layers/xrRender/Light_DB.h | 2 +- src/Layers/xrRender/ParticleEffect.cpp | 2 +- src/Layers/xrRender/QueryHelper.h | 4 +-- src/Layers/xrRender/R_Backend.h | 23 +++++++------ src/Layers/xrRender/R_Backend_DBG.cpp | 12 +++---- src/Layers/xrRender/R_Backend_Runtime.cpp | 18 +++++++---- src/Layers/xrRender/R_Backend_Runtime.h | 7 ++-- src/Layers/xrRender/ResourceManager.cpp | 6 ++-- src/Layers/xrRender/ResourceManager.h | 4 +-- src/Layers/xrRender/SH_Atomic.cpp | 6 ++-- src/Layers/xrRender/SH_Atomic.h | 8 +++-- src/Layers/xrRender/SH_RT.h | 2 +- src/Layers/xrRender/SH_Texture.h | 8 ++--- src/Layers/xrRender/ShaderResourceTraits.h | 26 +++++++-------- .../xrRender/blenders/BlenderDefault.cpp | 2 +- src/Layers/xrRender/blenders/Blender_Blur.cpp | 2 +- .../xrRender/blenders/Blender_LaEmB.cpp | 2 +- .../xrRender/blenders/Blender_Lm(EbB).cpp | 2 +- .../xrRender/blenders/Blender_Screen_GRAY.cpp | 2 +- .../blenders/Blender_Shadow_World.cpp | 2 +- .../xrRender/blenders/Blender_Vertex.cpp | 2 +- .../xrRender/blenders/Blender_Vertex_aref.cpp | 2 +- src/Layers/xrRender/blenders/uber_deffer.cpp | 2 +- src/Layers/xrRender/dxEnvironmentRender.cpp | 15 +++++---- src/Layers/xrRender/dxEnvironmentRender.h | 2 +- src/Layers/xrRender/dxStatGraphRender.cpp | 2 +- src/Layers/xrRender/light.cpp | 2 +- src/Layers/xrRender/r__dsgraph_build.cpp | 32 +++++++++---------- src/Layers/xrRender/r__dsgraph_render.cpp | 18 +++++------ src/Layers/xrRender/r__dsgraph_types.h | 11 ++++--- src/Layers/xrRender/r__occlusion.h | 4 +-- src/Layers/xrRender/r__pixel_calculator.cpp | 4 +-- src/Layers/xrRender/r__screenshot.cpp | 8 ++--- src/Layers/xrRender/r_constants.cpp | 4 +-- src/Layers/xrRender/r_constants.h | 8 ++--- src/Layers/xrRender/r_constants_cache.h | 2 ++ src/Layers/xrRender/stats_manager.cpp | 2 +- src/Layers/xrRender/tss_def.cpp | 4 ++- src/Layers/xrRender/tss_def.h | 2 ++ src/Layers/xrRender/xrRender_console.cpp | 20 ++++++------ src/Layers/xrRender/xr_effgamma.cpp | 2 +- src/Layers/xrRender/xr_effgamma.h | 2 +- src/Layers/xrRender_R2/r2.cpp | 14 ++++---- src/Layers/xrRender_R2/r2_R_render.cpp | 4 +-- 63 files changed, 212 insertions(+), 190 deletions(-) diff --git a/src/Layers/xrRender/Blender_Recorder.cpp b/src/Layers/xrRender/Blender_Recorder.cpp index f63619b778e..7fd8118fcbc 100644 --- a/src/Layers/xrRender/Blender_Recorder.cpp +++ b/src/Layers/xrRender/Blender_Recorder.cpp @@ -96,7 +96,7 @@ void CBlender_Compile::_cpp_Compile(ShaderElement* _SH) bDetail_Bump = false; #ifndef _EDITOR -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) if (RImplementation.o.no_detail_textures) bDetail = false; #endif @@ -107,7 +107,7 @@ void CBlender_Compile::_cpp_Compile(ShaderElement* _SH) RImplementation.Resources->m_textures_description.GetTextureUsage(base, bDetail_Diffuse, bDetail_Bump); #ifndef _EDITOR -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) // Detect the alowance of detail bump usage here. if (!(RImplementation.o.advancedpp && ps_r2_ls_flags.test(R2FLAG_DETAIL_BUMP))) { diff --git a/src/Layers/xrRender/Blender_Recorder.h b/src/Layers/xrRender/Blender_Recorder.h index 399eb150cee..7b2d83b15e9 100644 --- a/src/Layers/xrRender/Blender_Recorder.h +++ b/src/Layers/xrRender/Blender_Recorder.h @@ -174,7 +174,7 @@ class CBlender_Compile void r_Sampler_clf(LPCSTR name, LPCSTR texture, bool b_ps1x_ProjectiveDivide = false); void r_Sampler_clw(LPCSTR name, LPCSTR texture, bool b_ps1x_ProjectiveDivide = false); -#ifdef USE_OGL +#if defined(USE_OGL) || defined(USE_OGLR1) void i_Comparison(u32 s, u32 func); void r_Sampler_cmp(pcstr name, pcstr texture, bool b_ps1x_ProjectiveDivide = false); #endif // USE_OGL diff --git a/src/Layers/xrRender/Blender_Recorder_R2.cpp b/src/Layers/xrRender/Blender_Recorder_R2.cpp index a932e52020b..7107da71e12 100644 --- a/src/Layers/xrRender/Blender_Recorder_R2.cpp +++ b/src/Layers/xrRender/Blender_Recorder_R2.cpp @@ -137,7 +137,7 @@ u32 CBlender_Compile::r_Sampler( { #if defined(USE_DX11) r_dx10Texture(_name, texture, true); -#elif defined(USE_DX9) || defined(USE_OGL) +#elif defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) i_Texture(dwStage, texture); #else # error No graphics API selected or enabled! diff --git a/src/Layers/xrRender/Blender_Recorder_StandartBinding.cpp b/src/Layers/xrRender/Blender_Recorder_StandartBinding.cpp index 6a899a63b40..58c83bc29e6 100644 --- a/src/Layers/xrRender/Blender_Recorder_StandartBinding.cpp +++ b/src/Layers/xrRender/Blender_Recorder_StandartBinding.cpp @@ -86,7 +86,7 @@ class cl_texgen : public R_constant_setup 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f }; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) Fmatrix mTexelAdjust = { 0.5f, 0.0f, 0.0f, 0.0f, @@ -130,7 +130,7 @@ class cl_VPtexgen : public R_constant_setup 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f }; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) Fmatrix mTexelAdjust = { 0.5f, 0.0f, 0.0f, 0.0f, diff --git a/src/Layers/xrRender/ColorMapManager.cpp b/src/Layers/xrRender/ColorMapManager.cpp index aaa967a6b96..01917bbfc0f 100644 --- a/src/Layers/xrRender/ColorMapManager.cpp +++ b/src/Layers/xrRender/ColorMapManager.cpp @@ -30,7 +30,7 @@ void ColorMapManager::UpdateTexture(const shared_str& strTexName, int iTex) ID3DBaseTexture* e0 = I->second->surface_get(); m_CMap[iTex]->surface_set(e0); _RELEASE(e0); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) GLuint e0 = I->second->surface_get(); m_CMap[iTex]->surface_set(GL_TEXTURE_2D, e0); #else @@ -48,7 +48,7 @@ void ColorMapManager::UpdateTexture(const shared_str& strTexName, int iTex) ID3DBaseTexture* e0 = tmp->surface_get(); m_CMap[iTex]->surface_set(e0); _RELEASE(e0); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) GLuint e0 = tmp->surface_get(); m_CMap[iTex]->surface_set(GL_TEXTURE_2D, e0); #else @@ -60,7 +60,7 @@ void ColorMapManager::UpdateTexture(const shared_str& strTexName, int iTex) { #if defined(USE_DX9) || defined(USE_DX11) m_CMap[iTex]->surface_set(nullptr); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) m_CMap[iTex]->surface_set(GL_TEXTURE_2D, 0); #else # error No graphics API selected or in use! diff --git a/src/Layers/xrRender/D3DXRenderBase.cpp b/src/Layers/xrRender/D3DXRenderBase.cpp index 677eb557482..2077bd08f14 100644 --- a/src/Layers/xrRender/D3DXRenderBase.cpp +++ b/src/Layers/xrRender/D3DXRenderBase.cpp @@ -22,7 +22,7 @@ void D3DXRenderBase::setGamma(float fGamma) { #if defined(USE_DX9) || defined(USE_DX11) m_Gamma.Gamma(fGamma); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) UNUSED(fGamma); #else # error No graphics API selected or in use! @@ -33,7 +33,7 @@ void D3DXRenderBase::setBrightness(float fGamma) { #if defined(USE_DX9) || defined(USE_DX11) m_Gamma.Brightness(fGamma); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) UNUSED(fGamma); #else # error No graphics API selected or in use! @@ -44,7 +44,7 @@ void D3DXRenderBase::setContrast(float fGamma) { #if defined(USE_DX9) || defined(USE_DX11) m_Gamma.Contrast(fGamma); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) UNUSED(fGamma); #else # error No graphics API selected or in use! diff --git a/src/Layers/xrRender/D3DXRenderBase.h b/src/Layers/xrRender/D3DXRenderBase.h index 1ef15248c9c..6c2c583b297 100644 --- a/src/Layers/xrRender/D3DXRenderBase.h +++ b/src/Layers/xrRender/D3DXRenderBase.h @@ -38,7 +38,7 @@ class D3DXRenderBase : public IRender, public pureFrame R_dsgraph::mapSorted_T mapDistort; R_dsgraph::mapHUD_T mapHUDSorted; -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) R_dsgraph::mapSorted_T mapWmark; // sorted R_dsgraph::mapSorted_T mapEmissive; R_dsgraph::mapSorted_T mapHUDEmissive; @@ -46,7 +46,7 @@ class D3DXRenderBase : public IRender, public pureFrame // Runtime structures xr_vector nrmVS; -#ifndef USE_DX9 +#if !defined(USE_DX9) && !defined(USE_OGLR1) xr_vector nrmGS; #endif xr_vector nrmPS; @@ -56,7 +56,7 @@ class D3DXRenderBase : public IRender, public pureFrame xr_vector nrmTexturesTemp; xr_vector matVS; -#ifndef USE_DX9 +#if !defined(USE_DX9) && !defined(USE_OGLR1) xr_vector matGS; #endif xr_vector matPS; @@ -135,7 +135,7 @@ class D3DXRenderBase : public IRender, public pureFrame mapDistort.clear(); mapHUDSorted.clear(); -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) mapWmark.clear(); mapEmissive.clear(); mapHUDEmissive.clear(); diff --git a/src/Layers/xrRender/Debug/dxPixEventWrapper.h b/src/Layers/xrRender/Debug/dxPixEventWrapper.h index d3e136591b8..52fd9c6f179 100644 --- a/src/Layers/xrRender/Debug/dxPixEventWrapper.h +++ b/src/Layers/xrRender/Debug/dxPixEventWrapper.h @@ -12,7 +12,7 @@ class dxPixEventWrapper dxPixEventWrapper(const wchar_t* wszName) { HW.BeginPixEvent(wszName); } ~dxPixEventWrapper() { HW.EndPixEvent(); } }; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) # define PIX_EVENT(Name) dxPixEventWrapper pixEvent##Name(#Name) class dxPixEventWrapper diff --git a/src/Layers/xrRender/DetailManager.h b/src/Layers/xrRender/DetailManager.h index 001b0e76902..56f47d68113 100644 --- a/src/Layers/xrRender/DetailManager.h +++ b/src/Layers/xrRender/DetailManager.h @@ -61,7 +61,7 @@ class ECORE_API CDetailManager u32 vis_ID; // индекс в visibility списке он же тип [не качается, качается1, качается2] float c_hemi; float c_sun; -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) Fvector c_rgb; #endif }; @@ -191,7 +191,7 @@ class ECORE_API CDetailManager void hw_Render(); #if defined(USE_DX9) void hw_Render_dump(ref_constant array, u32 var_id, u32 lod_id, u32 c_base); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) void hw_Render_dump(const Fvector4& consts, const Fvector4& wave, const Fvector4& wind, u32 var_id, u32 lod_id); #else # error No graphics API selected or enabled! diff --git a/src/Layers/xrRender/DetailManager_Decompress.cpp b/src/Layers/xrRender/DetailManager_Decompress.cpp index 7d99bda2ae4..186bae8622d 100644 --- a/src/Layers/xrRender/DetailManager_Decompress.cpp +++ b/src/Layers/xrRender/DetailManager_Decompress.cpp @@ -257,7 +257,7 @@ gray255[3] = 255.f*float(c_pal->a3)/15.f; // int c_dw = 255; //iFloor (c_f); // clamp (c_dw,0,255); // Item.C_dw = color_rgba (c_dw,c_dw,c_dw,255); -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) Item.c_rgb.x = DS.r_qclr(DS.c_r, 15); Item.c_rgb.y = DS.r_qclr(DS.c_g, 15); Item.c_rgb.z = DS.r_qclr(DS.c_b, 15); diff --git a/src/Layers/xrRender/DetailManager_VS.cpp b/src/Layers/xrRender/DetailManager_VS.cpp index 0df2d7c744c..9b7e17f47a2 100644 --- a/src/Layers/xrRender/DetailManager_VS.cpp +++ b/src/Layers/xrRender/DetailManager_VS.cpp @@ -243,7 +243,7 @@ void CDetailManager::hw_Render_dump(ref_constant x_array, u32 var_id, u32 lod_id c_storage[base + 2].set(M._13 * scale, M._23 * scale, M._33 * scale, M._43); // Build color -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) Fvector C; C.set(c_ambient); // C.mad (c_lmap,Instance.c_rgb); diff --git a/src/Layers/xrRender/FProgressive.cpp b/src/Layers/xrRender/FProgressive.cpp index 8ece859788f..f39c863c173 100644 --- a/src/Layers/xrRender/FProgressive.cpp +++ b/src/Layers/xrRender/FProgressive.cpp @@ -46,7 +46,7 @@ void FProgressive::Load(const char* N, IReader* data, u32 dwFlags) lods().r(nSWI.sw, nSWI.count * sizeof(FSlideWindow)); // fast -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) if (m_fast) { destructor geomdef(data->open_chunk(OGF_FASTPATH)); @@ -67,7 +67,7 @@ void FProgressive::Load(const char* N, IReader* data, u32 dwFlags) void FProgressive::Render(float LOD) { -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) if (m_fast && RImplementation.phase == CRender::PHASE_SMAP) { int lod_id = iFloor((1.f - clampr(LOD, 0.f, 1.f)) * float(xSWI->count - 1) + 0.5f); diff --git a/src/Layers/xrRender/FTreeVisual.cpp b/src/Layers/xrRender/FTreeVisual.cpp index 193f9f193ad..742018ad623 100644 --- a/src/Layers/xrRender/FTreeVisual.cpp +++ b/src/Layers/xrRender/FTreeVisual.cpp @@ -98,7 +98,7 @@ struct FTreeVisual_setup wind.set(_sin(tm_rot), 0, _cos(tm_rot), 0); wind.normalize(); -#if RENDER!=R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) CEnvDescriptor& env = *g_pGamePersistent->Environment().CurrentEnv; float fValue = env.m_fTreeAmplitudeIntensity; wind.mul(fValue); // dir1*amplitude @@ -121,7 +121,7 @@ void FTreeVisual::Render(float /*LOD*/) if (tvs.dwFrame != Device.dwFrame) tvs.calculate(); // setup constants -#if RENDER != R_R1 +#if (RENDER != R_R1) || (RENDER != R_GLR1) Fmatrix xform_v; xform_v.mul_43(RCache.get_xform_view(), xform); RCache.tree.set_m_xform_v(xform_v); // matrix @@ -131,7 +131,7 @@ void FTreeVisual::Render(float /*LOD*/) RCache.tree.set_consts(tvs.scale, tvs.scale, 0, 0); // consts/scale RCache.tree.set_wave(tvs.wave); // wave RCache.tree.set_wind(tvs.wind); // wind -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) s *= 1.3333f; RCache.tree.set_c_scale(s * c_scale.rgb.x, s * c_scale.rgb.y, s * c_scale.rgb.z, s * c_scale.hemi); // scale RCache.tree.set_c_bias(s * c_bias.rgb.x, s * c_bias.rgb.y, s * c_bias.rgb.z, s * c_bias.hemi); // bias diff --git a/src/Layers/xrRender/FVF.h b/src/Layers/xrRender/FVF.h index 048c6a86f2c..4a879e180a0 100644 --- a/src/Layers/xrRender/FVF.h +++ b/src/Layers/xrRender/FVF.h @@ -6,7 +6,7 @@ # define FVF_COLOR(c) (c) #elif defined(USE_DX11) # define FVF_COLOR(c) ((c & 0xff00ff00) | ((c >> 16) & 0xff) | ((c & 0xff) << 16u)) -#elif defined(USE_OGL) //the compiler should know to dedup this, defined explicitly for organization +#elif defined(USE_OGL) || defined(USE_OGLR1) //the compiler should know to dedup this, defined explicitly for organization # define FVF_COLOR(c) (c) #else # error No graphics API selected or enabled! diff --git a/src/Layers/xrRender/FVisual.cpp b/src/Layers/xrRender/FVisual.cpp index 006d9c9fced..8f52a22e9d5 100644 --- a/src/Layers/xrRender/FVisual.cpp +++ b/src/Layers/xrRender/FVisual.cpp @@ -51,7 +51,7 @@ void Fvisual::Load(const char* N, IReader* data, u32 dwFlags) p_rm_Indices->AddRef(); #endif // check for fast-vertices -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) if (data->find_chunk(OGF_FASTPATH) && ps_r1_force_geomx) #else if (data->find_chunk(OGF_FASTPATH)) @@ -168,7 +168,7 @@ void Fvisual::Load(const char* N, IReader* data, u32 dwFlags) void Fvisual::Render(float) { -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) if (m_fast && ps_r1_force_geomx) #else if (m_fast && (ps_r1_force_geomx || RImplementation.phase == CRender::PHASE_SMAP && !RCache.is_TessEnabled())) diff --git a/src/Layers/xrRender/HOM.cpp b/src/Layers/xrRender/HOM.cpp index a85b868b5ae..777530b23f4 100644 --- a/src/Layers/xrRender/HOM.cpp +++ b/src/Layers/xrRender/HOM.cpp @@ -178,7 +178,7 @@ void CHOM::Render_DB(CFrustum& base) view_dim / 2.f + 0 + 0, view_dim / 2.f + 0 + 0, 0.0f, 1.0f}; Fmatrix m_viewport_01 = {1.f / 2.f, 0.0f, 0.0f, 0.0f, 0.0f, 1.f / 2.f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.f / 2.f + 0 + 0, 1.f / 2.f + 0 + 0, 0.0f, 1.0f}; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) Fmatrix m_viewport = {view_dim / 2.f, 0.0f, 0.0f, 0.0f, 0.0f, -view_dim / 2.f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, view_dim / 2.f + 0 + 0, view_dim / 2.f + 0 + 0, 0.0f, 1.0f}; Fmatrix m_viewport_01 = {1.f / 2.f, 0.0f, 0.0f, 0.0f, 0.0f, -1.f / 2.f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, diff --git a/src/Layers/xrRender/LightTrack.cpp b/src/Layers/xrRender/LightTrack.cpp index d6a2fc5b7c8..4fd32b805fb 100644 --- a/src/Layers/xrRender/LightTrack.cpp +++ b/src/Layers/xrRender/LightTrack.cpp @@ -34,7 +34,7 @@ CROS_impl::CROS_impl() sun_value = 0.2f; sun_smooth = 0.2f; -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) last_position.set(0.0f, 0.0f, 0.0f); ticks_to_update = 0; sky_rays_uptodate = 0; @@ -214,7 +214,7 @@ void CROS_impl::update(IRenderable* O) if (MODE & IRender_ObjectSpecific::TRACE_LIGHTS) { Fvector lacc = {0, 0, 0}; -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) float hemi_cube_light[NUM_FACES] = {0, 0, 0, 0, 0, 0}; #endif for (u32 lit = 0; lit < lights.size(); lit++) @@ -222,7 +222,7 @@ void CROS_impl::update(IRenderable* O) light* L = lights[lit].source; float d = L->position.distance_to(position); -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) float a = (1 / (L->attenuation0 + L->attenuation1 * d + L->attenuation2 * d * d) - d * L->falloff) * (L->flags.bStatic ? 1.f : 2.f); a = (a > 0) ? a : 0.0f; @@ -244,7 +244,7 @@ void CROS_impl::update(IRenderable* O) lacc.y += lights[lit].color.g * a; lacc.z += lights[lit].color.b * a; } -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) const float minHemiValue = 1 / 255.f; float hemi_light = (lacc.x + lacc.y + lacc.z) / 3.0f * ps_r2_dhemi_light_scale; @@ -280,7 +280,7 @@ void CROS_impl::update(IRenderable* O) approximate = accum; } -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) // Update ticks settings static const s32 s_iUTFirstTimeMin = 1; @@ -345,7 +345,7 @@ void CROS_impl::update_smooth(IRenderable* O) dwFrameSmooth = Device.dwFrame; -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) if (O && (0 == result_count)) update(O); // First time only #else // RENDER!=R_R1 @@ -387,7 +387,7 @@ void CROS_impl::calc_sky_hemi_value(Fvector& position, IGameObject* _object) // hemi-tracing if (MODE & IRender_ObjectSpecific::TRACE_HEMI) { -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) sky_rays_uptodate += ps_r2_dhemi_count; sky_rays_uptodate = _min(sky_rays_uptodate, lt_hemisamples); #endif // RENDER!=R_R1 @@ -452,7 +452,7 @@ void CROS_impl::prepare_lights(Fvector& position, IRenderable* O) // Select nearest lights Fvector bb_size = {radius, radius, radius}; -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) g_SpatialSpace->q_box(RImplementation.lstSpatial, 0, STYPE_LIGHTSOURCEHEMI, position, bb_size); #else g_SpatialSpace->q_box(RImplementation.lstSpatial, 0, STYPE_LIGHTSOURCE, position, bb_size); @@ -464,7 +464,7 @@ void CROS_impl::prepare_lights(Fvector& position, IRenderable* O) VERIFY(source); // sanity check float R = radius + source->range; if (position.distance_to(source->position) < R -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) && source->flags.bStatic #endif ) @@ -473,7 +473,7 @@ void CROS_impl::prepare_lights(Fvector& position, IRenderable* O) // Trace visibility lights.clear(); -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) float traceR = radius * .5f; #endif for (s32 id = 0; id < s32(track.size()); id++) @@ -492,7 +492,7 @@ void CROS_impl::prepare_lights(Fvector& position, IRenderable* O) float amount = 0; light* xrL = I->source; Fvector& LP = xrL->position; -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) P.mad(position, P.random_dir(), traceR); // Random point inside range #else P = position; @@ -526,7 +526,7 @@ void CROS_impl::prepare_lights(Fvector& position, IRenderable* O) } } -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) light* sun = (light*)RImplementation.Lights.sun._get(); // Sun diff --git a/src/Layers/xrRender/LightTrack.h b/src/Layers/xrRender/LightTrack.h index 976553ed7b4..a45d4bc18c4 100644 --- a/src/Layers/xrRender/LightTrack.h +++ b/src/Layers/xrRender/LightTrack.h @@ -73,7 +73,7 @@ class CROS_impl : public IRender_ObjectSpecific Fvector approximate; -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) Fvector last_position; s32 ticks_to_update; s32 sky_rays_uptodate; @@ -136,7 +136,7 @@ class CROS_impl : public IRender_ObjectSpecific // prepares static or hemisphere lights for ambient occlusion calculations void prepare_lights(Fvector& position, IRenderable* O); -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) // Updates only if makes a desizion that update is necessary void smart_update(IRenderable* O); #endif // RENDER!=R_R1 diff --git a/src/Layers/xrRender/Light_DB.cpp b/src/Layers/xrRender/Light_DB.cpp index d71a5f6d5c5..7deea3ec760 100644 --- a/src/Layers/xrRender/Light_DB.cpp +++ b/src/Layers/xrRender/Light_DB.cpp @@ -52,7 +52,7 @@ void CLight_DB::Load(IReader* fs) L->set_rotation(tmp_D, tmp_R); L->set_range(Ldata.range); L->set_color(Ldata.diffuse); -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) L->set_shadow(false); #else L->set_shadow(true); @@ -68,7 +68,7 @@ void CLight_DB::Load(IReader* fs) R_ASSERT2(sun, "Where is sun?"); } -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) void CLight_DB::LoadHemi() { string_path fn_game; @@ -141,7 +141,7 @@ void CLight_DB::add_light(light* L) if (Device.dwFrame == L->frame_render) return; L->frame_render = Device.dwFrame; -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) if (L->flags.bStatic) return; // skip static lighting, 'cause they are in lmaps if (ps_r1_flags.test(R1FLAG_DLIGHTS)) diff --git a/src/Layers/xrRender/Light_DB.h b/src/Layers/xrRender/Light_DB.h index 5f3d5e6186c..f65931b04d0 100644 --- a/src/Layers/xrRender/Light_DB.h +++ b/src/Layers/xrRender/Light_DB.h @@ -17,7 +17,7 @@ class CLight_DB void add_light(light* L); void Load(IReader* fs); -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) void LoadHemi(); #endif void Unload(); diff --git a/src/Layers/xrRender/ParticleEffect.cpp b/src/Layers/xrRender/ParticleEffect.cpp index 952fb858795..b5e384041e4 100644 --- a/src/Layers/xrRender/ParticleEffect.cpp +++ b/src/Layers/xrRender/ParticleEffect.cpp @@ -52,7 +52,7 @@ static void ApplyTexgen(const Fmatrix& mVP) 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f }; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) Fmatrix mTexelAdjust = { 0.5f, 0.0f, 0.0f, 0.0f, diff --git a/src/Layers/xrRender/QueryHelper.h b/src/Layers/xrRender/QueryHelper.h index ece3346ec42..9ccfb0f1afa 100644 --- a/src/Layers/xrRender/QueryHelper.h +++ b/src/Layers/xrRender/QueryHelper.h @@ -9,7 +9,7 @@ IC HRESULT GetData(ID3DQuery* pQuery, void* pData, u32 DataSize); IC HRESULT BeginQuery(ID3DQuery* pQuery); IC HRESULT EndQuery(ID3DQuery* pQuery); IC HRESULT ReleaseQuery(ID3DQuery *pQuery); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) IC HRESULT CreateQuery(GLuint* pQuery, D3D_QUERY type); IC HRESULT GetData(GLuint query, void* pData, u32 DataSize); IC HRESULT BeginQuery(GLuint query); @@ -72,7 +72,7 @@ IC HRESULT ReleaseQuery(ID3DQuery* pQuery) return S_OK; } -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) IC HRESULT CreateQuery(GLuint* pQuery, D3D_QUERY type) { diff --git a/src/Layers/xrRender/R_Backend.h b/src/Layers/xrRender/R_Backend.h index e1daeff3f21..637c59fb8c3 100644 --- a/src/Layers/xrRender/R_Backend.h +++ b/src/Layers/xrRender/R_Backend.h @@ -100,7 +100,7 @@ class ECORE_API CBackend #if defined(USE_DX9) || defined (USE_DX11) ID3DRenderTargetView* pRT[4]; ID3DDepthStencilView* pZB; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) GLuint pFB; GLuint pRT[4]; GLuint pZB; @@ -134,6 +134,9 @@ class ECORE_API CBackend GLuint ps; GLuint vs; GLuint gs; +#elif defined(USE_OGLR1) + GLuint ps; + GLuint vs; #else # error No graphics API selected or enabled! #endif @@ -175,14 +178,14 @@ class ECORE_API CBackend CTexture* textures_ps[CTexture::mtMaxPixelShaderTextures]; // stages //CTexture* textures_vs[5]; // dmap + 4 vs CTexture* textures_vs[CTexture::mtMaxVertexShaderTextures]; // 4 vs -#ifndef USE_DX9 +#if !defined(USE_DX9) && !defined(USE_OGLR1) CTexture* textures_gs[CTexture::mtMaxGeometryShaderTextures]; // 4 vs # if defined(USE_DX11) CTexture* textures_hs[CTexture::mtMaxHullShaderTextures]; // 4 vs CTexture* textures_ds[CTexture::mtMaxDomainShaderTextures]; // 4 vs CTexture* textures_cs[CTexture::mtMaxComputeShaderTextures]; // 4 vs # endif -#elif defined(USE_DX9) +#elif defined(USE_DX9) || defined(USE_OGLR1) // Nothing, because DX9 only has VS and PS #else # error No graphics API selected or enabled! @@ -264,7 +267,7 @@ class ECORE_API CBackend IC void set_ZB(ID3DDepthStencilView* ZB); IC ID3DRenderTargetView* get_RT(u32 ID = 0); IC ID3DDepthStencilView* get_ZB(); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) IC void set_FB(GLuint FB = 0); IC void set_RT(GLuint RT, u32 ID = 0); IC void set_ZB(GLuint ZB); @@ -283,7 +286,7 @@ class ECORE_API CBackend IC bool ClearRTRect(ID3DRenderTargetView* rt, const Fcolor& color, size_t numRects, const Irect* rects); IC bool ClearZBRect(ID3DDepthStencilView* zb, float depth, size_t numRects, const Irect* rects); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) IC void ClearRT(GLuint rt, const Fcolor& color); IC void ClearZB(GLuint zb, float depth); @@ -301,7 +304,7 @@ class ECORE_API CBackend return ClearRTRect(rt->pRT, color, numRects, rects); } -#if defined(USE_DX9) || defined(USE_OGL) +#if defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) ICF void ClearZB(ref_rt& zb, float depth) { ClearZB(zb->pRT, depth);} ICF void ClearZB(ref_rt& zb, float depth, u8 stencil) { ClearZB(zb->pRT, depth, stencil);} ICF bool ClearZBRect(ref_rt& zb, float depth, size_t numRects, const Irect* rects) @@ -343,7 +346,7 @@ class ECORE_API CBackend #if defined(USE_DX9) || defined(USE_DX11) ICF void set_PS(ID3DPixelShader* _ps, LPCSTR _n = nullptr); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) ICF void set_PS(GLuint _ps, LPCSTR _n = 0); #else # error No graphics API selected or enabled! @@ -351,7 +354,7 @@ class ECORE_API CBackend ICF void set_PS(ref_ps& _ps) { set_PS(_ps->sh, _ps->cName.c_str()); } -#ifndef USE_DX9 +#if !defined(USE_DX9) && !defined(USE_OGLR1) ICF void set_GS(ref_gs& _gs) { set_GS(_gs->sh, _gs->cName.c_str()); } # if defined(USE_DX11) @@ -371,7 +374,7 @@ class ECORE_API CBackend #endif // USE_DX9 -#if defined(USE_DX9) || defined(USE_OGL) +#if defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) ICF bool is_TessEnabled() { return false; } #elif defined(USE_DX11) ICF bool is_TessEnabled(); @@ -389,7 +392,7 @@ class ECORE_API CBackend #if defined(USE_DX9) || defined(USE_DX11) ICF void set_VS(ID3DVertexShader* _vs, LPCSTR _n = nullptr); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) ICF void set_VS(GLuint _vs, LPCSTR _n = 0); #else # error No graphics API selected or enabled! diff --git a/src/Layers/xrRender/R_Backend_DBG.cpp b/src/Layers/xrRender/R_Backend_DBG.cpp index 3335caf84f8..a0b5632d2fa 100644 --- a/src/Layers/xrRender/R_Backend_DBG.cpp +++ b/src/Layers/xrRender/R_Backend_DBG.cpp @@ -7,7 +7,7 @@ extern IC u32 GetIndexCount(D3DPRIMITIVETYPE T, u32 iPrimitiveCount); void CBackend::InitializeDebugDraw() { -#ifndef USE_DX9 +#if !defined(USE_DX9) && !defined(USE_OGLR1) vs_L.create(FVF::F_L, RCache.Vertex.Buffer(), RCache.Index.Buffer()); vs_TL.create(FVF::F_TL, RCache.Vertex.Buffer(), RCache.Index.Buffer()); #endif @@ -15,7 +15,7 @@ void CBackend::InitializeDebugDraw() void CBackend::DestroyDebugDraw() { -#ifndef USE_DX9 +#if !defined(USE_DX9) && !defined(USE_OGLR1) vs_L.destroy(); vs_TL.destroy(); #endif @@ -258,7 +258,7 @@ void CBackend::dbg_OverdrawEnd() // Draw a rectangle wherever the count equal I #if defined(USE_DX9) CHK_DX(HW.pDevice->SetFVF(FVF::F_TL)); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) set_Geometry(vs_TL); #else # error No graphics API defined or enabled! @@ -277,7 +277,7 @@ void CBackend::dbg_OverdrawEnd() pv[3].set(float(Device.dwWidth), float(0), c, 0, 0); CHK_DX(HW.pDevice->SetRenderState(D3DRS_STENCILREF, I)); CHK_DX(HW.pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, pv, sizeof(FVF::TL))); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) u32 vBase; FVF::TL* pv = (FVF::TL*)Vertex.Lock(4, vs_L->vb_stride, vBase); pv[0].set(float(0), float(Device.dwHeight), c, 0, 0); @@ -300,7 +300,7 @@ void CBackend::dbg_SetRS(D3DRENDERSTATETYPE p1, u32 p2) { #ifdef USE_DX9 CHK_DX(HW.pDevice->SetRenderState(p1, p2)); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) VERIFY(!"Not implemented"); #else # error No graphics API defined or enabled! @@ -311,7 +311,7 @@ void CBackend::dbg_SetSS(u32 sampler, D3DSAMPLERSTATETYPE type, u32 value) { #ifdef USE_DX9 CHK_DX(HW.pDevice->SetSamplerState(sampler, type, value)); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) VERIFY(!"Not implemented"); #else # error No graphics API defined or enabled! diff --git a/src/Layers/xrRender/R_Backend_Runtime.cpp b/src/Layers/xrRender/R_Backend_Runtime.cpp index 1ea752b1b92..449d3ae730d 100644 --- a/src/Layers/xrRender/R_Backend_Runtime.cpp +++ b/src/Layers/xrRender/R_Backend_Runtime.cpp @@ -16,7 +16,7 @@ void CBackend::OnFrameEnd() { if (!GEnv.isDedicatedServer) { -#if !defined(USE_DX9) && !defined(USE_OGL) +#if !defined(USE_DX9) && !defined(USE_OGL) && !defined(USE_OGLR1) HW.pContext->ClearState(); #elif defined(USE_DX9) for (u32 stage = 0; stage < HW.Caps.raster.dwStages; stage++) @@ -36,7 +36,7 @@ void CBackend::OnFrameBegin() { PGO(Msg("PGO:*****frame[%d]*****", RDEVICE.dwFrame)); -#ifndef USE_DX9 +#if !defined(USE_DX9) && !defined(USE_OGLR1) Invalidate(); // DX9 sets base rt and base zb by default #ifndef USE_OGL @@ -180,7 +180,7 @@ void CBackend::set_ClipPlanes(u32 _enable, Fplane* _planes /*=NULL */, u32 count // Enable them u32 e_mask = (1 << count) - 1; CHK_DX(HW.pDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, e_mask)); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) // TODO: DX10: Implement in the corresponding vertex shaders // Use this to set up location, were shader setup code will get data // VERIFY(!"CBackend::set_ClipPlanes not implemented!"); @@ -202,7 +202,7 @@ void CBackend::set_ClipPlanes(u32 _enable, Fmatrix* _xform /*=NULL */, u32 fmask { #if defined(USE_DX9) CHK_DX(HW.pDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, FALSE)); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) // TODO: DX10: Implement in the corresponding vertex shaders // Use this to set up location, were shader setup code will get data // VERIFY(!"CBackend::set_ClipPlanes not implemented!"); @@ -401,11 +401,13 @@ void CBackend::set_Textures(STextureList* _T) ID3DShaderResourceView* pRes = 0; // HW.pDevice->PSSetShaderResources(_last_ps, 1, &pRes); SRVSManager.SetPSResource(_last_ps, pRes); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) CHK_GL(glActiveTexture(GL_TEXTURE0 + _last_ps)); CHK_GL(glBindTexture(GL_TEXTURE_2D, 0)); +#ifndef USE_OGLR1 if (RImplementation.o.dx10_msaa) CHK_GL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0)); +#endif CHK_GL(glBindTexture(GL_TEXTURE_3D, 0)); CHK_GL(glBindTexture(GL_TEXTURE_CUBE_MAP, 0)); #else @@ -426,11 +428,13 @@ void CBackend::set_Textures(STextureList* _T) ID3DShaderResourceView* pRes = 0; // HW.pDevice->VSSetShaderResources(_last_vs, 1, &pRes); SRVSManager.SetVSResource(_last_vs, pRes); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) CHK_GL(glActiveTexture(GL_TEXTURE0 + CTexture::rstVertex + _last_vs)); CHK_GL(glBindTexture(GL_TEXTURE_2D, 0)); +#ifndef USE_OGLR1 if (RImplementation.o.dx10_msaa) CHK_GL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0)); +#endif CHK_GL(glBindTexture(GL_TEXTURE_3D, 0)); CHK_GL(glBindTexture(GL_TEXTURE_CUBE_MAP, 0)); #else @@ -538,7 +542,7 @@ void CBackend::SetupStates() #elif defined(USE_DX11) SSManager.SetMaxAnisotropy(ps_r__tf_Anisotropic); SSManager.SetMipLODBias(ps_r__tf_Mipbias); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) // TODO: OGL: Implement SetupStates(). #else # error No graphics API selected or enabled! diff --git a/src/Layers/xrRender/R_Backend_Runtime.h b/src/Layers/xrRender/R_Backend_Runtime.h index fdfbace7afc..5e6602f2435 100644 --- a/src/Layers/xrRender/R_Backend_Runtime.h +++ b/src/Layers/xrRender/R_Backend_Runtime.h @@ -15,6 +15,9 @@ #elif defined(USE_OGL) #include "Layers/xrRenderGL/glR_Backend_Runtime.h" #include "Layers/xrRenderGL/glState.h" +#elif defined(USE_OGLR1) +#include "Layers/xrRenderGLR1/glR_Backend_Runtime.h" +#include "Layers/xrRenderGLR1/glState.h" #endif IC void R_xforms::set_c_w(R_constant* C) @@ -61,7 +64,7 @@ IC const Fmatrix& CBackend::get_xform_view() { return xforms.get_V(); } IC const Fmatrix& CBackend::get_xform_project() { return xforms.get_P(); } #if defined(USE_DX9) || defined(USE_DX11) IC ID3DRenderTargetView* CBackend::get_RT(u32 ID) -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) IC GLuint CBackend::get_RT(u32 ID) #else # error No graphics API selected or enabled! @@ -74,7 +77,7 @@ IC GLuint CBackend::get_RT(u32 ID) #if defined(USE_DX9) || defined(USE_DX11) IC ID3DDepthStencilView* CBackend::get_ZB() -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) IC GLuint CBackend::get_ZB() #else # error No graphics API selected or enabled! diff --git a/src/Layers/xrRender/ResourceManager.cpp b/src/Layers/xrRender/ResourceManager.cpp index 67b1da53c41..ace8a550e40 100644 --- a/src/Layers/xrRender/ResourceManager.cpp +++ b/src/Layers/xrRender/ResourceManager.cpp @@ -326,7 +326,7 @@ Shader* CResourceManager::Create(LPCSTR s_shader, LPCSTR s_textures, LPCSTR s_co { if (!GEnv.isDedicatedServer) { -#if defined(USE_DX9) +#if defined(USE_DX9) || defined(USE_OGLR1) # ifndef _EDITOR if (_lua_HasShader(s_shader)) return _lua_Create(s_shader, s_textures); @@ -375,7 +375,7 @@ void CResourceManager::DeferredUpload() #if defined(USE_DX9) || defined(USE_DX11) xr_parallel_for_each(m_textures, [&](auto m_tex) { m_tex.second->Load(); }); -#elif defined(USE_OGL) // XXX: OGL: Set additional contexts for all worker threads? +#elif defined(USE_OGL) || defined(USE_OGLR1) // XXX: OGL: Set additional contexts for all worker threads? for (auto& texture : m_textures) texture.second->Load(); #else @@ -390,7 +390,7 @@ void CResourceManager::DeferredUnload() #if defined(USE_DX9) || defined(USE_DX11) xr_parallel_for_each(m_textures, [&](auto m_tex) { m_tex.second->Unload(); }); -#elif defined(USE_OGL) // XXX: OGL: Set additional contexts for all worker threads? +#elif defined(USE_OGL) || defined(USE_OGLR1) // XXX: OGL: Set additional contexts for all worker threads? for (auto& texture : m_textures) texture.second->Unload(); #else diff --git a/src/Layers/xrRender/ResourceManager.h b/src/Layers/xrRender/ResourceManager.h index 2a7371d9038..8b98cc04ee4 100644 --- a/src/Layers/xrRender/ResourceManager.h +++ b/src/Layers/xrRender/ResourceManager.h @@ -187,7 +187,7 @@ class ECORE_API CResourceManager SState* _CreateState(SimulatorStates& Code); void _DeleteState(const SState* SB); -#ifdef USE_OGL +#if defined(USE_OGL) || defined(USE_OGLR1) SDeclaration* _CreateDecl (u32 FVF); #endif @@ -214,7 +214,7 @@ class ECORE_API CResourceManager CResourceManager() : bDeferredLoad(TRUE) { -#if RENDER == R_R1 || RENDER == R_R2 +#if RENDER == R_R1 || RENDER == R_R2 || RENDER == R_GLR1 m_shader_fallback_allowed = !!strstr(Core.Params, "-lack_of_shaders"); #else // For another renderers we should always allow fallback m_shader_fallback_allowed = true; diff --git a/src/Layers/xrRender/SH_Atomic.cpp b/src/Layers/xrRender/SH_Atomic.cpp index 65d17ecc8de..1cea2ea7eb1 100644 --- a/src/Layers/xrRender/SH_Atomic.cpp +++ b/src/Layers/xrRender/SH_Atomic.cpp @@ -46,7 +46,7 @@ SVS::~SVS() #if defined(USE_DX9) || defined(USE_DX11) _RELEASE(sh); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) CHK_GL(glDeleteProgram(sh)); #else # error No graphics API selected or enabled! @@ -59,7 +59,7 @@ SPS::~SPS() { #if defined(USE_DX9) || defined(USE_DX11) _RELEASE(sh); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) CHK_GL(glDeleteProgram(sh)); #else # error No graphics API selected or enabled! @@ -153,7 +153,7 @@ SDeclaration::~SDeclaration() { RImplementation.Resources->_DeleteDecl(this); // Release vertex layout -#ifdef USE_OGL +#if defined(USE_OGL) || defined(USE_OGLR1) glDeleteVertexArrays(1, &dcl); #elif defined(USE_DX11) || defined(USE_OGL) xr_map::iterator iLayout; diff --git a/src/Layers/xrRender/SH_Atomic.h b/src/Layers/xrRender/SH_Atomic.h index ded249ed162..6594eec0974 100644 --- a/src/Layers/xrRender/SH_Atomic.h +++ b/src/Layers/xrRender/SH_Atomic.h @@ -9,6 +9,8 @@ #include "Layers/xrRenderDX10/StateManager/dx10State.h" #elif defined(USE_OGL) #include "Layers/xrRenderGL/glState.h" +#elif defined(USE_OGLR1) +#include "Layers/xrRenderGLR1/glState.h" #endif #pragma pack(push, 4) @@ -30,7 +32,7 @@ struct ECORE_API SVS : public xr_resource_named { #if defined(USE_DX9) || defined(USE_DX11) ID3DVertexShader* sh; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) GLuint sh; #else # error No graphics API selected or enabled! @@ -49,7 +51,7 @@ struct ECORE_API SPS : public xr_resource_named { #if defined(USE_DX9) || defined(USE_DX11) ID3DPixelShader* sh; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) GLuint sh; #else # error No graphics API selected or enabled! @@ -139,7 +141,7 @@ struct ECORE_API SDeclaration : public xr_resource_flagged // Maps input signature to input layout xr_map vs_to_layout; xr_vector dx10_dcl_code; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) u32 FVF; GLuint dcl; #else diff --git a/src/Layers/xrRender/SH_RT.h b/src/Layers/xrRender/SH_RT.h index f1b415238ba..f2b73e70aa8 100644 --- a/src/Layers/xrRender/SH_RT.h +++ b/src/Layers/xrRender/SH_RT.h @@ -33,7 +33,7 @@ class CRT : public xr_resource_named ID3DDepthStencilView* pZRT; ID3D11UnorderedAccessView* pUAView; # endif -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) GLuint pRT; GLuint pZRT; GLenum target; diff --git a/src/Layers/xrRender/SH_Texture.h b/src/Layers/xrRender/SH_Texture.h index bd2b03418d1..f2d15fb51bf 100644 --- a/src/Layers/xrRender/SH_Texture.h +++ b/src/Layers/xrRender/SH_Texture.h @@ -10,7 +10,7 @@ class CTheoraSurface; class ECORE_API CTexture : public xr_resource_named { public: -#if defined(USE_DX9) +#if defined(USE_DX9) || defined(USE_OGLR1) enum MaxTextures { mtMaxPixelShaderTextures = 16, @@ -59,7 +59,7 @@ class ECORE_API CTexture : public xr_resource_named rstCompute = rstDomain + 256, rstInvalid = rstCompute + 256 }; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) // Since OGL doesn't differentiate between stages, // distance between enum values should be the max for that stage. enum ResourceShaderType @@ -88,7 +88,7 @@ class ECORE_API CTexture : public xr_resource_named #if defined(USE_DX9) || defined(USE_DX11) void surface_set(ID3DBaseTexture* surf); ID3DBaseTexture* surface_get(); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) void surface_set(GLenum target, GLuint surf); GLuint surface_get(); #else @@ -175,7 +175,7 @@ class ECORE_API CTexture : public xr_resource_named u32 m_height; ID3DBaseTexture* desc_cache; D3D_TEXTURE2D_DESC desc; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) GLuint pSurface; GLuint pBuffer; // Sequence data diff --git a/src/Layers/xrRender/ShaderResourceTraits.h b/src/Layers/xrRender/ShaderResourceTraits.h index 34171023f0d..2e2c2c6fbef 100644 --- a/src/Layers/xrRender/ShaderResourceTraits.h +++ b/src/Layers/xrRender/ShaderResourceTraits.h @@ -2,7 +2,7 @@ #include "ResourceManager.h" -#ifdef USE_OGL +#if defined(USE_OGL) || defined(USE_OGLR1) template inline std::pair GLCompileShader(pcstr* buffer, size_t size, pcstr name) { @@ -71,7 +71,7 @@ struct ShaderTypeTraits { using MapType = CResourceManager::map_VS; -#ifdef USE_OGL +#if defined(USE_OGL) || defined(USE_OGLR1) using LinkageType = const GLenum*; using HWShaderType = GLuint; using BufferType = pcstr*; @@ -127,7 +127,7 @@ struct ShaderTypeTraits #elif defined(USE_DX11) res = HW.pDevice->CreateVertexShader(buffer, size, linkage, &sh); UNUSED(name); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) if (linkage) res = GLUseBinary(buffer, size, linkage, name); else @@ -147,7 +147,7 @@ struct ShaderTypeTraits { using MapType = CResourceManager::map_PS; -#if defined(USE_OGL) +#if defined(USE_OGL) || defined(USE_OGLR1) using LinkageType = const GLenum*; using HWShaderType = GLuint; using BufferType = pcstr*; @@ -217,7 +217,7 @@ struct ShaderTypeTraits #elif defined(USE_DX11) res = HW.pDevice->CreatePixelShader(buffer, size, linkage, &sh); UNUSED(name); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) if (linkage) res = GLUseBinary(buffer, size, linkage, name); else @@ -243,7 +243,7 @@ struct ShaderTypeTraits using HWShaderType = ID3DGeometryShader*; using BufferType = DWORD const*; using ResultType = HRESULT; -# elif defined(USE_OGL) +# elif defined(USE_OGL) || defined(USE_OGLR1) using LinkageType = const GLenum*; using HWShaderType = GLuint; using BufferType = pcstr*; @@ -290,7 +290,7 @@ struct ShaderTypeTraits # if defined(USE_DX11) res = HW.pDevice->CreateGeometryShader(buffer, size, linkage, &sh); UNUSED(name); -# elif defined(USE_OGL) +# elif defined(USE_OGL) || defined(USE_OGLR1) if (linkage) res = GLUseBinary(buffer, size, linkage, name); else @@ -315,7 +315,7 @@ struct ShaderTypeTraits using HWShaderType = ID3D11HullShader*; using BufferType = DWORD const*; using ResultType = HRESULT; -# elif defined(USE_OGL) +# elif defined(USE_OGL) || defined(USE_OGLR1) using LinkageType = const GLenum*; using HWShaderType = GLuint; using BufferType = pcstr*; @@ -345,7 +345,7 @@ struct ShaderTypeTraits # if defined(USE_DX11) res = HW.pDevice->CreateHullShader(buffer, size, linkage, &sh); UNUSED(name); -# elif defined(USE_OGL) +# elif defined(USE_OGL) || defined(USE_OGLR1) if (linkage) res = GLUseBinary(buffer, size, linkage, name); else @@ -370,7 +370,7 @@ struct ShaderTypeTraits using HWShaderType = ID3D11DomainShader*; using BufferType = DWORD const*; using ResultType = HRESULT; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) using LinkageType = const GLenum*; using HWShaderType = GLuint; using BufferType = pcstr*; @@ -400,7 +400,7 @@ struct ShaderTypeTraits # if defined(USE_DX11) res = HW.pDevice->CreateDomainShader(buffer, size, linkage, &sh); UNUSED(name); -# elif defined(USE_OGL) +# elif defined(USE_OGL) || defined(USE_OGLR1) if (linkage) res = GLUseBinary(buffer, size, linkage, name); else @@ -425,7 +425,7 @@ struct ShaderTypeTraits using HWShaderType = ID3D11ComputeShader*; using BufferType = DWORD const*; using ResultType = HRESULT; -# elif defined(USE_OGL) +# elif defined(USE_OGL) || defined(USE_OGLR1) using LinkageType = const GLenum*; using HWShaderType = GLuint; using BufferType = pcstr*; @@ -472,7 +472,7 @@ struct ShaderTypeTraits #if defined(USE_DX11) res = HW.pDevice->CreateComputeShader(buffer, size, linkage, &sh); UNUSED(name); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) if (linkage) res = GLUseBinary(buffer, size, linkage, name); else diff --git a/src/Layers/xrRender/blenders/BlenderDefault.cpp b/src/Layers/xrRender/blenders/BlenderDefault.cpp index e27b06dbbed..1aff89e1734 100644 --- a/src/Layers/xrRender/blenders/BlenderDefault.cpp +++ b/src/Layers/xrRender/blenders/BlenderDefault.cpp @@ -4,7 +4,7 @@ #include "BlenderDefault.h" -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) #error "The blender can't be used in this renderer generation" #endif diff --git a/src/Layers/xrRender/blenders/Blender_Blur.cpp b/src/Layers/xrRender/blenders/Blender_Blur.cpp index 7e0918f9a49..fe17e4e6db0 100644 --- a/src/Layers/xrRender/blenders/Blender_Blur.cpp +++ b/src/Layers/xrRender/blenders/Blender_Blur.cpp @@ -8,7 +8,7 @@ * Consider removing. */ -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) #error "The blender can't be used in this renderer generation" #endif diff --git a/src/Layers/xrRender/blenders/Blender_LaEmB.cpp b/src/Layers/xrRender/blenders/Blender_LaEmB.cpp index a7a1dafb939..ba753dfe5c3 100644 --- a/src/Layers/xrRender/blenders/Blender_LaEmB.cpp +++ b/src/Layers/xrRender/blenders/Blender_LaEmB.cpp @@ -8,7 +8,7 @@ * Consider removing. */ -#if RENDER != R_R1 +#if (RENDER != R_R1) || (RENDER != R_GLR1) #error "The blender can't be used in this renderer generation" #endif diff --git a/src/Layers/xrRender/blenders/Blender_Lm(EbB).cpp b/src/Layers/xrRender/blenders/Blender_Lm(EbB).cpp index d7ecac10e38..c97d3d1e93b 100644 --- a/src/Layers/xrRender/blenders/Blender_Lm(EbB).cpp +++ b/src/Layers/xrRender/blenders/Blender_Lm(EbB).cpp @@ -116,7 +116,7 @@ void CBlender_LmEbB::Compile(CBlender_Compile& C) #endif C.r_End(); break; -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) case SE_R1_LPOINT: C.r_Pass("lmap_point", "add_point", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); C.r_Sampler("s_base", C.L_textures[0]); diff --git a/src/Layers/xrRender/blenders/Blender_Screen_GRAY.cpp b/src/Layers/xrRender/blenders/Blender_Screen_GRAY.cpp index ff2eabf5451..e1d6ca162e3 100644 --- a/src/Layers/xrRender/blenders/Blender_Screen_GRAY.cpp +++ b/src/Layers/xrRender/blenders/Blender_Screen_GRAY.cpp @@ -8,7 +8,7 @@ * Consider removing. */ -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) #error "The blender can't be used in this renderer generation" #endif diff --git a/src/Layers/xrRender/blenders/Blender_Shadow_World.cpp b/src/Layers/xrRender/blenders/Blender_Shadow_World.cpp index bedce090b3a..d6ef4e90df2 100644 --- a/src/Layers/xrRender/blenders/Blender_Shadow_World.cpp +++ b/src/Layers/xrRender/blenders/Blender_Shadow_World.cpp @@ -3,7 +3,7 @@ #include "Blender_Shadow_World.h" -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) #error "The blender can't be used in this renderer generation" #endif diff --git a/src/Layers/xrRender/blenders/Blender_Vertex.cpp b/src/Layers/xrRender/blenders/Blender_Vertex.cpp index 2cb9cc881ab..580e7ce04d2 100644 --- a/src/Layers/xrRender/blenders/Blender_Vertex.cpp +++ b/src/Layers/xrRender/blenders/Blender_Vertex.cpp @@ -3,7 +3,7 @@ #include "Blender_Vertex.h" -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) #error "The blender can't be used in this renderer generation" #endif diff --git a/src/Layers/xrRender/blenders/Blender_Vertex_aref.cpp b/src/Layers/xrRender/blenders/Blender_Vertex_aref.cpp index dc97e586ae1..09b22ac1dde 100644 --- a/src/Layers/xrRender/blenders/Blender_Vertex_aref.cpp +++ b/src/Layers/xrRender/blenders/Blender_Vertex_aref.cpp @@ -3,7 +3,7 @@ #include "Blender_Vertex_aref.h" -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) #error "This blender can't be used in this renderer generation" #endif diff --git a/src/Layers/xrRender/blenders/uber_deffer.cpp b/src/Layers/xrRender/blenders/uber_deffer.cpp index 65ef1a80fba..0fb7cf21aeb 100644 --- a/src/Layers/xrRender/blenders/uber_deffer.cpp +++ b/src/Layers/xrRender/blenders/uber_deffer.cpp @@ -205,7 +205,7 @@ void uber_deffer(CBlender_Compile& C, bool hq, LPCSTR _vspec, LPCSTR _pspec, BOO C.r_dx10Texture("s_hemi", C.L_textures[2]); C.r_dx10Sampler("smp_rtlinear"); } -#elif defined(USE_DX9) || defined(USE_OGL) +#elif defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) C.r_Pass(vs, ps, FALSE); VERIFY(C.L_textures[0].size()); if (bump) diff --git a/src/Layers/xrRender/dxEnvironmentRender.cpp b/src/Layers/xrRender/dxEnvironmentRender.cpp index 2955a3c88ef..9b653540542 100644 --- a/src/Layers/xrRender/dxEnvironmentRender.cpp +++ b/src/Layers/xrRender/dxEnvironmentRender.cpp @@ -131,7 +131,7 @@ dxEnvironmentRender::dxEnvironmentRender() { tsky0 = RImplementation.Resources->_CreateTexture("$user$sky0"); tsky1 = RImplementation.Resources->_CreateTexture("$user$sky1"); -#ifdef USE_OGL +#if defined(USE_OGL) || defined(USE_OGLR1) // These textures are specified in clouds.s tclouds0 = RImplementation.Resources->_CreateTexture("$user$clouds0"); tclouds1 = RImplementation.Resources->_CreateTexture("$user$clouds1"); @@ -159,7 +159,7 @@ void dxEnvironmentRender::OnFrame(CEnvironment& env) #if defined(USE_DX9) || defined(USE_DX11) const u32 smp_location_sky = CTexture::rstVertex; const u32 smp_location_clouds = CTexture::rstVertex; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) const u32 smp_location_sky = CTexture::rstVertex + 1 /* m_WVP */; const u32 smp_location_clouds = CTexture::rstVertex + 1 /* m_WVP */; #else @@ -182,7 +182,7 @@ void dxEnvironmentRender::OnFrame(CEnvironment& env) } //. Setup skybox textures, somewhat ugly -#ifdef USE_OGL +#if defined(USE_OGL) || defined(USE_OGLR1) GLuint e0 = mixRen.sky_r_textures[0].second->surface_get(); GLuint e1 = mixRen.sky_r_textures[1].second->surface_get(); @@ -206,7 +206,8 @@ void dxEnvironmentRender::OnFrame(CEnvironment& env) // ******************** Environment params (setting) #if defined(USE_DX9) -# if RENDER == R_R1 + +# if (RENDER == R_R1) || (RENDER == R_GLR1) Fvector3 fog_color = env.CurrentEnv->fog_color; fog_color.mul(ps_r1_fog_luminance); # else @@ -258,7 +259,7 @@ void dxEnvironmentRender::RenderSky(CEnvironment& env) RCache.set_Shader(sh_2sky); #if defined(USE_DX9) || defined(USE_DX11) RCache.set_Textures(&mixRen.sky_r_textures); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) if (HW.Caps.geometry.bVTF) RCache.set_Textures(&mixRen.sky_r_textures); #else @@ -276,7 +277,7 @@ void dxEnvironmentRender::RenderSky(CEnvironment& env) // Sun GEnv.Render->rmNormal(); -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) // // This hack is done to make sure that the state is set for sure: // The state may be not set by RCache if the state is changed using API SetRenderState() function before @@ -356,7 +357,7 @@ void dxEnvironmentRender::OnDeviceDestroy() #if defined(USE_DX9) || defined(USE_DX11) tsky0->surface_set(nullptr); tsky1->surface_set(nullptr); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) tsky0->surface_set(GL_TEXTURE_CUBE_MAP, 0); tsky1->surface_set(GL_TEXTURE_CUBE_MAP, 0); tclouds0->surface_set(GL_TEXTURE_2D, 0); diff --git a/src/Layers/xrRender/dxEnvironmentRender.h b/src/Layers/xrRender/dxEnvironmentRender.h index 3e4b41ecc38..b8b667d5ae1 100644 --- a/src/Layers/xrRender/dxEnvironmentRender.h +++ b/src/Layers/xrRender/dxEnvironmentRender.h @@ -14,7 +14,7 @@ class CBlender_skybox : public IBlender virtual void Compile(CBlender_Compile& C) { C.r_Pass("sky2", "sky2", FALSE, TRUE, FALSE); -#if defined(USE_DX9) +#if defined(USE_DX9) || defined(USE_OGLR1) C.r_Sampler_clf("s_sky0", "$null"); C.r_Sampler_clf("s_sky1", "$null"); C.r_Sampler_rtf("s_tonemap", "$user$tonemap"); //. hack diff --git a/src/Layers/xrRender/dxStatGraphRender.cpp b/src/Layers/xrRender/dxStatGraphRender.cpp index 9c88b7f48d1..4c9e5c8d4cd 100644 --- a/src/Layers/xrRender/dxStatGraphRender.cpp +++ b/src/Layers/xrRender/dxStatGraphRender.cpp @@ -26,7 +26,7 @@ void dxStatGraphRender::OnRender(CStatGraph& owner) RCache.set_xform_world(Fidentity); RCache.set_xform_view(ViewM); RCache.set_xform_project(Fidentity); -#ifdef USE_DX9 +#if defined(USE_DX9) || defined(USE_OGLR1) RCache.OnFrameEnd(); #else // when we don't have FFP support RCache.set_Shader(RImplementation.m_WireShader); diff --git a/src/Layers/xrRender/light.cpp b/src/Layers/xrRender/light.cpp index f692cf76176..6fdf71b1a2c 100644 --- a/src/Layers/xrRender/light.cpp +++ b/src/Layers/xrRender/light.cpp @@ -98,7 +98,7 @@ void light::set_texture(LPCSTR name) } #endif -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) void light::set_texture(LPCSTR name) {} #endif diff --git a/src/Layers/xrRender/r__dsgraph_build.cpp b/src/Layers/xrRender/r__dsgraph_build.cpp index d7a17f69670..9015b49361c 100644 --- a/src/Layers/xrRender/r__dsgraph_build.cpp +++ b/src/Layers/xrRender/r__dsgraph_build.cpp @@ -40,7 +40,7 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(IRenderable* root, dxRender_Visual return; pVisual->vis.marker = RI.marker; -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) if (RI.o.vis_intersect && (pVisual->vis.accept_frame != Device.dwFrame)) return; pVisual->vis.accept_frame = Device.dwFrame; @@ -78,7 +78,7 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(IRenderable* root, dxRender_Visual } mapHUD.insert_anyway(distSQ, _MatrixItemS({ SSA, root, pVisual, xform, sh })); -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) if (sh->flags.bEmissive) mapHUDEmissive.insert_anyway(distSQ, _MatrixItemS({ SSA, root, pVisual, xform, sh_d })); // sh_d -> L_special #endif @@ -86,7 +86,7 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(IRenderable* root, dxRender_Visual } // Shadows registering -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) RI.L_Shadows->add_element(_MatrixItem{ SSA, root, pVisual, xform }); #endif if (root && root->renderable_Invisible()) @@ -99,7 +99,7 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(IRenderable* root, dxRender_Visual return; } -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) // Emissive geometry should be marked and R2 special-cases it // a) Allow to skeep already lit pixels // b) Allow to make them 100% lit and really bright @@ -125,7 +125,7 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(IRenderable* root, dxRender_Visual auto& pass = *sh->passes[iPass]; auto& map = mapMatrixPasses[sh->flags.iPriority / 2][iPass]; -#if defined(USE_DX9) +#if defined(USE_DX9) || defined(USE_OGLR1) auto& Nvs = map[pass.vs->sh]; auto& Nps = Nvs[pass.ps->sh]; #elif defined(USE_DX11) @@ -140,7 +140,7 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(IRenderable* root, dxRender_Visual # error No graphics API selected or enabled! #endif -#if defined(USE_DX9) || defined(USE_OGL) +#if defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) auto& Ncs = Nps[pass.constants._get()]; #elif defined(USE_DX11) Nps.hs = pass.hs->sh; @@ -164,7 +164,7 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(IRenderable* root, dxRender_Visual if (SSA > Ncs.ssa) { Ncs.ssa = SSA; -#if defined(USE_DX9) || defined(USE_OGL) +#if defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) if (SSA > Nps.ssa) { Nps.ssa = SSA; @@ -193,7 +193,7 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(IRenderable* root, dxRender_Visual } } -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) if (val_recorder) { Fbox3 temp; @@ -211,7 +211,7 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual) return; pVisual->vis.marker = RI.marker; -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) if (RI.o.vis_intersect && (pVisual->vis.accept_frame != Device.dwFrame)) return; pVisual->vis.accept_frame = Device.dwFrame; @@ -248,7 +248,7 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual) return; } -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) // Emissive geometry should be marked and R2 special-cases it // a) Allow to skeep already lit pixels // b) Allow to make them 100% lit and really bright @@ -277,7 +277,7 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual) auto& pass = *sh->passes[iPass]; auto& map = mapNormalPasses[sh->flags.iPriority / 2][iPass]; -#if defined(USE_DX9) +#if defined(USE_DX9) || defined(USE_OGLR1) auto& Nvs = map[pass.vs->sh]; auto& Nps = Nvs[pass.ps->sh]; #elif defined(USE_DX11) @@ -299,7 +299,7 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual) Nps.ds = pass.ds->sh; auto& Ncs = Nps.mapCS[pass.constants._get()]; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) auto& Ncs = Nps[pass.constants._get()]; #else # error No graphics API selected or enabled! @@ -326,7 +326,7 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual) if (SSA > Nps.mapCS.ssa) { Nps.mapCS.ssa = SSA; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) if (SSA > Nps.ssa) { Nps.ssa = SSA; @@ -352,7 +352,7 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual) } } -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) if (val_recorder) { val_recorder->push_back(pVisual->vis.box); @@ -511,7 +511,7 @@ void D3DXRenderBase::add_leafs_Static(dxRender_Visual* pVisual) return; mapLOD.insert_anyway(D, _LodItem({ ssa, pVisual })); } -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) if (ssa > r_ssaLOD_B || phase == CRender::PHASE_SMAP) #else if (ssa > r_ssaLOD_B) @@ -739,7 +739,7 @@ void D3DXRenderBase::add_Static(dxRender_Visual* pVisual, const CFrustum& view, return; mapLOD.insert_anyway(D, _LodItem({ ssa, pVisual })); } -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) if (ssa > r_ssaLOD_B || phase == CRender::PHASE_SMAP) #else if (ssa > r_ssaLOD_B) diff --git a/src/Layers/xrRender/r__dsgraph_render.cpp b/src/Layers/xrRender/r__dsgraph_render.cpp index f8bc7a7a82d..3ae2cb60f0c 100644 --- a/src/Layers/xrRender/r__dsgraph_render.cpp +++ b/src/Layers/xrRender/r__dsgraph_render.cpp @@ -127,7 +127,7 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority) RCache.set_GS(gs_it->first); mapNormalPS& ps = gs_it->second; -#elif defined(USE_DX9) +#elif defined(USE_DX9) || defined(USE_OGLR1) mapNormalPS& ps = vs_it->second; #else # error No graphics API selected or enabled! @@ -144,7 +144,7 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority) RCache.set_DS(ps_it->second.ds); mapNormalCS& cs = ps_it->second.mapCS; -#elif defined(USE_DX9) || defined(USE_OGL) +#elif defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) mapNormalCS& cs = ps_it->second; #else # error No graphics API selected or enabled! @@ -240,7 +240,7 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority) RCache.set_GS(gs_it->first); mapMatrixPS& ps = gs_it->second; -#elif defined(USE_DX9) +#elif defined(USE_DX9) || defined(USE_OGLR1) mapMatrixPS& ps = vs_id->second; #else # error No graphics API selected or enabled! @@ -257,7 +257,7 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority) RCache.set_DS(ps_it->second.ds); mapMatrixCS& cs = ps_it->second.mapCS; -#elif defined(USE_DX9) || defined(USE_OGL) +#elif defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) mapMatrixCS& cs = ps_it->second; #else # error No graphics API selected or enabled! @@ -458,7 +458,7 @@ void D3DXRenderBase::r_dsgraph_render_hud() sort_front_to_back_render_and_clean(mapHUD); } -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) if (g_hud && g_hud->RenderActiveItemUIQuery()) r_dsgraph_render_hud_ui(); // hud ui #endif @@ -472,7 +472,7 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui() hud_transform_helper helper; -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) // Targets, use accumulator for temporary storage const ref_rt rt_null; RCache.set_RT(0, 1); @@ -511,7 +511,7 @@ void D3DXRenderBase::r_dsgraph_render_sorted() // strict-sorted render void D3DXRenderBase::r_dsgraph_render_emissive() { -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) PIX_EVENT(r_dsgraph_render_emissive); sort_front_to_back_render_and_clean(mapEmissive); @@ -528,7 +528,7 @@ void D3DXRenderBase::r_dsgraph_render_emissive() // strict-sorted render void D3DXRenderBase::r_dsgraph_render_wmarks() { -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) PIX_EVENT(r_dsgraph_render_wmarks); sort_front_to_back_render_and_clean(mapWmark); @@ -623,7 +623,7 @@ void D3DXRenderBase::r_dsgraph_render_subspace(IRender_Sector* _sector, CFrustum renderable->renderable_Render(renderable); } } -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) // Actor Shadow (Sun + Light) if (g_pGameLevel && phase == RImplementation.PHASE_SMAP && ps_r__common_flags.test(RFLAG_ACTOR_SHADOW)) diff --git a/src/Layers/xrRender/r__dsgraph_types.h b/src/Layers/xrRender/r__dsgraph_types.h index 548e4035639..33ebc3d2c57 100644 --- a/src/Layers/xrRender/r__dsgraph_types.h +++ b/src/Layers/xrRender/r__dsgraph_types.h @@ -59,6 +59,9 @@ using ds_type = ID3D11DomainShader*; using vs_type = GLuint; using ps_type = GLuint; using gs_type = GLuint; +#elif defined(USE_OGLR1) +using vs_type = GLuint; +using ps_type = GLuint; #else # error No graphics API selected or enabled! #endif @@ -98,7 +101,7 @@ struct mapNormalPS : public xr_fixed_map { float ssa; }; -#elif defined(USE_DX9) || defined(USE_OGL) +#elif defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) struct mapNormalPS : public xr_fixed_map { float ssa; @@ -108,7 +111,7 @@ struct mapNormalPS : public xr_fixed_map #endif // !USE_DX9 && !USE_OGL -#if defined(USE_DX9) +#if defined(USE_DX9) || defined(USE_OGLR1) struct mapNormalVS : public xr_fixed_map {}; #elif defined(USE_DX11) || defined(USE_OGL) struct mapNormalGS : public xr_fixed_map @@ -159,7 +162,7 @@ struct mapMatrixPS : public xr_fixed_map { float ssa; }; -#elif defined(USE_DX9) || defined(USE_OGL) +#elif defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) struct mapMatrixPS : public xr_fixed_map { float ssa; @@ -169,7 +172,7 @@ struct mapMatrixPS : public xr_fixed_map #endif // !USE_DX9 && !USE_OGL -#if defined(USE_DX9) +#if defined(USE_DX9) || defined(USE_OGLR1) struct mapMatrixVS : public xr_fixed_map {}; #elif defined(USE_DX11) || defined(USE_OGL) struct mapMatrixGS : public xr_fixed_map diff --git a/src/Layers/xrRender/r__occlusion.h b/src/Layers/xrRender/r__occlusion.h index 0c3e401a699..be455d572f5 100644 --- a/src/Layers/xrRender/r__occlusion.h +++ b/src/Layers/xrRender/r__occlusion.h @@ -20,7 +20,7 @@ class R_occlusion u32 order; #if defined(USE_DX9) || defined(USE_DX11) ID3DQuery* Q; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) GLuint Q; #else # error No graphics API selected or enabled! @@ -36,7 +36,7 @@ class R_occlusion public: #if defined(USE_DX11) typedef u64 occq_result; -#elif defined(USE_DX9) || defined(USE_OGL) +#elif defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) typedef u32 occq_result; #else # error No graphics API selected or enabled! diff --git a/src/Layers/xrRender/r__pixel_calculator.cpp b/src/Layers/xrRender/r__pixel_calculator.cpp index 41dfc867612..81b1978b73e 100644 --- a/src/Layers/xrRender/r__pixel_calculator.cpp +++ b/src/Layers/xrRender/r__pixel_calculator.cpp @@ -17,7 +17,7 @@ void r_pixel_calculator::begin() RCache.set_RT(rt->pRT); #ifdef USE_DX11 RCache.set_ZB(zb->pZRT); -#elif defined(USE_DX9) || defined(USE_OGL) +#elif defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) RCache.set_ZB(zb->pRT); #endif @@ -88,7 +88,7 @@ r_aabb_ssa r_pixel_calculator::calculate(dxRender_Visual* V) } return result; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) VERIFY(!"Not implemented!"); return {}; #else diff --git a/src/Layers/xrRender/r__screenshot.cpp b/src/Layers/xrRender/r__screenshot.cpp index 93f67f0d1a9..d01b0e9f756 100644 --- a/src/Layers/xrRender/r__screenshot.cpp +++ b/src/Layers/xrRender/r__screenshot.cpp @@ -412,7 +412,7 @@ void CRender::ScreenshotImpl(ScreenshotMode mode, LPCSTR name, CMemoryWriter* me _RELEASE(pSrcTexture); } -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) // XXX: Provide full implementation void CRender::ScreenshotImpl(ScreenshotMode mode, LPCSTR name, CMemoryWriter* memory_writer) { @@ -490,7 +490,7 @@ void CRender::ScreenshotAsyncEnd(CMemoryWriter& memory_writer) if (hr != D3D_OK) return; -#if RENDER == R_R1 +#if (RENDER == R_R1) || (RENDER == R_GLR1) u32 rtWidth = Target->get_rtwidth(); u32 rtHeight = Target->get_rtheight(); #else // RENDER != R_R1 @@ -504,7 +504,7 @@ void CRender::ScreenshotAsyncEnd(CMemoryWriter& memory_writer) u32* pEnd = pPixel + (rtWidth * rtHeight); // Kill alpha -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) if (Target->rt_Color->fmt == D3DFMT_A16B16G16R16F) { static const int iMaxPixelsInARow = 1024; @@ -573,7 +573,7 @@ void CRender::ScreenshotAsyncEnd(CMemoryWriter& memory_writer) } HW.pContext->Unmap(pTex, 0); } -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) void CRender::ScreenshotAsyncEnd(CMemoryWriter &memory_writer) { // TODO: OGL: Implement screenshot feature. diff --git a/src/Layers/xrRender/r_constants.cpp b/src/Layers/xrRender/r_constants.cpp index 56281927d7f..89e7630ce69 100644 --- a/src/Layers/xrRender/r_constants.cpp +++ b/src/Layers/xrRender/r_constants.cpp @@ -218,7 +218,7 @@ void R_constant_table::merge(R_constant_table* T) C->type = src->type; C->ps = src->ps; C->vs = src->vs; -#ifndef USE_DX9 +#if !defined(USE_DX9) && !defined(USE_OGLR1) C->gs = src->gs; # if defined(USE_DX11) C->hs = src->hs; @@ -238,7 +238,7 @@ void R_constant_table::merge(R_constant_table* T) R_constant_load& dL = C->get_load(src->destination); dL.index = sL.index; dL.cls = sL.cls; -#ifdef USE_OGL +#if defined(USE_OGL) || defined(USE_OGLR1) dL.location = sL.location; dL.program = sL.program; #endif // USE_OGL diff --git a/src/Layers/xrRender/r_constants.h b/src/Layers/xrRender/r_constants.h index 4377b563f6a..d55cdcc15d9 100644 --- a/src/Layers/xrRender/r_constants.h +++ b/src/Layers/xrRender/r_constants.h @@ -76,7 +76,7 @@ struct ECORE_API R_constant_load #if defined(USE_DX9) || defined(USE_DX11) R_constant_load() : index(u16(-1)), cls(u16(-1)) {}; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) GLuint location; GLuint program; @@ -89,7 +89,7 @@ struct ECORE_API R_constant_load { #if defined(USE_DX9) || defined(USE_DX11) return (index == C.index) && (cls == C.cls); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) return (index == C.index) && (cls == C.cls) && (location == C.location) && (program == C.program); #else # error No graphics API selected or enabled! @@ -105,7 +105,7 @@ struct ECORE_API R_constant : public xr_resource R_constant_load ps; R_constant_load vs; -#ifndef USE_DX9 +#if !defined(USE_DX9) && !defined(USE_OGLR1) R_constant_load gs; # if defined(USE_DX11) R_constant_load hs; @@ -127,7 +127,7 @@ struct ECORE_API R_constant : public xr_resource case RC_dest_vertex: return vs; case RC_dest_pixel: return ps; case RC_dest_sampler: return samp; -#ifndef USE_DX9 +#if !defined(USE_DX9) && !defined(USE_OGLR1) case RC_dest_geometry: return gs; # if defined(USE_DX11) case RC_dest_hull: return hs; diff --git a/src/Layers/xrRender/r_constants_cache.h b/src/Layers/xrRender/r_constants_cache.h index 85d6d3d4ad2..9387725ea99 100644 --- a/src/Layers/xrRender/r_constants_cache.h +++ b/src/Layers/xrRender/r_constants_cache.h @@ -10,6 +10,8 @@ #include "Layers/xrRenderDX10/dx10r_constants_cache.h" #elif defined(USE_OGL) #include "Layers/xrRenderGL/glr_constants_cache.h" +#elif defined(USE_OGLR1) +#include "Layers/xrRenderGLR1/glr_constants_cache.h" #else # error No graphics API selected or enabled! #endif diff --git a/src/Layers/xrRender/stats_manager.cpp b/src/Layers/xrRender/stats_manager.cpp index 7f079cefd1b..63cb73ed665 100644 --- a/src/Layers/xrRender/stats_manager.cpp +++ b/src/Layers/xrRender/stats_manager.cpp @@ -44,7 +44,7 @@ void stats_manager::increment_stats_rtarget(ID3DTexture2D* buff) return; _D3DPOOL pool = D3DPOOL_MANAGED; -#if defined(USE_DX9) +#if defined(USE_DX9) || defined(USE_OGLR1) D3DSURFACE_DESC desc; buff->GetLevelDesc(0, &desc); pool = desc.Pool; diff --git a/src/Layers/xrRender/tss_def.cpp b/src/Layers/xrRender/tss_def.cpp index 2414743ce77..dc4eb44b9aa 100644 --- a/src/Layers/xrRender/tss_def.cpp +++ b/src/Layers/xrRender/tss_def.cpp @@ -5,6 +5,8 @@ #ifdef USE_OGL #include "../xrRenderGL/glState.h" +#elif defined(USE_OGLR1) +#include "../xrRenderGLR1/glState.h" #endif // TODO: DX10: Implement equivalent for SimulatorStates::record for DX10 @@ -31,7 +33,7 @@ void SimulatorStates::record(ID3DState*& state) #elif defined(USE_DX11) // VERIFY(!"SimulatorStates::record not implemented!"); state = ID3DState::Create(*this); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) state = ID3DState::Create(); for (SimulatorStates::State& S : States) { diff --git a/src/Layers/xrRender/tss_def.h b/src/Layers/xrRender/tss_def.h index 31d50390860..5774f170d59 100644 --- a/src/Layers/xrRender/tss_def.h +++ b/src/Layers/xrRender/tss_def.h @@ -5,6 +5,8 @@ #if defined(USE_OGL) #include "../xrRenderGL/glState.h" +#elif defined(USE_OGLR1) +#include "../xrRenderGLR1/glState.h" #endif class SimulatorStates diff --git a/src/Layers/xrRender/xrRender_console.cpp b/src/Layers/xrRender/xrRender_console.cpp index 19ea691d62f..7d20afdb459 100644 --- a/src/Layers/xrRender/xrRender_console.cpp +++ b/src/Layers/xrRender/xrRender_console.cpp @@ -11,7 +11,7 @@ const xr_token qpreset_token[] = {{"Minimum", 0}, {"Low", 1}, {"Default", 2}, {" u32 ps_r2_smapsize = 2048; const xr_token qsmapsize_token[] = { -#if !defined(MASTER_GOLD) || RENDER == R_R1 +#if !defined(MASTER_GOLD) || RENDER == R_R1 || RENDER == R_GLR1 { "256", 256 }, // Too bad for R2+ { "512", 512 }, // But works #endif @@ -23,7 +23,7 @@ const xr_token qsmapsize_token[] = { "3072", 3072 }, { "3584", 3584 }, { "4096", 4096 }, -#if defined(USE_DX11) || defined(USE_OGL) // XXX: check if values more than 8192 are supported on OpenGL +#if defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) // XXX: check if values more than 8192 are supported on OpenGL { "5120", 5120 }, { "6144", 6144 }, { "7168", 7168 }, @@ -297,7 +297,7 @@ class CCC_tf_Aniso : public CCC_Integer CHK_DX(HW.pDevice->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, val)); #elif defined(USE_DX11) SSManager.SetMaxAnisotropy(val); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) // OGL: don't set aniso here because it will be updated after vid restart #else # error No graphics API selected or enabled! @@ -559,7 +559,7 @@ class CCC_TexturesStat final : public IConsole_Command } }; -#if RENDER != R_R1 +#if (RENDER != R_R1) && (RENDER != R_GLR1) #include "r__pixel_calculator.h" class CCC_BuildSSA : public IConsole_Command { @@ -736,8 +736,8 @@ void xrRender_initconsole() CMD1(CCC_Screenshot, "screenshot"); #ifdef DEBUG -#if RENDER != R_R1 - CMD1(CCC_BuildSSA, "build_ssa"); +#if (RENDER != R_R1) && (RENDER != R_GLR1) + //CMD1(CCC_BuildSSA, "build_ssa"); #endif CMD4(CCC_Integer, "r__lsleep_frames", &ps_r__LightSleepFrames, 4, 30); CMD4(CCC_Float, "r__ssa_glod_start", &ps_r__GLOD_ssa_start, 128, 512); @@ -848,8 +848,8 @@ void xrRender_initconsole() CMD4(CCC_Float, "r2_sun_tsm_proj", &ps_r2_sun_tsm_projection, .001f, 0.8f); CMD4(CCC_Float, "r2_sun_tsm_bias", &ps_r2_sun_tsm_bias, -0.5, +0.5); CMD4(CCC_Float, "r2_sun_near", &ps_r2_sun_near, 1.f, 150.f); //AVO: extended from 50.f to 150.f -#if RENDER != R_R1 - CMD4(CCC_Float, "r2_sun_far", &OLES_SUN_LIMIT_27_01_07, 51.f, 180.f); +#if (RENDER != R_R1) && (RENDER != RGLR1) + //CMD4(CCC_Float, "r2_sun_far", &OLES_SUN_LIMIT_27_01_07, 51.f, 180.f); #endif CMD4(CCC_Float, "r2_sun_near_border", &ps_r2_sun_near_border, .5f, 1.0f); CMD4(CCC_Float, "r2_sun_depth_far_scale", &ps_r2_sun_depth_far_scale, 0.5, 1.5); @@ -920,7 +920,7 @@ void xrRender_initconsole() #ifdef DEBUG CMD4(CCC_SunshaftsIntensity, "r__sunshafts_intensity", &SunshaftsIntensity, 0.f, 1.f); #endif - +/* CMD3(CCC_Mask, "r2_volumetric_lights", &ps_r2_ls_flags, R2FLAG_VOLUMETRIC_LIGHTS); //CMD3(CCC_Mask, "r2_sun_shafts", &ps_r2_ls_flags, R2FLAG_SUN_SHAFTS); CMD3(CCC_Token, "r2_sun_shafts", &ps_r_sun_shafts, qsun_shafts_token); @@ -955,7 +955,7 @@ void xrRender_initconsole() //CMD3(CCC_Mask, "r3_msaa_alphatest", &ps_r2_ls_flags, (u32)R3FLAG_MSAA_ALPHATEST); CMD3(CCC_Token, "r3_msaa_alphatest", &ps_r3_msaa_atest, qmsaa__atest_token); CMD3(CCC_Token, "r3_minmax_sm", &ps_r3_minmax_sm, qminmax_sm_token); - +*/ // Allow real-time fog config reload #if (RENDER == R_R3) || (RENDER == R_R4) # ifndef MASTER_GOLD diff --git a/src/Layers/xrRender/xr_effgamma.cpp b/src/Layers/xrRender/xr_effgamma.cpp index cd52599b73b..8cce45fc0cc 100644 --- a/src/Layers/xrRender/xr_effgamma.cpp +++ b/src/Layers/xrRender/xr_effgamma.cpp @@ -56,7 +56,7 @@ void CGammaControl::GenLUT(const DXGI_GAMMA_CONTROL_CAPABILITIES& GC, DXGI_GAMMA } } -#elif defined(USE_DX9) || defined(USE_OGL) // !USE_DX9 && !USE_OGL +#elif defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) // !USE_DX9 && !USE_OGL IC u16 clr2gamma(float c) { diff --git a/src/Layers/xrRender/xr_effgamma.h b/src/Layers/xrRender/xr_effgamma.h index 166810adf97..b24a232cd95 100644 --- a/src/Layers/xrRender/xr_effgamma.h +++ b/src/Layers/xrRender/xr_effgamma.h @@ -37,7 +37,7 @@ class CGammaControl private: #if defined(USE_DX11) void GenLUT(const DXGI_GAMMA_CONTROL_CAPABILITIES& GC, DXGI_GAMMA_CONTROL& G); -#elif defined(USE_DX9) || defined(USE_OGL) +#elif defined(USE_DX9) || defined(USE_OGL) || defined(USE_OGLR1) void GenLUT(D3DGAMMARAMP& G); #else # error No graphics API selected or enabled! diff --git a/src/Layers/xrRender_R2/r2.cpp b/src/Layers/xrRender_R2/r2.cpp index 750520b2c6d..96ec8a746c5 100644 --- a/src/Layers/xrRender_R2/r2.cpp +++ b/src/Layers/xrRender_R2/r2.cpp @@ -85,7 +85,7 @@ static class cl_pos_decompress_params : public R_constant_setup #if defined(USE_DX9) || defined(USE_DX11) const float VertTan = -1.0f * tanf(deg2rad(Device.fFOV / 2.0f)); const float HorzTan = -VertTan / Device.fASPECT; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) const float VertTan = tanf(deg2rad(Device.fFOV / 2.0f)); const float HorzTan = VertTan / Device.fASPECT; #else @@ -235,7 +235,7 @@ void CRender::create() #ifdef USE_DX9 D3DFORMAT nullrt = (D3DFORMAT)MAKEFOURCC('N', 'U', 'L', 'L'); o.nullrt = HW.support(nullrt, D3DRTYPE_SURFACE, D3DUSAGE_RENDERTARGET); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) o.nullrt = false; #else # error No graphics API selected or enabled! @@ -306,7 +306,7 @@ void CRender::create() o.HW_smap_FETCH4 = FALSE; #ifdef USE_DX9 o.HW_smap = HW.support(D3DFMT_D24X8, D3DRTYPE_TEXTURE, D3DUSAGE_DEPTHSTENCIL); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) o.HW_smap = true; #else # error No graphics API selected or enabled! @@ -344,7 +344,7 @@ void CRender::create() #ifdef USE_DX9 o.fp16_filter = HW.support(D3DFMT_A16B16G16R16F, D3DRTYPE_TEXTURE, D3DUSAGE_QUERY_FILTER); o.fp16_blend = HW.support(D3DFMT_A16B16G16R16F, D3DRTYPE_TEXTURE, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) o.fp16_filter = true; o.fp16_blend = true; #else @@ -390,7 +390,7 @@ void CRender::create() // nv-dbt #ifdef USE_DX9 o.nvdbt = HW.support((D3DFORMAT)MAKEFOURCC('N', 'V', 'D', 'B'), D3DRTYPE_SURFACE, 0); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) o.nvdbt = false; #else # error No graphics API selected or enabled! @@ -464,7 +464,7 @@ void CRender::create() o.ssao_ultra = HW.ComputeShadersSupported && ssao_hdao_cs_shaders_exist(); # endif o.ssao_hbao = !o.ssao_hdao && ps_r2_ls_flags_ext.test(R2FLAGEXT_SSAO_HBAO) && (ps_r_ssao != 0); -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) // TODO: OGL: temporary disabled HBAO/HDAO, need to fix it o.ssao_hbao = false; o.ssao_hdao = false; @@ -478,7 +478,7 @@ void CRender::create() o.ssao_opt_data = false; o.ssao_hbao = false; } -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) // TODO: fix hbao shader to allow to perform per-subsample effect! o.hbao_vectorized = false; if (o.ssao_hdao) diff --git a/src/Layers/xrRender_R2/r2_R_render.cpp b/src/Layers/xrRender_R2/r2_R_render.cpp index b253315502f..ee8fc5591b6 100644 --- a/src/Layers/xrRender_R2/r2_R_render.cpp +++ b/src/Layers/xrRender_R2/r2_R_render.cpp @@ -192,7 +192,7 @@ void CRender::render_menu() pv++; pv->set(float(_w + EPS), EPS, d_Z, d_W, C, p1.x, p0.y); pv++; -#elif defined(USE_OGL) +#elif defined(USE_OGL) || defined(USE_OGLR1) pv->set(EPS, EPS, d_Z, d_W, C, p0.x, p0.y); pv++; pv->set(EPS, float(_h + EPS), d_Z, d_W, C, p0.x, p1.y); @@ -507,7 +507,7 @@ void CRender::Render() RCache.set_xform_project(Device.mProject); RCache.set_xform_view(Device.mView); // Stencil - write 0x1 at pixel pos - -#if defined(USE_DX9) +#if defined(USE_DX9) || defined(USE_OGLR1) RCache.set_Stencil(TRUE, D3DCMP_ALWAYS, 0x01, 0xff, 0xff, D3DSTENCILOP_KEEP, D3DSTENCILOP_REPLACE, D3DSTENCILOP_KEEP); #elif defined(USE_DX11) || defined(USE_OGL) From e98ff79baa8f7e532f46f19965e00f8c6c542f2d Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Tue, 10 May 2022 18:24:29 +0300 Subject: [PATCH 5/9] fix Windows build + fix few typos like if (RENDER != R_R1) || (RENDER != R_GLR1) --- src/Layers/xrRender/FTreeVisual.cpp | 2 +- src/Layers/xrRender/blenders/Blender_LaEmB.cpp | 2 +- src/Layers/xrRender/dxDebugRender.cpp | 2 +- src/Layers/xrRenderPC_GL/stdafx.h | 1 + src/Layers/xrRenderPC_GLR1/stdafx.h | 2 +- src/Layers/xrRenderPC_R1/stdafx.h | 1 + src/Layers/xrRenderPC_R2/stdafx.h | 1 + src/Layers/xrRenderPC_R4/stdafx.h | 1 + 8 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Layers/xrRender/FTreeVisual.cpp b/src/Layers/xrRender/FTreeVisual.cpp index 742018ad623..55423226a44 100644 --- a/src/Layers/xrRender/FTreeVisual.cpp +++ b/src/Layers/xrRender/FTreeVisual.cpp @@ -121,7 +121,7 @@ void FTreeVisual::Render(float /*LOD*/) if (tvs.dwFrame != Device.dwFrame) tvs.calculate(); // setup constants -#if (RENDER != R_R1) || (RENDER != R_GLR1) +#if (RENDER != R_R1) && (RENDER != R_GLR1) Fmatrix xform_v; xform_v.mul_43(RCache.get_xform_view(), xform); RCache.tree.set_m_xform_v(xform_v); // matrix diff --git a/src/Layers/xrRender/blenders/Blender_LaEmB.cpp b/src/Layers/xrRender/blenders/Blender_LaEmB.cpp index ba753dfe5c3..b82acc631fa 100644 --- a/src/Layers/xrRender/blenders/Blender_LaEmB.cpp +++ b/src/Layers/xrRender/blenders/Blender_LaEmB.cpp @@ -8,7 +8,7 @@ * Consider removing. */ -#if (RENDER != R_R1) || (RENDER != R_GLR1) +#if (RENDER != R_R1) && (RENDER != R_GLR1) #error "The blender can't be used in this renderer generation" #endif diff --git a/src/Layers/xrRender/dxDebugRender.cpp b/src/Layers/xrRender/dxDebugRender.cpp index ef8b55f06c9..eb6e67f6cac 100644 --- a/src/Layers/xrRender/dxDebugRender.cpp +++ b/src/Layers/xrRender/dxDebugRender.cpp @@ -100,7 +100,7 @@ void dxDebugRender::SetAmbient(u32 colour) { #if defined(USE_DX9) CHK_DX(HW.pDevice->SetRenderState(D3DRS_AMBIENT, colour)); -#elif defined(USE_DX11) || defined(USE_OGL) +#elif defined(USE_DX11) || defined(USE_OGL) || defined(USE_OGLR1) // TODO: DX10: Check if need this for DX10 VERIFY(!"Not implemented for DX10"); UNUSED(colour); diff --git a/src/Layers/xrRenderPC_GL/stdafx.h b/src/Layers/xrRenderPC_GL/stdafx.h index e0a80dd456a..40bf5b3247a 100644 --- a/src/Layers/xrRenderPC_GL/stdafx.h +++ b/src/Layers/xrRenderPC_GL/stdafx.h @@ -38,6 +38,7 @@ #define R_R2 2 #define R_R3 3 #define R_R4 4 +#define R_GLR1 5 #define RENDER R_GL #include "Common/_d3d_extensions.h" diff --git a/src/Layers/xrRenderPC_GLR1/stdafx.h b/src/Layers/xrRenderPC_GLR1/stdafx.h index 2e2f6717f41..ca8a4ea42f1 100755 --- a/src/Layers/xrRenderPC_GLR1/stdafx.h +++ b/src/Layers/xrRenderPC_GLR1/stdafx.h @@ -38,11 +38,11 @@ #include "Layers/xrRender/Blender_CLSID.h" #define R_GL 0 -#define R_GLR1 5 #define R_R1 1 #define R_R2 2 #define R_R3 3 #define R_R4 4 +#define R_GLR1 5 #define RENDER R_GLR1 #include "Common/_d3d_extensions.h" diff --git a/src/Layers/xrRenderPC_R1/stdafx.h b/src/Layers/xrRenderPC_R1/stdafx.h index ca2806f4b47..8c1aa6bceb4 100644 --- a/src/Layers/xrRenderPC_R1/stdafx.h +++ b/src/Layers/xrRenderPC_R1/stdafx.h @@ -36,6 +36,7 @@ #define R_R2 2 #define R_R3 3 #define R_R4 4 +#define R_GLR1 5 #define RENDER R_R1 #include "Common/_d3d_extensions.h" diff --git a/src/Layers/xrRenderPC_R2/stdafx.h b/src/Layers/xrRenderPC_R2/stdafx.h index abe4077376d..33088841a4b 100644 --- a/src/Layers/xrRenderPC_R2/stdafx.h +++ b/src/Layers/xrRenderPC_R2/stdafx.h @@ -34,6 +34,7 @@ #define R_R2 2 #define R_R3 3 #define R_R4 4 +#define R_GLR1 5 #define RENDER R_R2 #include "Common/_d3d_extensions.h" diff --git a/src/Layers/xrRenderPC_R4/stdafx.h b/src/Layers/xrRenderPC_R4/stdafx.h index a9ed05dcfd3..164651810d1 100644 --- a/src/Layers/xrRenderPC_R4/stdafx.h +++ b/src/Layers/xrRenderPC_R4/stdafx.h @@ -52,6 +52,7 @@ #define R_R2 2 #define R_R3 3 #define R_R4 4 +#define R_GLR1 5 #define RENDER R_R4 #include "Common/_d3d_extensions.h" From 46f8a1390a3f65a27d9d8028973924729b1b9f41 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Wed, 11 May 2022 21:54:50 +0300 Subject: [PATCH 6/9] add Windows build of xrRenderPC_GLR1 --- src/Layers/xrRenderPC_GLR1/xrRender_GLR1.cpp | 2 +- .../xrRenderPC_GLR1/xrRender_GLR1.vcxproj | 66 +++++++++++-------- src/engine.sln | 18 +++++ 3 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.cpp b/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.cpp index 30107a8e7b1..d146648b351 100755 --- a/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.cpp +++ b/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.cpp @@ -24,7 +24,7 @@ class RGLRendererModule final : public RendererModule Log("~ No shaders found for xrRender_GLR1"); return false; } - return xrRender_test_hw; + return xrRender_test_hw(); } const xr_vector& ObtainSupportedModes() override diff --git a/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj b/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj index 4dcc8e3c6d0..f107689d52b 100755 --- a/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj +++ b/src/Layers/xrRenderPC_GLR1/xrRender_GLR1.vcxproj @@ -4,8 +4,8 @@ - {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E2} - xrRender_R1 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3} + xrRender_GLR1 Win32Proj @@ -22,11 +22,11 @@ - $(xrExternals)OpenAutomate\inc;$(xrSdkDir)include\nvapi;%(AdditionalIncludeDirectories) - _USRDLL;XRRENDER_R1_EXPORTS;USE_DX9;%(PreprocessorDefinitions) + $(xrExternals)OpenAutomate\inc;$(xrExternals)gl\include;$(xrExternals)glew\include;$(xrExternals)gli;$(xrExternals)gli\external\glm;%(AdditionalIncludeDirectories) + _USRDLL;USE_OGLR1;NO_XR_VDECLARATOR;%(PreprocessorDefinitions) - nvapi$(PlatformArchitecture).lib;%(AdditionalDependencies) + opengl32.lib;glew32s.lib;%(AdditionalDependencies) $(xrExternals)OpenAutomate\libraries;%(AdditionalLibraryDirectories) $(xrExternals)nvapi\x86;%(AdditionalLibraryDirectories) $(xrExternals)nvapi\amd64;%(AdditionalLibraryDirectories) @@ -58,10 +58,6 @@ - - - - @@ -155,7 +151,7 @@ - + @@ -163,16 +159,23 @@ - + - + + + + + + + + @@ -183,12 +186,6 @@ - - - - - - @@ -274,46 +271,59 @@ + - + - - + + - + - + + + + + + + + + + + + + Create - + @@ -359,17 +369,17 @@ - - + + Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}. - - + + \ No newline at end of file diff --git a/src/engine.sln b/src/engine.sln index 853dad8c600..1b2a5ee65fd 100644 --- a/src/engine.sln +++ b/src/engine.sln @@ -199,6 +199,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mimalloc", "..\Externals\mi EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xrWeatherEngine", "editors\xrWeatherEngine\xrWeatherEngine.vcxproj", "{FABD5BBF-EA6F-4633-A34F-95CDC553CA36}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xrRender_GLR1", "Layers\xrRenderPC_GLR1\xrRender_GLR1.vcxproj", "{57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -1165,6 +1167,22 @@ Global {FABD5BBF-EA6F-4633-A34F-95CDC553CA36}.Release|x64.Build.0 = Release|x64 {FABD5BBF-EA6F-4633-A34F-95CDC553CA36}.Release|x86.ActiveCfg = Release|Win32 {FABD5BBF-EA6F-4633-A34F-95CDC553CA36}.Release|x86.Build.0 = Release|Win32 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Debug|x64.ActiveCfg = Debug|x64 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Debug|x64.Build.0 = Debug|x64 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Debug|x86.ActiveCfg = Debug|Win32 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Debug|x86.Build.0 = Debug|Win32 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Mixed|x64.ActiveCfg = Mixed|x64 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Mixed|x64.Build.0 = Mixed|x64 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Mixed|x86.ActiveCfg = Mixed|Win32 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Mixed|x86.Build.0 = Mixed|Win32 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Release Master Gold|x64.ActiveCfg = Release Master Gold|x64 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Release Master Gold|x64.Build.0 = Release Master Gold|x64 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Release Master Gold|x86.ActiveCfg = Release Master Gold|Win32 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Release Master Gold|x86.Build.0 = Release Master Gold|Win32 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Release|x64.ActiveCfg = Release|x64 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Release|x64.Build.0 = Release|x64 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Release|x86.ActiveCfg = Release|Win32 + {57A498C9-A741-4DDF-8EFC-BFB9EB6B00E3}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From c52d534631055fbcb9b8c230b085abfa17b7c8ac Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Wed, 11 May 2022 21:59:55 +0300 Subject: [PATCH 7/9] Remove XRRENDER_*_EXPORTS from *.vcxproj --- src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj | 2 +- src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj | 2 +- src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj | 2 +- src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj b/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj index b8811a0dccd..2d1a27aaac5 100644 --- a/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj +++ b/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj @@ -23,7 +23,7 @@ $(SolutionDir)Layers\xrRender_R2;$(xrExternals)OpenAutomate\inc;$(xrExternals)gl\include;$(xrExternals)glew\include;$(xrExternals)gli;$(xrExternals)gli\external\glm;$(xrExternals)AGS_SDK;$(xrExternals)glslang\glslang\Public;$(xrExternals)sse2neon\include;%(AdditionalIncludeDirectories) - _USRDLL;XRRENDER_GL_EXPORTS;USE_OGL;NO_XR_VDECLARATOR;%(PreprocessorDefinitions) + _USRDLL;USE_OGL;NO_XR_VDECLARATOR;%(PreprocessorDefinitions) opengl32.lib;glew32s.lib;glu32.lib;oalib.lib;nvapi$(PlatformArchitecture).lib;amd_ags_$(PlatformShortName).lib;%(AdditionalDependencies) diff --git a/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj b/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj index c217c223134..604234fe9dd 100644 --- a/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj +++ b/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj @@ -23,7 +23,7 @@ $(xrExternals)OpenAutomate\inc;$(xrSdkDir)include\nvapi;%(AdditionalIncludeDirectories) - _USRDLL;XRRENDER_R1_EXPORTS;USE_DX9;%(PreprocessorDefinitions) + _USRDLL;USE_DX9;%(PreprocessorDefinitions) nvapi$(PlatformArchitecture).lib;%(AdditionalDependencies) diff --git a/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj b/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj index f31ea673e94..7759c73ae39 100644 --- a/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj +++ b/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj @@ -22,7 +22,7 @@ - _USRDLL;XRRENDER_R2_EXPORTS;USE_DX9;%(PreprocessorDefinitions) + _USRDLL;USE_DX9;%(PreprocessorDefinitions) $(SolutionDir)Layers\xrRender_R2;$(xrExternals)OpenAutomate\inc;$(xrSdkDir)include\nvapi;%(AdditionalIncludeDirectories) diff --git a/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj b/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj index 61f0a30369e..4fd80d1887a 100644 --- a/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj +++ b/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj @@ -23,7 +23,7 @@ $(SolutionDir)Layers\xrRender_R2;$(xrExternals)OpenAutomate\inc;$(xrSdkDir)include\nvapi;$(xrExternals)AGS_SDK;%(AdditionalIncludeDirectories) - _USRDLL;XRRENDER_R4_EXPORTS;USE_DX11;%(PreprocessorDefinitions) + _USRDLL;USE_DX11;%(PreprocessorDefinitions) dxguid.lib;d3dcompiler.lib;nvapi$(PlatformArchitecture).lib;%(AdditionalDependencies) From 831da0b4a7e6f8ab4ba02e6ce5bf21108f99eb3f Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Wed, 11 May 2022 22:00:54 +0300 Subject: [PATCH 8/9] Enable Linux build for xrRenderPC_GL --- src/Layers/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Layers/CMakeLists.txt b/src/Layers/CMakeLists.txt index ab97c177134..397406d4ae6 100644 --- a/src/Layers/CMakeLists.txt +++ b/src/Layers/CMakeLists.txt @@ -3,5 +3,5 @@ add_subdirectory(xrAPI) #add_subdirectory(xrRenderPC_R2) #add_subdirectory(xrRenderPC_R3) #add_subdirectory(xrRenderPC_R4) -#add_subdirectory(xrRenderPC_GL) +add_subdirectory(xrRenderPC_GL) add_subdirectory(xrRenderPC_GLR1) From ccc2c6eb0f519428ffda4acaef79e35391a3701f Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Tue, 17 May 2022 00:09:14 +0300 Subject: [PATCH 9/9] [glr1] restore original xrRender_initconsole --- src/Layers/xrRender/xrRender_console.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Layers/xrRender/xrRender_console.cpp b/src/Layers/xrRender/xrRender_console.cpp index 7d20afdb459..64311dd61ad 100644 --- a/src/Layers/xrRender/xrRender_console.cpp +++ b/src/Layers/xrRender/xrRender_console.cpp @@ -737,7 +737,7 @@ void xrRender_initconsole() #ifdef DEBUG #if (RENDER != R_R1) && (RENDER != R_GLR1) - //CMD1(CCC_BuildSSA, "build_ssa"); + CMD1(CCC_BuildSSA, "build_ssa"); #endif CMD4(CCC_Integer, "r__lsleep_frames", &ps_r__LightSleepFrames, 4, 30); CMD4(CCC_Float, "r__ssa_glod_start", &ps_r__GLOD_ssa_start, 128, 512); @@ -848,8 +848,8 @@ void xrRender_initconsole() CMD4(CCC_Float, "r2_sun_tsm_proj", &ps_r2_sun_tsm_projection, .001f, 0.8f); CMD4(CCC_Float, "r2_sun_tsm_bias", &ps_r2_sun_tsm_bias, -0.5, +0.5); CMD4(CCC_Float, "r2_sun_near", &ps_r2_sun_near, 1.f, 150.f); //AVO: extended from 50.f to 150.f -#if (RENDER != R_R1) && (RENDER != RGLR1) - //CMD4(CCC_Float, "r2_sun_far", &OLES_SUN_LIMIT_27_01_07, 51.f, 180.f); +#if (RENDER != R_R1) && (RENDER != R_GLR1) + CMD4(CCC_Float, "r2_sun_far", &OLES_SUN_LIMIT_27_01_07, 51.f, 180.f); #endif CMD4(CCC_Float, "r2_sun_near_border", &ps_r2_sun_near_border, .5f, 1.0f); CMD4(CCC_Float, "r2_sun_depth_far_scale", &ps_r2_sun_depth_far_scale, 0.5, 1.5); @@ -920,7 +920,7 @@ void xrRender_initconsole() #ifdef DEBUG CMD4(CCC_SunshaftsIntensity, "r__sunshafts_intensity", &SunshaftsIntensity, 0.f, 1.f); #endif -/* + CMD3(CCC_Mask, "r2_volumetric_lights", &ps_r2_ls_flags, R2FLAG_VOLUMETRIC_LIGHTS); //CMD3(CCC_Mask, "r2_sun_shafts", &ps_r2_ls_flags, R2FLAG_SUN_SHAFTS); CMD3(CCC_Token, "r2_sun_shafts", &ps_r_sun_shafts, qsun_shafts_token); @@ -954,8 +954,8 @@ void xrRender_initconsole() CMD3(CCC_Mask, "r3_use_dx10_1", &ps_r2_ls_flags, (u32)R3FLAG_USE_DX10_1); //CMD3(CCC_Mask, "r3_msaa_alphatest", &ps_r2_ls_flags, (u32)R3FLAG_MSAA_ALPHATEST); CMD3(CCC_Token, "r3_msaa_alphatest", &ps_r3_msaa_atest, qmsaa__atest_token); + CMD3(CCC_Token, "r3_minmax_sm", &ps_r3_minmax_sm, qminmax_sm_token); -*/ // Allow real-time fog config reload #if (RENDER == R_R3) || (RENDER == R_R4) # ifndef MASTER_GOLD