Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
OgreTerrainPSSMMaterialGenerator.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2012 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28
29#pragma once
30
31#include <Terrain/OgreTerrainPrerequisites.h>
32#include <Terrain/OgreTerrainMaterialGenerator.h>
33#include <OgreGpuProgramParams.h>
34
35namespace Ogre {
36class PSSMShadowCameraSetup;
37
38
39
44class TerrainPSSMMaterialGenerator : public TerrainMaterialGenerator
45{
46public:
49
52 class SM2Profile : public TerrainMaterialGenerator::Profile
53 {
54 public:
55 SM2Profile(TerrainMaterialGenerator* parent, const String& name, const String& desc);
57 MaterialPtr generate(const Terrain* terrain);
58 MaterialPtr generateForCompositeMap(const Terrain* terrain);
59 uint8 getMaxLayers(const Terrain* terrain) const;
60 void updateParams(const MaterialPtr& mat, const Terrain* terrain);
61 void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain);
62 void requestOptions(Terrain* terrain);
64
70 void setLayerNormalMappingEnabled(bool enabled);
71
77 void setLayerParallaxMappingEnabled(bool enabled);
78
84 void setLayerSpecularMappingEnabled(bool enabled);
85
93 void setGlobalColourMapEnabled(bool enabled);
94
98 bool isLightmapEnabled() const { return mLightmapEnabled; }
102 void setLightmapEnabled(bool enabled);
103
111 void setCompositeMapEnabled(bool enabled);
112
120 void setReceiveDynamicShadowsEnabled(bool enabled);
121
125 void setReceiveDynamicShadowsPSSM(PSSMShadowCameraSetup* pssmSettings);
126
130 PSSMShadowCameraSetup* getReceiveDynamicShadowsPSSM() const { return mPSSM; }
133 void setReceiveDynamicShadowsDepth(bool enabled);
134
140 void setReceiveDynamicShadowsLowLod(bool enabled);
141
145
147 bool _isSM3Available() const { return mSM3Available; }
148 bool _isSM4Available() const { return mSM4Available; }
149
150 protected:
151
158
159 void addTechnique(const MaterialPtr& mat, const Terrain* terrain, TechniqueType tt);
160
162 class ShaderHelper : public TerrainAlloc
163 {
164 public:
166 {
167 }
168
170 {
171 }
172
173 virtual HighLevelGpuProgramPtr generateVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
174 virtual HighLevelGpuProgramPtr generateFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
175 virtual void updateParams(const SM2Profile* prof, const MaterialPtr& mat, const Terrain* terrain, bool compositeMap);
176 protected:
177 virtual String getVertexProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
178 virtual String getFragmentProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
179 virtual HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
180 virtual HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
181 virtual void generateVertexProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
182 virtual void generateFragmentProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
183 virtual void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) = 0;
184 virtual void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) = 0;
185 virtual void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, Ogre::StringStream& outStream) = 0;
186 virtual void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, Ogre::StringStream& outStream) = 0;
187 virtual void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) = 0;
188 virtual void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) = 0;
189 virtual void defaultVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
190 virtual void defaultFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
191 virtual void updateVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
192 virtual void updateFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
193 static String getChannel(uint idx);
194
197 };
198
201 {
202 protected:
203 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
204 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
205 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
206 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
207 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, Ogre::StringStream& outStream);
208 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, Ogre::StringStream& outStream);
209 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
210 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
211 uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
212 void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
213 void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
214 void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
215 void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream);
216 };
217
219 {
220 protected:
221 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
222 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
223 };
224
227 {
228 protected:
229 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
230 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
231
232 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) {}
233
234 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) {}
235
236 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, Ogre::StringStream& outStream) {}
237
238 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, Ogre::StringStream& outStream) {}
239
240 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) {}
241
242 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) {}
243 };
244
247 {
248 protected:
249 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
250 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
251
252 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) {}
253
254 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) {}
255
256 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, Ogre::StringStream& outStream) {}
257
258 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, Ogre::StringStream& outStream) {}
259
260 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) {}
261
262 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, Ogre::StringStream& outStream) {}
263 };
264
273 PSSMShadowCameraSetup* mPSSM;
278
279 bool isShadowingEnabled(TechniqueType tt, const Terrain* terrain) const;
280 };
281};
282
283}
284
Utility class to help with generating shaders for Cg / HLSL.
uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateFpLayer(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, uint layer, Ogre::StringStream &outStream)
HighLevelGpuProgramPtr createVertexProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
void generateVpDynamicShadows(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateFpHeader(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateFpDynamicShadowsHelpers(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateFpDynamicShadowsParams(uint *texCoord, uint *sampler, const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateVpFooter(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateVpHeader(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateFpFooter(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
void generateFpDynamicShadows(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateVpLayer(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, uint layer, Ogre::StringStream &outStream)
void generateFpHeader(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateVpFooter(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateVpHeader(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateFpLayer(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, uint layer, Ogre::StringStream &outStream)
void generateFpFooter(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateVpLayer(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, uint layer, Ogre::StringStream &outStream)
HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
HighLevelGpuProgramPtr createVertexProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
void generateVpFooter(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
HighLevelGpuProgramPtr createVertexProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
void generateFpFooter(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateVpLayer(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, uint layer, Ogre::StringStream &outStream)
void generateFpLayer(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, uint layer, Ogre::StringStream &outStream)
void generateVpHeader(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
void generateFpHeader(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
HighLevelGpuProgramPtr createVertexProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
Interface definition for helper class to generate shaders.
virtual void generateVpFooter(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)=0
virtual void updateVpParams(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, const GpuProgramParametersSharedPtr &params)
virtual HighLevelGpuProgramPtr generateFragmentProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
virtual void generateFpHeader(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)=0
virtual void generateFragmentProgramSource(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
virtual void defaultVpParams(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, const HighLevelGpuProgramPtr &prog)
virtual void generateVertexProgramSource(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)
virtual void generateFpFooter(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)=0
virtual HighLevelGpuProgramPtr generateVertexProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
virtual void updateParams(const SM2Profile *prof, const MaterialPtr &mat, const Terrain *terrain, bool compositeMap)
virtual String getFragmentProgramName(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
virtual void generateVpLayer(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, uint layer, Ogre::StringStream &outStream)=0
virtual void updateFpParams(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, const GpuProgramParametersSharedPtr &params)
virtual HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)=0
virtual void defaultFpParams(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, const HighLevelGpuProgramPtr &prog)
virtual String getVertexProgramName(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)
virtual HighLevelGpuProgramPtr createVertexProgram(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt)=0
virtual void generateFpLayer(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, uint layer, Ogre::StringStream &outStream)=0
virtual void generateVpHeader(const SM2Profile *prof, const Terrain *terrain, TechniqueType tt, Ogre::StringStream &outStream)=0
bool getReceiveDynamicShadowsLowLod() const
Whether to use shadows on low LOD material rendering (when using composite map) (default false).
void setCompositeMapEnabled(bool enabled)
Whether to use the composite map to provide a lower LOD technique in the distance (default true).
bool isLayerParallaxMappingEnabled() const
Whether to support parallax mapping per layer in the shader (default true).
bool isGlobalColourMapEnabled() const
Whether to support a global colour map over the terrain in the shader, if it's present (default true)...
void setReceiveDynamicShadowsLowLod(bool enabled)
Whether to use shadows on low LOD material rendering (when using composite map) (default false).
bool getReceiveDynamicShadowsDepth() const
Whether to use depth shadows (default false).
void updateParams(const MaterialPtr &mat, const Terrain *terrain)
bool isCompositeMapEnabled() const
Whether to use the composite map to provide a lower LOD technique in the distance (default true).
void setReceiveDynamicShadowsEnabled(bool enabled)
Whether to support dynamic texture shadows received from other objects, on the terrain (default true)...
void setReceiveDynamicShadowsDepth(bool enabled)
Whether to use depth shadows (default false).
void setLayerNormalMappingEnabled(bool enabled)
Whether to support normal mapping per layer in the shader (default true).
PSSMShadowCameraSetup * getReceiveDynamicShadowsPSSM() const
Whether to use PSSM support dynamic texture shadows, and if so the settings to use (default 0).
void setLightmapEnabled(bool enabled)
Whether to support a light map over the terrain in the shader, if it's present (default true).
bool isLayerNormalMappingEnabled() const
Whether to support normal mapping per layer in the shader (default true).
void setLayerSpecularMappingEnabled(bool enabled)
Whether to support specular mapping per layer in the shader (default true).
void updateParamsForCompositeMap(const MaterialPtr &mat, const Terrain *terrain)
void setReceiveDynamicShadowsPSSM(PSSMShadowCameraSetup *pssmSettings)
Whether to use PSSM support dynamic texture shadows, and if so the settings to use (default 0).
bool isShadowingEnabled(TechniqueType tt, const Terrain *terrain) const
void setGlobalColourMapEnabled(bool enabled)
Whether to support a global colour map over the terrain in the shader, if it's present (default true)...
bool isLightmapEnabled() const
Whether to support a light map over the terrain in the shader, if it's present (default true).
void addTechnique(const MaterialPtr &mat, const Terrain *terrain, TechniqueType tt)
void setLayerParallaxMappingEnabled(bool enabled)
Whether to support parallax mapping per layer in the shader (default true).
bool isLayerSpecularMappingEnabled() const
Whether to support specular mapping per layer in the shader (default true).
bool getReceiveDynamicShadowsEnabled() const
Whether to support dynamic texture shadows received from other objects, on the terrain (default true)...
A TerrainMaterialGenerator which can cope with normal mapped, specular mapped terrain.