Add support for main view information in Surface materials during subpass rendering (eg. shadow depth)
This commit is contained in:
@@ -22,6 +22,8 @@ PACK_STRUCT(struct DeferredMaterialShaderData {
|
||||
Matrix ViewMatrix;
|
||||
Matrix PrevViewProjectionMatrix;
|
||||
Matrix PrevWorldMatrix;
|
||||
Matrix MainViewProjectionMatrix;
|
||||
Float4 MainScreenSize;
|
||||
Float3 ViewPos;
|
||||
float ViewFar;
|
||||
Float3 ViewDir;
|
||||
@@ -86,6 +88,8 @@ void DeferredMaterialShader::Bind(BindParameters& params)
|
||||
Matrix::Transpose(view.View, materialData->ViewMatrix);
|
||||
Matrix::Transpose(drawCall.Surface.PrevWorld, materialData->PrevWorldMatrix);
|
||||
Matrix::Transpose(view.PrevViewProjection, materialData->PrevViewProjectionMatrix);
|
||||
Matrix::Transpose(view.MainViewProjection, materialData->MainViewProjectionMatrix);
|
||||
materialData->MainScreenSize = view.MainScreenSize;
|
||||
materialData->ViewPos = view.Position;
|
||||
materialData->ViewFar = view.Far;
|
||||
materialData->ViewDir = view.Direction;
|
||||
|
||||
@@ -24,6 +24,8 @@ PACK_STRUCT(struct ForwardMaterialShaderData {
|
||||
Matrix ViewMatrix;
|
||||
Matrix PrevViewProjectionMatrix;
|
||||
Matrix PrevWorldMatrix;
|
||||
Matrix MainViewProjectionMatrix;
|
||||
Float4 MainScreenSize;
|
||||
Float3 ViewPos;
|
||||
float ViewFar;
|
||||
Float3 ViewDir;
|
||||
@@ -94,6 +96,8 @@ void ForwardMaterialShader::Bind(BindParameters& params)
|
||||
Matrix::Transpose(view.View, materialData->ViewMatrix);
|
||||
Matrix::Transpose(drawCall.Surface.PrevWorld, materialData->PrevWorldMatrix);
|
||||
Matrix::Transpose(view.PrevViewProjection, materialData->PrevViewProjectionMatrix);
|
||||
Matrix::Transpose(view.MainViewProjection, materialData->MainViewProjectionMatrix);
|
||||
materialData->MainScreenSize = view.MainScreenSize;
|
||||
materialData->ViewPos = view.Position;
|
||||
materialData->ViewFar = view.Far;
|
||||
materialData->ViewDir = view.Direction;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/// <summary>
|
||||
/// Current materials shader version.
|
||||
/// </summary>
|
||||
#define MATERIAL_GRAPH_VERSION 154
|
||||
#define MATERIAL_GRAPH_VERSION 155
|
||||
|
||||
class Material;
|
||||
class GPUShader;
|
||||
|
||||
@@ -60,7 +60,7 @@ void RenderView::Prepare(RenderContext& renderContext)
|
||||
PrepareCache(renderContext, width, height, taaJitter);
|
||||
}
|
||||
|
||||
void RenderView::PrepareCache(RenderContext& renderContext, float width, float height, const Float2& temporalAAJitter)
|
||||
void RenderView::PrepareCache(RenderContext& renderContext, float width, float height, const Float2& temporalAAJitter, RenderView* mainView)
|
||||
{
|
||||
// The same format used by the Flax common shaders and postFx materials
|
||||
ViewInfo = Float4(1.0f / Projection.M11, 1.0f / Projection.M22, Far / (Far - Near), (-Far * Near) / (Far - Near) / Far);
|
||||
@@ -76,6 +76,12 @@ void RenderView::PrepareCache(RenderContext& renderContext, float width, float h
|
||||
// Ortho views have issues with screen size LOD culling
|
||||
const float modelLODDistanceFactor = (renderContext.LodProxyView ? renderContext.LodProxyView->IsOrthographicProjection() : IsOrthographicProjection()) ? 100.0f : ModelLODDistanceFactor;
|
||||
ModelLODDistanceFactorSqrt = modelLODDistanceFactor * modelLODDistanceFactor;
|
||||
|
||||
// Setup main view render info
|
||||
if (!mainView)
|
||||
mainView = this;
|
||||
MainViewProjection = mainView->ViewProjection();
|
||||
MainScreenSize = mainView->ScreenSize;
|
||||
}
|
||||
|
||||
void RenderView::SetUp(const Matrix& view, const Matrix& projection)
|
||||
|
||||
@@ -202,6 +202,16 @@ public:
|
||||
/// </summary>
|
||||
API_FIELD() Matrix PrevViewProjection;
|
||||
|
||||
/// <summary>
|
||||
/// The main viewport view * projection matrix.
|
||||
/// </summary>
|
||||
API_FIELD() Matrix MainViewProjection;
|
||||
|
||||
/// <summary>
|
||||
/// The main viewport screen size packed (x - width, y - height, zw - inv width, w - inv height).
|
||||
/// </summary>
|
||||
API_FIELD() Float4 MainScreenSize;
|
||||
|
||||
/// <summary>
|
||||
/// Square of <see cref="ModelLODDistanceFactor"/>. Cached by rendering backend.
|
||||
/// </summary>
|
||||
@@ -220,7 +230,8 @@ public:
|
||||
/// <param name="width">The rendering width.</param>
|
||||
/// <param name="height">The rendering height.</param>
|
||||
/// <param name="temporalAAJitter">The temporal jitter for this frame.</param>
|
||||
void PrepareCache(RenderContext& renderContext, float width, float height, const Float2& temporalAAJitter);
|
||||
/// <param name="mainView">The main rendering viewport. Use null if it's top level view; pass pointer to main view for sub-passes like shadow depths.</param>
|
||||
void PrepareCache(RenderContext& renderContext, float width, float height, const Float2& temporalAAJitter, RenderView* mainView = nullptr);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether view is perspective projection or orthographic.
|
||||
|
||||
Reference in New Issue
Block a user