SO3Engine
SO3RtssClipPlane.cpp
Go to the documentation of this file.
1
10#include "SO3Material/SO3Pass.h"
13#include "OgreShaderPrecompiledHeaders.h"
14
15#define FFP_LIB_CLIP_PLANE "FFPLib_ClipPlane"
16#define FFP_FUNC_CLIP_PLANE "FFP_Clip_Plane"
17
18namespace SO3
19{
20 const Ogre::String SRS_CLIP_PLANE = "FFP_Clip_Plane";
21
22 //-----------------------------------------------------------------------
23 const Ogre::String& FFPClipPLane::getType() const
24 {
25 return SRS_CLIP_PLANE;
26 }
27
28 //-----------------------------------------------------------------------
29 bool FFPClipPLane::resolveParameters(Ogre::RTShader::ProgramSet* programSet)
30 {
31 Ogre::RTShader::Program* vsProgram = programSet->getCpuProgram(Ogre::GPT_VERTEX_PROGRAM);
32 Ogre::RTShader::Function* vsMain = vsProgram->getEntryPointFunction();
33 Ogre::RTShader::Program* psProgram = programSet->getCpuProgram(Ogre::GPT_FRAGMENT_PROGRAM);
34 Ogre::RTShader::Function* psMain = psProgram->getEntryPointFunction();
35
36 mWorldMatrix = vsProgram->resolveParameter(Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
37
38 // Resolve vertex shader output pos
39 mVSInPosition = vsMain->resolveInputParameter(Ogre::RTShader::Parameter::SPC_POSITION_OBJECT_SPACE);
40 mVSOutPosition = vsMain->resolveOutputParameter(Ogre::RTShader::Parameter::SPC_POSITION_WORLD_SPACE);
41
42 // Resolve pixel shader input
43 mPSInPosition = psMain->resolveInputParameter(mVSOutPosition);
44 mPSClipPlaneRef = psProgram->resolveParameter(Ogre::GCT_FLOAT4, "slicePlane");
45
46 return true;
47 }
48
49 //-----------------------------------------------------------------------
50 bool FFPClipPLane::resolveDependencies(Ogre::RTShader::ProgramSet* programSet)
51 {
52 Ogre::RTShader::Program* vsProgram = programSet->getCpuProgram(Ogre::GPT_VERTEX_PROGRAM);
53 Ogre::RTShader::Program* psProgram = programSet->getCpuProgram(Ogre::GPT_FRAGMENT_PROGRAM);
54 vsProgram->addDependency(FFP_LIB_TRANSFORM);
55 psProgram->addDependency(FFP_LIB_CLIP_PLANE);
56 return true;
57 }
58
59 //-----------------------------------------------------------------------
60 void FFPClipPLane::copyFrom(const SubRenderState& rhs)
61 {
62 }
63
64 bool FFPClipPLane::addFunctionInvocations(Ogre::RTShader::ProgramSet* programSet)
65 {
66 Ogre::RTShader::Program* vsProgram = programSet->getCpuProgram(Ogre::GPT_VERTEX_PROGRAM);
67 Ogre::RTShader::Function* vsMain = vsProgram->getEntryPointFunction();
68 Ogre::RTShader::Program* psProgram = programSet->getCpuProgram(Ogre::GPT_FRAGMENT_PROGRAM);
69 Ogre::RTShader::Function* psMain = psProgram->getEntryPointFunction();
70
71 vsMain->getStage(Ogre::RTShader::FFP_VS_TRANSFORM).callFunction(FFP_FUNC_TRANSFORM, mWorldMatrix, mVSInPosition, mVSOutPosition);
72 psMain->getStage(Ogre::RTShader::FFP_PS_COLOUR_BEGIN).callFunction(FFP_FUNC_CLIP_PLANE, { Ogre::RTShader::In(mPSClipPlaneRef), Ogre::RTShader::In(mPSInPosition) });
73
74 return true;
75 }
76
78 {
79 return Ogre::RTShader::FFP_ALPHA_TEST;
80 }
81
82 bool FFPClipPLane::preAddToRenderState(const Ogre::RTShader::RenderState* renderState, Ogre::Pass* srcPass, Ogre::Pass* dstPass)
83 {
84 bool ret = false;
85 Ogre::Any bindedSPass = srcPass->getUserObjectBindings().getUserAny("SPass");
86 if (bindedSPass.has_value())
87 {
88 SPass* pass = Ogre::any_cast<SPass*> (bindedSPass);
90 }
92 }
93
94 void FFPClipPLane::updateGpuProgramsParams(Ogre::Renderable* rend, const Ogre::Pass* pass, const Ogre::AutoParamDataSource* source, const Ogre::LightList* pLightList)
95 {
96 mPSClipPlaneRef->setGpuParameter(SRoot::getSingletonPtr()->GetSlicePlane());
97 }
98
99 //----------------------Factory Implementation---------------------------
100 //-----------------------------------------------------------------------
101 const Ogre::String& FFPClipPLaneFactory::getType() const
102 {
103 return SRS_CLIP_PLANE;
104 }
105
106 //-----------------------------------------------------------------------
107 Ogre::RTShader::SubRenderState* FFPClipPLaneFactory::createInstanceImpl()
108 {
109 return OGRE_NEW FFPClipPLane;
110 }
111
112}
const Ogre::String & getType() const override
Ogre::RTShader::SubRenderState * createInstanceImpl() override
void updateGpuProgramsParams(Ogre::Renderable *rend, const Ogre::Pass *pass, const Ogre::AutoParamDataSource *source, const Ogre::LightList *pLightList) override
bool resolveParameters(Ogre::RTShader::ProgramSet *programSet) override
int getExecutionOrder() const override
bool preAddToRenderState(const Ogre::RTShader::RenderState *renderState, Ogre::Pass *srcPass, Ogre::Pass *dstPass) override
bool resolveDependencies(Ogre::RTShader::ProgramSet *programSet) override
const Ogre::String & getType() const override
bool addFunctionInvocations(Ogre::RTShader::ProgramSet *programSet) override
void copyFrom(const Ogre::RTShader::SubRenderState &rhs) override
bool GetIgnoreSlicePlane()
STechnique * GetTechnique()
Definition SO3Pass.cpp:277
bool GetSlicePlaneState()
Definition SO3Root.cpp:2797
static SRoot * getSingletonPtr()
Definition SO3Root.cpp:111
SMaterial * GetParentMaterial()
const Ogre::String SRS_CLIP_PLANE