Skip to content

Commit bde8551

Browse files
authored
Merge branch 'OGRECave:master' into master
2 parents 22b1dad + 63ba6a3 commit bde8551

File tree

6 files changed

+167
-283
lines changed

6 files changed

+167
-283
lines changed

OgreMain/include/OgreAutoParamDataSource.h

+2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ namespace Ogre {
163163
size_t getBoneMatrixCount(void) const;
164164
OGRE_DEPRECATED size_t getWorldMatrixCount(void) const { return getBoneMatrixCount(); }
165165
const Affine3& getViewMatrix(void) const;
166+
Affine3 getViewMatrix(const Camera* cam) const;
166167
const Matrix4& getViewProjectionMatrix(void) const;
167168
const Matrix4& getProjectionMatrix(void) const;
169+
Matrix4 getProjectionMatrix(const Camera* cam) const;
168170
const Matrix4& getWorldViewProjMatrix(void) const;
169171
const Affine3& getWorldViewMatrix(void) const;
170172
const Affine3& getInverseWorldMatrix(void) const;

OgreMain/src/OgreAutoParamDataSource.cpp

+46-32
Original file line numberDiff line numberDiff line change
@@ -306,21 +306,26 @@ namespace Ogre {
306306
return mWorldMatrixArray + int(MeshManager::getBonesUseObjectSpace());
307307
}
308308
//-----------------------------------------------------------------------------
309-
const Affine3& AutoParamDataSource::getViewMatrix(void) const
309+
Affine3 AutoParamDataSource::getViewMatrix(const Camera* cam) const
310310
{
311-
if (mViewMatrixDirty)
311+
Affine3 view;
312+
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityView())
313+
view = Affine3::IDENTITY;
314+
else
312315
{
313-
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityView())
314-
mViewMatrix = Affine3::IDENTITY;
315-
else
316+
view = cam->getViewMatrix(true);
317+
if (mCameraRelativeRendering)
316318
{
317-
mViewMatrix = mCurrentCamera->getViewMatrix(true);
318-
if (mCameraRelativeRendering)
319-
{
320-
mViewMatrix.setTrans(Vector3::ZERO);
321-
}
322-
319+
view.setTrans(Vector3::ZERO);
323320
}
321+
}
322+
return view;
323+
}
324+
const Affine3& AutoParamDataSource::getViewMatrix(void) const
325+
{
326+
if (mViewMatrixDirty)
327+
{
328+
mViewMatrix = getViewMatrix(mCurrentCamera);
324329
mViewMatrixDirty = false;
325330
}
326331
return mViewMatrix;
@@ -336,31 +341,40 @@ namespace Ogre {
336341
return mViewProjMatrix;
337342
}
338343
//-----------------------------------------------------------------------------
344+
Matrix4 AutoParamDataSource::getProjectionMatrix(const Camera* cam) const
345+
{
346+
Matrix4 proj;
347+
348+
// NB use API-independent projection matrix since GPU programs
349+
// bypass the API-specific handedness and use right-handed coords
350+
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityProjection())
351+
{
352+
// Use identity projection matrix, still need to take RS depth into account.
353+
RenderSystem* rs = Root::getSingleton().getRenderSystem();
354+
rs->_convertProjectionMatrix(Matrix4::IDENTITY, proj, true);
355+
}
356+
else
357+
{
358+
proj = mCurrentCamera->getProjectionMatrixWithRSDepth();
359+
}
360+
361+
if (mCurrentRenderTarget && mCurrentRenderTarget->requiresTextureFlipping())
362+
{
363+
// Because we're not using setProjectionMatrix, this needs to be done here
364+
// Invert transformed y
365+
proj[1][0] = -proj[1][0];
366+
proj[1][1] = -proj[1][1];
367+
proj[1][2] = -proj[1][2];
368+
proj[1][3] = -proj[1][3];
369+
}
370+
371+
return proj;
372+
}
339373
const Matrix4& AutoParamDataSource::getProjectionMatrix(void) const
340374
{
341375
if (mProjMatrixDirty)
342376
{
343-
// NB use API-independent projection matrix since GPU programs
344-
// bypass the API-specific handedness and use right-handed coords
345-
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityProjection())
346-
{
347-
// Use identity projection matrix, still need to take RS depth into account.
348-
RenderSystem* rs = Root::getSingleton().getRenderSystem();
349-
rs->_convertProjectionMatrix(Matrix4::IDENTITY, mProjectionMatrix, true);
350-
}
351-
else
352-
{
353-
mProjectionMatrix = mCurrentCamera->getProjectionMatrixWithRSDepth();
354-
}
355-
if (mCurrentRenderTarget && mCurrentRenderTarget->requiresTextureFlipping())
356-
{
357-
// Because we're not using setProjectionMatrix, this needs to be done here
358-
// Invert transformed y
359-
mProjectionMatrix[1][0] = -mProjectionMatrix[1][0];
360-
mProjectionMatrix[1][1] = -mProjectionMatrix[1][1];
361-
mProjectionMatrix[1][2] = -mProjectionMatrix[1][2];
362-
mProjectionMatrix[1][3] = -mProjectionMatrix[1][3];
363-
}
377+
mProjectionMatrix = getProjectionMatrix(mCurrentCamera);
364378
mProjMatrixDirty = false;
365379
}
366380
return mProjectionMatrix;

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)