| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- //
- // Urho3D Engine
- // Copyright (c) 2008-2011 Lasse Öörni
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #pragma once
- #include "GraphicsDefs.h"
- #include "HashMap.h"
- #include "Resource.h"
- #include "Vector4.h"
- class Pass;
- class Technique;
- class Texture;
- class Texture2D;
- class TextureCube;
- /// Material's shader parameter definition.
- struct MaterialShaderParameter
- {
- /// Name.
- String name_;
- /// Value.
- Vector4 value_;
- };
- /// Material's technique list entry.
- struct TechniqueEntry
- {
- /// Construct with defaults.
- TechniqueEntry();
- /// Construct with parameters.
- TechniqueEntry(Technique* technique, unsigned qualityLevel, float lodDistance);
- /// Destruct.
- ~TechniqueEntry();
-
- /// Technique.
- SharedPtr<Technique> technique_;
- /// Quality level.
- int qualityLevel_;
- /// LOD distance.
- float lodDistance_;
- };
- /// Describes how to render 3D geometries.
- class Material : public Resource
- {
- OBJECT(Material);
-
- public:
- /// Construct.
- Material(Context* context);
- /// Destruct.
- ~Material();
- /// Register object factory.
- static void RegisterObject(Context* context);
-
- /// Load resource. Return true if successful.
- virtual bool Load(Deserializer& source);
- /// Save resource. Return true if successful.
- virtual bool Save(Serializer& dest);
-
- /// %Set number of techniques.
- void SetNumTechniques(unsigned num);
- /// %Set technique.
- void SetTechnique(unsigned index, Technique* technique, unsigned qualityLevel = 0, float lodDistance = 0.0f);
- /// %Set shader parameter.
- void SetShaderParameter(const String& name, const Vector4& value);
- /// %Set texture.
- void SetTexture(TextureUnit unit, Texture* texture);
- /// %Set texture coordinate transform.
- void SetUVTransform(const Vector2& offset, float rotation, const Vector2& repeat);
- /// %Set texture coordinate transform.
- void SetUVTransform(const Vector2& offset, float rotation, float repeat);
- /// %Set culling mode.
- void SetCullMode(CullMode mode);
- /// %Set culling mode for shadows.
- void SetShadowCullMode(CullMode mode);
- /// Remove a shader parameter.
- void RemoveShaderParameter(const String& name);
- /// Reset all shader pointers.
- void ReleaseShaders();
- /// Clone material.
- SharedPtr<Material> Clone(const String& cloneName = String()) const;
- /// Mark material for auxiliary view rendering.
- void MarkForAuxView(unsigned frameNumber);
-
- /// Return number of techniques.
- unsigned GetNumTechniques() const { return techniques_.Size(); }
- /// Return all techniques.
- const Vector<TechniqueEntry>& GetTechniques() const { return techniques_; }
- /// Return technique entry by index.
- const TechniqueEntry& GetTechniqueEntry(unsigned index) const;
- /// Return technique by index.
- Technique* GetTechnique(unsigned index) const;
- /// Return pass by technique index and pass type.
- Pass* GetPass(unsigned index, PassType pass) const;
- /// Return all textures.
- const Vector<SharedPtr<Texture> >& GetTextures() const { return textures_; }
- /// Return texture by unit.
- Texture* GetTexture(TextureUnit unit) const;
- /// Return all shader parameters.
- const HashMap<StringHash, MaterialShaderParameter>& GetShaderParameters() const { return shaderParameters_; }
- /// Return normal culling mode.
- CullMode GetCullMode() const { return cullMode_; }
- /// Return culling mode for shadows.
- CullMode GetShadowCullMode() const { return shadowCullMode_; }
- /// Return last auxiliary view rendered frame number.
- unsigned GetAuxViewFrameNumber() const { return auxViewFrameNumber_; }
- /// Return whether should render occlusion.
- bool GetOcclusion() const { return occlusion_; }
- /// Return whether should render specular.
- bool GetSpecular() const { return specular_; }
-
- /// Return name for texture unit.
- static const String& GetTextureUnitName(TextureUnit unit);
-
- private:
- /// Re-evaluate occlusion rendering.
- void CheckOcclusion();
- /// Re-evaluate specular lighting.
- void CheckSpecular();
-
- /// Techniques.
- Vector<TechniqueEntry> techniques_;
- /// Textures.
- Vector<SharedPtr<Texture> > textures_;
- /// Shader parameters.
- HashMap<StringHash, MaterialShaderParameter> shaderParameters_;
- /// Last auxiliary view rendered frame number.
- unsigned auxViewFrameNumber_;
- /// Normal culling mode.
- CullMode cullMode_;
- /// Culling mode for shadow rendering.
- CullMode shadowCullMode_;
- /// Render occlusion flag.
- bool occlusion_;
- /// Specular lighting flag.
- bool specular_;
- };
|