OGRE-Next
4.0.0unstable
Object-Oriented Graphics Rendering Engine
|
Contains information needed by PBS (Physically Based Shading) for OpenGL 3+ & D3D11+. More...
#include <OgreHlmsPbsDatablock.h>
Public Types | |
enum | TransparencyModes { None , Transparent , Fade , Refractive } |
enum | Workflows { SpecularWorkflow , SpecularAsFresnelWorkflow , MetallicWorkflow } |
Public Member Functions | |
HlmsPbsDatablock (IdString name, HlmsPbs *creator, const HlmsMacroblock *macroblock, const HlmsBlendblock *blendblock, const HlmsParamVec ¶ms) | |
Valid parameters in params: More... | |
~HlmsPbsDatablock () override | |
bool | _hasEmissive () const |
Returns true if getEmissive is non-zero or if there is an emissive texture set. More... | |
void | calculateHash () override |
ColourValue | getBackgroundDiffuse () const |
uint32 | getBrdf () const |
float | getClearCoat () const |
float | getClearCoatRoughness () const |
CubemapProbe * | getCubemapProbe () const |
PbsBlendModes | getDetailMapBlendMode (uint8 detailMapIdx) const |
Vector4 | getDetailMapOffsetScale (uint8 detailMap) const |
Real | getDetailMapWeight (uint8 detailMap) const |
Real | getDetailNormalWeight (uint8 detailNormalMapIdx) const |
Returns the detail normal maps' weight. More... | |
Vector3 | getDiffuse () const |
ColourValue | getDiffuseColour () const override |
TextureGpu * | getDiffuseTexture () const override |
Vector3 | getEmissive () const |
ColourValue | getEmissiveColour () const override |
TextureGpu * | getEmissiveTexture () const override |
Vector3 | getFresnel () const |
Returns the current fresnel. More... | |
float | getMetalness () const |
Real | getNormalMapWeight () const |
Returns the detail normal maps' weight. More... | |
bool | getReceiveShadows () const |
float | getRefractionStrength () const |
float | getRoughness () const |
Vector3 | getSpecular () const |
uint8 | getTextureUvSource (PbsTextureTypes sourceType) const |
float | getTransparency () const |
TransparencyModes | getTransparencyMode () const |
bool | getTwoSidedLighting () const |
bool | getUseAlphaFromTextures () const |
bool | getUseDiffuseMapAsGrayscale () const |
bool | getUseEmissiveAsLightmap () const |
Vector4 | getUserValue (uint8 userValueIdx) const |
Workflows | getWorkflow () const |
bool | hasEmissiveConstant () const |
Returns true iif getEmissive is non-zero. More... | |
bool | hasSeparateFresnel () const |
Whether the same fresnel term is used for RGB, or individual ones for each channel. More... | |
void | importUnity (const Vector3 &colour, Real metallic, Real roughness, bool changeBrdf) |
Helper function to import values from Unity (metallic workflow). More... | |
void | importUnity (const Vector3 &diffuse, const Vector3 &specular, Real roughness, bool changeBrdf) |
Helper function to import & convert values from Unity (specular workflow). More... | |
void | notifyTextureChanged (TextureGpu *texture, TextureGpuListener::Reason reason, void *extraData) override |
void | setAlphaTest (CompareFunction compareFunction, bool shadowCasterOnly=false, bool useAlphaFromTextures=true) override |
void | setAlphaTestThreshold (float threshold) override |
void | setBackgroundDiffuse (const ColourValue &bgDiffuse) |
Sets the diffuse background colour. More... | |
void | setBrdf (PbsBrdf::PbsBrdf brdf) |
Changes the BRDF in use. More... | |
void | setClearCoat (float clearCoat) |
Sets the strength of the of the clear coat layer and its roughness. More... | |
void | setClearCoatRoughness (float roughness) |
void | setCubemapProbe (CubemapProbe *probe) |
Manually set a probe to affect this particular material. More... | |
void | setDetailMapBlendMode (uint8 detailMapIdx, PbsBlendModes blendMode) |
Changes the blend mode of the detail map. More... | |
void | setDetailMapOffsetScale (uint8 detailMap, const Vector4 &offsetScale) |
Sets the scale and offset of the detail map. More... | |
void | setDetailMapWeight (uint8 detailMap, Real weight) |
Sets the weight of detail map. More... | |
void | setDetailNormalWeight (uint8 detailNormalMapIdx, Real weight) |
Sets the normal mapping weight. More... | |
void | setDiffuse (const Vector3 &diffuseColour) |
Sets the diffuse colour (final multiplier). More... | |
void | setEmissive (const Vector3 &emissiveColour) |
Sets emissive colour (e.g. More... | |
void | setFresnel (const Vector3 &fresnel, bool separateFresnel) |
Sets the fresnel (F0) directly, instead of using the IOR. More... | |
void | setIndexOfRefraction (const Vector3 &refractionIdx, bool separateFresnel) |
Calculates fresnel (F0 in most books) based on the IOR. More... | |
void | setMetalness (float metalness) |
Sets the metalness in a metallic workflow. More... | |
void | setNormalMapWeight (Real weight) |
See setDetailNormalWeight(). This is the same, but for the main normal map. More... | |
void | setReceiveShadows (bool receiveShadows) |
When false, objects with this material will not receive shadows (independent of whether they case shadows or not) More... | |
void | setRefractionStrength (float strength) |
Sets the strength of the refraction, i.e. More... | |
void | setRoughness (float roughness) |
Sets the roughness. More... | |
void | setSpecular (const Vector3 &specularColour) |
Sets the specular colour. More... | |
void | setTexture (PbsTextureTypes texUnit, const String &name, const HlmsSamplerblock *refParams=0) |
void | setTextureUvSource (PbsTextureTypes sourceType, uint8 uvSet) |
Sets which UV set to use for the given texture. More... | |
void | setTransparency (float transparency, TransparencyModes mode=Transparent, bool useAlphaFromTextures=true, bool changeBlendblock=true) |
Makes the material transparent, and sets the amount of transparency. More... | |
void | setTwoSidedLighting (bool twoSided, bool changeMacroblock=true, CullingMode oneSidedShadowCast=CULL_NONE) |
Allows support for two sided lighting. More... | |
void | setUseDiffuseMapAsGrayscale (bool bUseDiffuseMapAsGrayscale) |
When set, it treats the diffuse map as a grayscale map; which means it will spread red component to all rgb channels. More... | |
void | setUseEmissiveAsLightmap (bool bUseEmissiveAsLightmap) |
When set, it treats the emissive map as a lightmap; which means it will be multiplied against the diffuse component. More... | |
void | setUserValue (uint8 userValueIdx, const Vector4 &value) |
Sets the value of the userValue, this can be used in a custom piece. More... | |
void | setWorkflow (Workflows workflow) |
Sets whether to use a specular workflow, or a metallic workflow. More... | |
uint32 | suggestFiltersForType (PbsTextureTypes type) const |
bool | suggestUsingSRGB (PbsTextureTypes type) const |
Suggests the TextureMapType (aka texture category) for each type of texture (i.e. More... | |
Static Public Attributes | |
static const uint32 | MaterialSizeInGpu |
static const uint32 | MaterialSizeInGpuAligned |
Contains information needed by PBS (Physically Based Shading) for OpenGL 3+ & D3D11+.
Enumerator | |
---|---|
SpecularWorkflow | Specular workflow. Many popular PBRs use SpecularAsFresnelWorkflow though.
|
SpecularAsFresnelWorkflow | Specular workflow where the specular texture is addressed to the fresnel instead of kS. This is normally referred as simply Specular workflow in many other PBRs.
|
MetallicWorkflow |
Ogre::HlmsPbsDatablock::HlmsPbsDatablock | ( | IdString | name, |
HlmsPbs * | creator, | ||
const HlmsMacroblock * | macroblock, | ||
const HlmsBlendblock * | blendblock, | ||
const HlmsParamVec & | params | ||
) |
Valid parameters in params:
params |
|
|
override |
bool Ogre::HlmsPbsDatablock::_hasEmissive | ( | ) | const |
Returns true if getEmissive is non-zero or if there is an emissive texture set.
|
override |
ColourValue Ogre::HlmsPbsDatablock::getBackgroundDiffuse | ( | ) | const |
uint32 Ogre::HlmsPbsDatablock::getBrdf | ( | ) | const |
|
inline |
|
inline |
CubemapProbe* Ogre::HlmsPbsDatablock::getCubemapProbe | ( | ) | const |
PbsBlendModes Ogre::HlmsPbsDatablock::getDetailMapBlendMode | ( | uint8 | detailMapIdx | ) | const |
Returns the detail normal maps' weight.
Vector3 Ogre::HlmsPbsDatablock::getDiffuse | ( | ) | const |
|
override |
|
override |
Vector3 Ogre::HlmsPbsDatablock::getEmissive | ( | ) | const |
|
override |
|
override |
Vector3 Ogre::HlmsPbsDatablock::getFresnel | ( | ) | const |
Returns the current fresnel.
Note: when hasSeparateFresnel returns false, the Y and Z components still correspond to mFresnelG & mFresnelB just in case you want to preserve this data (i.e. toggling separate fresnel often (which is not a good idea though, in terms of performance)
float Ogre::HlmsPbsDatablock::getMetalness | ( | ) | const |
Real Ogre::HlmsPbsDatablock::getNormalMapWeight | ( | ) | const |
Returns the detail normal maps' weight.
bool Ogre::HlmsPbsDatablock::getReceiveShadows | ( | ) | const |
|
inline |
float Ogre::HlmsPbsDatablock::getRoughness | ( | ) | const |
Vector3 Ogre::HlmsPbsDatablock::getSpecular | ( | ) | const |
uint8 Ogre::HlmsPbsDatablock::getTextureUvSource | ( | PbsTextureTypes | sourceType | ) | const |
|
inline |
|
inline |
bool Ogre::HlmsPbsDatablock::getTwoSidedLighting | ( | ) | const |
|
inline |
bool Ogre::HlmsPbsDatablock::getUseDiffuseMapAsGrayscale | ( | ) | const |
bool Ogre::HlmsPbsDatablock::getUseEmissiveAsLightmap | ( | ) | const |
Workflows Ogre::HlmsPbsDatablock::getWorkflow | ( | ) | const |
bool Ogre::HlmsPbsDatablock::hasEmissiveConstant | ( | ) | const |
Returns true iif getEmissive is non-zero.
bool Ogre::HlmsPbsDatablock::hasSeparateFresnel | ( | ) | const |
Whether the same fresnel term is used for RGB, or individual ones for each channel.
void Ogre::HlmsPbsDatablock::importUnity | ( | const Vector3 & | colour, |
Real | metallic, | ||
Real | roughness, | ||
bool | changeBrdf | ||
) |
Helper function to import values from Unity (metallic workflow).
void Ogre::HlmsPbsDatablock::importUnity | ( | const Vector3 & | diffuse, |
const Vector3 & | specular, | ||
Real | roughness, | ||
bool | changeBrdf | ||
) |
Helper function to import & convert values from Unity (specular workflow).
changeBrdf | True if you want us to select a BRDF that closely matches that of Unity. It will change the BRDF to PbsBrdf::DefaultUncorrelated. For best realism though, it is advised that you use that you actually use PbsBrdf::Default. |
|
override |
|
override |
|
override |
void Ogre::HlmsPbsDatablock::setBackgroundDiffuse | ( | const ColourValue & | bgDiffuse | ) |
Sets the diffuse background colour.
When no diffuse texture is present, this solid colour replaces it, and can act as a background for the detail maps.
void Ogre::HlmsPbsDatablock::setBrdf | ( | PbsBrdf::PbsBrdf | brdf | ) |
Changes the BRDF in use.
Calling this function may trigger an HlmsDatablock::flushRenderables
void Ogre::HlmsPbsDatablock::setClearCoat | ( | float | clearCoat | ) |
Sets the strength of the of the clear coat layer and its roughness.
clearCoat | This should be treated as a binary value, set to either 0 or 1. Intermediate values are useful to control transitions between parts of the surface that have a clear coat layers and parts that don't. |
void Ogre::HlmsPbsDatablock::setClearCoatRoughness | ( | float | roughness | ) |
void Ogre::HlmsPbsDatablock::setCubemapProbe | ( | CubemapProbe * | probe | ) |
Manually set a probe to affect this particular material.
To use manual probes just call: datablock->setCubemapProbe( probe );
To use Auto you don't need to do anything. Just enable PCC: hlmsPbs->setParallaxCorrectedCubemap( mParallaxCorrectedCubemap ); and leave PBSM_REFLECTION empty and don't enable manual mode.
probe | The probe that should affect this material to enable manual mode. Null pointer to disable manual mode and switch to auto. |
void Ogre::HlmsPbsDatablock::setDetailMapBlendMode | ( | uint8 | detailMapIdx, |
PbsBlendModes | blendMode | ||
) |
Changes the blend mode of the detail map.
Calling this function triggers a HlmsDatablock::flushRenderables even if you never use detail maps (they affect the cache's hash)
detailMapIdx | Value in the range [0; 4) |
blendMode | Blend mode |
void Ogre::HlmsPbsDatablock::setDetailMapOffsetScale | ( | uint8 | detailMap, |
const Vector4 & | offsetScale | ||
) |
Sets the scale and offset of the detail map.
detailMap | Value in the range [0; 4) |
offsetScale | XY = Contains the UV offset. ZW = Constains the UV scale. Default value is Vector4( 0, 0, 1, 1 ) |
Sets the weight of detail map.
Affects both diffuse and normal at the same time.
detailMap | Value in the range [0; 4) |
weight | The weight for the detail map. Usual values are in range [0; 1] but any value is accepted and valid. Default value is 1 |
Sets the normal mapping weight.
The range doesn't necessarily have to be in [0; 1]
detailNormalMapIdx | Value in the range [0; 4) |
weight | The weight for the normal map. A value of 0 means no effect (tangent space normal is 0, 0, 1); and would be the same as disabling the normal map texture. A value of 1 means full normal map effect. A value outside the [0; 1] range extrapolates. Default value is 1. |
void Ogre::HlmsPbsDatablock::setDiffuse | ( | const Vector3 & | diffuseColour | ) |
Sets the diffuse colour (final multiplier).
The colour will be divided by PI for energy conservation.
void Ogre::HlmsPbsDatablock::setEmissive | ( | const Vector3 & | emissiveColour | ) |
Sets emissive colour (e.g.
a firefly). Emissive colour has no physical basis. Though in HDR, if you're working in lumens, this value should probably be in lumens too. To disable emissive, setEmissive( Vector3::ZERO ) and unset any texture in PBSM_EMISSIVE slot.
void Ogre::HlmsPbsDatablock::setFresnel | ( | const Vector3 & | fresnel, |
bool | separateFresnel | ||
) |
Sets the fresnel (F0) directly, instead of using the IOR.
refractionIdx | The fresnel of the material for each colour component. When separateFresnel = false, the Y and Z components are ignored. |
separateFresnel | Whether to use the same fresnel term for RGB channel, or individual ones. |
void Ogre::HlmsPbsDatablock::setIndexOfRefraction | ( | const Vector3 & | refractionIdx, |
bool | separateFresnel | ||
) |
Calculates fresnel (F0 in most books) based on the IOR.
The formula used is ( (1 - idx) / (1 + idx) )²
refractionIdx | The index of refraction of the material for each colour component. When separateFresnel = false, the Y and Z components are ignored. |
separateFresnel | Whether to use the same fresnel term for RGB channel, or individual ones. |
void Ogre::HlmsPbsDatablock::setMetalness | ( | float | metalness | ) |
Sets the metalness in a metallic workflow.
metalness | Value in range [0; 1] |
void Ogre::HlmsPbsDatablock::setNormalMapWeight | ( | Real | weight | ) |
See setDetailNormalWeight(). This is the same, but for the main normal map.
void Ogre::HlmsPbsDatablock::setReceiveShadows | ( | bool | receiveShadows | ) |
When false, objects with this material will not receive shadows (independent of whether they case shadows or not)
receiveShadows | Whether to enable or disable receiving shadows. |
void Ogre::HlmsPbsDatablock::setRefractionStrength | ( | float | strength | ) |
Sets the strength of the refraction, i.e.
how much displacement in screen space.
This value is not physically based. Only used when HlmsPbsDatablock::setTransparency was set to HlmsPbsDatablock::Refractive
strength | Refraction strength. Useful range is often (0; 1) but any value is valid (even negative), but the bigger the number, the more likely glitches will appear (with large values we have to fallback to regular alpha blending due to the screen space pixel landing outside the screen) |
void Ogre::HlmsPbsDatablock::setRoughness | ( | float | roughness | ) |
Sets the roughness.
void Ogre::HlmsPbsDatablock::setSpecular | ( | const Vector3 & | specularColour | ) |
Sets the specular colour.
void Ogre::HlmsPbsDatablock::setTexture | ( | PbsTextureTypes | texUnit, |
const String & | name, | ||
const HlmsSamplerblock * | refParams = 0 |
||
) |
void Ogre::HlmsPbsDatablock::setTextureUvSource | ( | PbsTextureTypes | sourceType, |
uint8 | uvSet | ||
) |
Sets which UV set to use for the given texture.
Calling this function triggers a HlmsDatablock::flushRenderables.
sourceType | Source texture to modify. Note that we don't enforce PBSM_SOURCE_DETAIL0 = PBSM_SOURCE_DETAIL_NM0, but you probably want to have both textures using the same UV source. Must be lower than NUM_PBSM_SOURCES. |
uvSet | UV coordinate set. Value must be between in range [0; 8) |
void Ogre::HlmsPbsDatablock::setTransparency | ( | float | transparency, |
TransparencyModes | mode = Transparent , |
||
bool | useAlphaFromTextures = true , |
||
bool | changeBlendblock = true |
||
) |
Makes the material transparent, and sets the amount of transparency.
transparency | Value in range [0; 1] where 0 = full transparency and 1 = fully opaque. |
mode | see TransparencyModes |
useAlphaFromTextures | When false, the alpha channel of the diffuse maps and detail maps will be ignored. It's a GPU performance optimization. |
changeBlendblock | When true, the routine prepares the ideal blendblock to use according to the selected mode. When false, the user is expected to change the blendblock manually before calling this function to prevent false warnings. Useful for advanced experiments or artistic license. |
void Ogre::HlmsPbsDatablock::setTwoSidedLighting | ( | bool | twoSided, |
bool | changeMacroblock = true , |
||
CullingMode | oneSidedShadowCast = CULL_NONE |
||
) |
Allows support for two sided lighting.
Disabled by default (faster)
twoSided | Whether to enable or disable. |
changeMacroblock | Whether to change the current macroblock for one that has cullingMode = CULL_NONE or set it to false to leave the current macroblock as is. |
oneSidedShadowCast | If changeMacroblock == true; this parameter controls the culling mode of the shadow caster. While oneSidedShadowCast == CULL_NONE is usually the "correct" option, setting oneSidedShadowCast=CULL_ANTICLOCKWISE can prevent ugly self-shadowing on interiors. |
void Ogre::HlmsPbsDatablock::setUseDiffuseMapAsGrayscale | ( | bool | bUseDiffuseMapAsGrayscale | ) |
When set, it treats the diffuse map as a grayscale map; which means it will spread red component to all rgb channels.
void Ogre::HlmsPbsDatablock::setUseEmissiveAsLightmap | ( | bool | bUseEmissiveAsLightmap | ) |
When set, it treats the emissive map as a lightmap; which means it will be multiplied against the diffuse component.
Sets the value of the userValue, this can be used in a custom piece.
userValueIdx | Which userValue to modify, in the range [0; 3) |
void Ogre::HlmsPbsDatablock::setWorkflow | ( | Workflows | workflow | ) |
Sets whether to use a specular workflow, or a metallic workflow.
bEnableMetallic |
uint32 Ogre::HlmsPbsDatablock::suggestFiltersForType | ( | PbsTextureTypes | type | ) | const |
bool Ogre::HlmsPbsDatablock::suggestUsingSRGB | ( | PbsTextureTypes | type | ) | const |
Suggests the TextureMapType (aka texture category) for each type of texture (i.e.
normals should load from TEXTURE_TYPE_NORMALS).
|
static |
|
static |