Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_D3D11_DEFAULT_SHADER_H__
00009 #define __SP_D3D11_DEFAULT_SHADER_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #if defined(SP_COMPILE_WITH_DIRECT3D11)
00015
00016
00017 #include "Base/spDimensionVector3D.hpp"
00018 #include "Base/spDimensionMatrix4.hpp"
00019 #include "Base/spGeometryStructures.hpp"
00020 #include "Base/spMaterialConfigTypes.hpp"
00021 #include "RenderSystem/spRenderSystem.hpp"
00022
00023
00024 namespace sp
00025 {
00026 namespace scene
00027 {
00028 class Light;
00029 class Mesh;
00030 }
00031 namespace video
00032 {
00033
00034
00035 class Shader;
00036 class ShaderClass;
00037
00039 class D3D11DefaultShader
00040 {
00041
00042 private:
00043
00044 friend class Direct3D11RenderSystem;
00045
00046
00047
00048 struct SConstantBufferLights
00049 {
00050 struct SLight
00051 {
00052 SLight();
00053 ~SLight();
00054
00055
00056 s32 Model;
00057 s32 Enabled;
00058 f32 Unused1[2];
00059 dim::vector4df Position;
00060 dim::vector4df Diffuse, Ambient, Specular;
00061 dim::vector4df SpotDir;
00062 f32 Attn0, Attn1, Attn2;
00063 f32 Unused2;
00064 f32 Theta, Phi, Falloff, Range;
00065 };
00066
00067
00068 SLight Lights[8];
00069 };
00070
00071 struct SConstantBufferObject
00072 {
00073 struct SMaterial
00074 {
00075 SMaterial();
00076 ~SMaterial();
00077
00078
00079 dim::vector4df Diffuse, Ambient, Specular, Emission;
00080 s32 Shading;
00081 s32 LightingEnabled;
00082 s32 FogEnabled;
00083 f32 Shininess;
00084 s32 AlphaMethod;
00085 f32 AlphaReference;
00086 s32 Unused[2];
00087 };
00088
00089
00090 dim::matrix4f WorldMatrix, ViewMatrix, ProjectionMatrix;
00091 SMaterial Material;
00092 };
00093
00094 struct SConstantBufferSurface
00095 {
00096 SConstantBufferSurface();
00097 ~SConstantBufferSurface();
00098
00099 struct STextureLayer
00100 {
00101 STextureLayer();
00102 ~STextureLayer();
00103
00104
00105 dim::vector3di MapGenType;
00106 s32 TexEnvType;
00107 dim::matrix4f Matrix;
00108 };
00109
00110
00111 s32 NumTextureLayers;
00112 s32 Unused[3];
00113 STextureLayer TextureLayers[4];
00114 };
00115
00116 struct SConstantBufferExtension
00117 {
00118 struct SClipPlane
00119 {
00120 SClipPlane();
00121 ~SClipPlane();
00122
00123
00124 s32 Enabled;
00125 s32 Unused[3];
00126 dim::plane3df Plane;
00127 };
00128
00129 struct SFogStates
00130 {
00131 SFogStates();
00132 ~SFogStates();
00133
00134 enum EConstBufferFogModes
00135 {
00136 FOGMODE_STATIC_PALE = 0,
00137 FOGMODE_STATIC_THICK,
00138 FOGMODE_VOLUMETRIC,
00139 };
00140
00141
00142 s32 Mode;
00143 f32 Density;
00144 f32 Near, Far;
00145 dim::vector4df Color;
00146 };
00147
00148 SClipPlane Planes[8];
00149 SFogStates Fog;
00150 };
00151
00152
00153
00154 D3D11DefaultShader();
00155 ~D3D11DefaultShader();
00156
00157 bool createShader();
00158
00159 void bind();
00160 void unbind();
00161
00162 void setupLight(
00163 u32 LightID, const scene::ELightModels LightType, bool isVolumetric,
00164 const dim::vector3df &Direction, f32 SpotInnerConeAngle, f32 SpotOuterConeAngle,
00165 f32 AttenuationConstant, f32 AttenuationLinear, f32 AttenuationQuadratic
00166 );
00167 void setupLightStatus(u32 LightID, bool Enable);
00168 void setupLightColor(
00169 u32 LightID, const video::color &Diffuse, const video::color &Ambient, const video::color &Specular
00170 );
00171
00172 void setupFog(const EFogTypes Type, const EFogModes Mode, f32 Range, f32 Near, f32 Far);
00173 void setupFogColor(const video::color &Color);
00174
00175 void setupClipPlane(u32 Index, const dim::plane3df &Plane, bool Enable);
00176
00177 void updateObject(scene::Mesh* MeshObj);
00178 void updateTextureLayers(const TextureLayerListType &TextureLayers);
00179 void updateExtensions();
00180
00181
00182
00183 ShaderClass* ShaderClass_;
00184
00185 Shader* VertexShader_;
00186 Shader* PixelShader_;
00187
00188 bool Valid_;
00189
00190 SConstantBufferLights ConstBufferLights_;
00191 SConstantBufferObject ConstBufferObject_;
00192 SConstantBufferSurface ConstBufferSurface_;
00193 SConstantBufferExtension ConstBufferExtension_;
00194
00195 };
00196
00197
00198 }
00199
00200 }
00201
00202
00203 #endif
00204
00205 #endif
00206
00207
00208
00209