Skip to content

Commit 63ba6a3

Browse files
committed
Samples: InstancedViewports - refactor to work with Cameras
1 parent 0baa453 commit 63ba6a3

File tree

4 files changed

+119
-251
lines changed

4 files changed

+119
-251
lines changed

Samples/Media/materials/programs/GLSL/SampleLib_InstancedViewports.glsl

+8-22
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,22 @@ furnished to do so, subject to the following conditions:
2929
// Transform the output position to the current "monitor"
3030
//-----------------------------------------------------------------------------
3131

32+
#ifdef OGRE_VERTEX_SHADER
3233
void SGX_InstancedViewportsTransform(
3334
in vec4 i_position,
34-
in mat4 i_worldViewMatrix,
35-
in mat4 i_projectionMatrix,
36-
in vec4 i_viewportOffsetMatrixR0,
37-
in vec4 i_viewportOffsetMatrixR1,
38-
in vec4 i_viewportOffsetMatrixR2,
39-
in vec4 i_viewportOffsetMatrixR3,
40-
in vec2 i_monitorsCount,
35+
in mat4 viewportOffsetArray[NUM_MONITORS],
4136
in vec4 i_monitorIndex,
4237
out vec4 o_position)
4338
{
44-
o_position = mul(i_worldViewMatrix, i_position);
45-
mat4 viewportOffset = mtxFromRows(i_viewportOffsetMatrixR0,
46-
i_viewportOffsetMatrixR1,
47-
i_viewportOffsetMatrixR2,
48-
i_viewportOffsetMatrixR3);
49-
50-
o_position = mul(viewportOffset, o_position);
51-
o_position = mul(i_projectionMatrix, o_position);
52-
53-
vec2 monitorIndexNorm = i_monitorIndex.xy - ((i_monitorsCount - 1.0)/2.0);
54-
o_position.xy =
55-
(o_position.xy + (o_position.w * monitorIndexNorm)*2.0) / i_monitorsCount;
39+
mat4 viewportOffset = viewportOffsetArray[int(i_monitorIndex.z)];
40+
o_position = mul(viewportOffset, i_position);
5641
}
42+
#endif
5743

5844
//-----------------------------------------------------------------------------
5945
// Discard any pixel that is outside the bounds of the current "monitor"
6046
//-----------------------------------------------------------------------------
61-
47+
#ifdef OGRE_FRAGMENT_SHADER
6248
void SGX_InstancedViewportsDiscardOutOfBounds(
6349
in vec2 i_monitorsCount,
6450
in vec4 i_monitorIndex,
@@ -72,8 +58,8 @@ void SGX_InstancedViewportsDiscardOutOfBounds(
7258
float maxM = max(boxedXY.x,boxedXY.y);
7359
if (maxM >= 0.5)
7460
{
75-
#ifdef OGRE_FRAGMENT_SHADER
61+
7662
discard;
77-
#endif
7863
}
7964
}
65+
#endif

Samples/ShaderSystem/include/OgreShaderExInstancedViewports.h

+7-51
Original file line numberDiff line numberDiff line change
@@ -82,66 +82,22 @@ class ShaderExInstancedViewports : public SubRenderState
8282

8383
/** Set the monitors count. */
8484
void setMonitorsCount (const Vector2 monitorsCount);
85-
86-
/** Return the monitors count. */
87-
Vector2 getMonitorsCount () const { return mMonitorsCount; }
85+
86+
void setParameter(const String& name, const Any& value) override;
8887

8988
static String Type;
9089

9190
// Protected methods.
9291
protected:
93-
92+
bool createCpuSubPrograms(ProgramSet* programSet) override;
9493

95-
/**
96-
@see SubRenderState::resolveParameters.
97-
*/
98-
bool resolveParameters (ProgramSet* programSet) override;
94+
UniformParameterPtr mPSInMonitorsCount;
95+
UniformParameterPtr mVSInMatrixArray;
9996

100-
/**
101-
@see SubRenderState::resolveDependencies.
102-
*/
103-
bool resolveDependencies (ProgramSet* programSet) override;
104-
105-
/**
106-
@see SubRenderState::addFunctionInvocations.
107-
*/
108-
bool addFunctionInvocations (ProgramSet* programSet) override;
109-
110-
/**
111-
Internal method that adds related vertex shader functions invocations.
112-
*/
113-
bool addVSInvocations (Function* vsMain, const int groupOrder);
114-
115-
116-
/**
117-
Internal method that adds related pixel shader functions invocations.
118-
*/
119-
bool addPSInvocations (Function* psMain, const int groupOrder);
120-
121-
122-
// Attributes.
123-
protected:
124-
ParameterPtr mVSInPosition; // Vertex shader original input position in projective space.
125-
ParameterPtr mVSOriginalOutPositionProjectiveSpace; // Vertex shader original output position in projective space.
126-
ParameterPtr mVSOutPositionProjectiveSpace; // Vertex shader output texcord position in projective space.
127-
ParameterPtr mPSInPositionProjectiveSpace; // Pixel shader input position in projective space.
128-
UniformParameterPtr mVSInMonitorsCount; // Vertex shader uniform monitors count.
129-
UniformParameterPtr mPSInMonitorsCount; // Pixel shader uniform monitors count.
130-
ParameterPtr mVSInMonitorIndex; // Vertex shader uniform monitor index.
131-
ParameterPtr mVSOutMonitorIndex; // Vertex shader output monitor index.
132-
ParameterPtr mPSInMonitorIndex; // Pixel shader input monitor index.
133-
134-
ParameterPtr mVSInViewportOffsetMatrixR0;
135-
ParameterPtr mVSInViewportOffsetMatrixR1;
136-
ParameterPtr mVSInViewportOffsetMatrixR2;
137-
ParameterPtr mVSInViewportOffsetMatrixR3;
138-
139-
UniformParameterPtr mWorldViewMatrix; // world & view parameter.
140-
UniformParameterPtr mProjectionMatrix; // projection parameter.
141-
142-
Vector2 mMonitorsCount;
97+
Vector2 mViewportGrid;
14398
bool mMonitorsCountChanged;
14499

100+
std::vector<Camera*> mCameras;
145101
};
146102

147103

0 commit comments

Comments
 (0)