mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Adding one more feature for NULL_VAR in scribe function parameters and unifying the MAterialTexture shader code
This commit is contained in:
parent
00782b0e76
commit
9cb8bd0808
11 changed files with 158 additions and 140 deletions
88
libraries/render-utils/src/MaterialTextures.slh
Normal file
88
libraries/render-utils/src/MaterialTextures.slh
Normal file
|
@ -0,0 +1,88 @@
|
|||
<!
|
||||
// MaterialTextures.slh
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Sam Gateau on 2/22/16
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
!>
|
||||
<@if not MODEL_MATERIAL_TEXTURES_SLH@>
|
||||
<@def MODEL_MATERIAL_TEXTURES_SLH@>
|
||||
|
||||
<@func declareMaterialTextures(withAlbedo, withRoughness, withNormal, withMetallic)@>
|
||||
|
||||
<@if withAlbedo@>
|
||||
uniform sampler2D albedoMap;
|
||||
vec4 fetchAlbedoMap(vec2 uv) {
|
||||
return texture(albedoMap, uv);
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
<!
|
||||
<@if withRoughness@>
|
||||
uniform sampler2D roughnessMap;
|
||||
float fetchRoughnessMap(vec2 uv) {
|
||||
return texture(roughnessMap, uv).r;
|
||||
}
|
||||
<@endif@>
|
||||
!>
|
||||
|
||||
<@if withNormal@>
|
||||
uniform sampler2D normalMap;
|
||||
vec3 fetchNormalMap(vec2 uv) {
|
||||
return texture(normalMap, uv).xyz;
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
<@if withMetallic@>
|
||||
uniform sampler2D specularMap;
|
||||
vec3 fetchMetallicMap(vec2 uv) {
|
||||
return texture(specularMap, uv).rgb;
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
<@endfunc@>
|
||||
|
||||
|
||||
<@func fetchMaterialTextures(texcoord0, albedo, roughness, normal, metallic)@>
|
||||
<@if albedo@>
|
||||
vec4 <$albedo$> = fetchAlbedoMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@if roughness@>
|
||||
float <$roughness$> = 1.0; //fetchRoughnessMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@if normal@>
|
||||
vec3 <$normal$> = fetchNormalMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@if metallic@>
|
||||
vec3 <$metallic$> = fetchMetallicMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@endfunc@>
|
||||
|
||||
|
||||
<@func declareMaterialLightmap()@>
|
||||
uniform sampler2D emissiveMap;
|
||||
uniform vec2 emissiveParams;
|
||||
vec3 fetchLightmapMap(vec2 uv) {
|
||||
return (vec3(emissiveParams.x) + emissiveParams.y * texture(emissiveMap, uv).rgb);
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@func fetchMaterialLightmap(texcoord1, lightmapVal)@>
|
||||
vec3 <$lightmapVal$> = fetchLightmapMap(<$texcoord1$>);
|
||||
<@endfunc@>
|
||||
|
||||
|
||||
<@func tangentToViewSpace(fetchedNormal, interpolatedNormal, interpolatedTangent, normal)@>
|
||||
{
|
||||
vec3 normalizedNormal = normalize(<$interpolatedNormal$>.xyz);
|
||||
vec3 normalizedTangent = normalize(<$interpolatedTangent$>.xyz);
|
||||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||
vec3 localNormal = normalize(<$fetchedNormal$> - vec3(0.5, 0.5, 0.5));
|
||||
<$normal$> = vec3(normalizedTangent * localNormal.x + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z);
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@endif@>
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
<@include model/Material.slh@>
|
||||
|
||||
uniform sampler2D albedoMap;
|
||||
uniform sampler2D roughnessMap;
|
||||
<@include MaterialTextures.slh@>
|
||||
<$declareMaterialTextures(ALBEDO, ROUGHNESS)$>
|
||||
|
||||
in vec4 _position;
|
||||
in vec3 _normal;
|
||||
|
@ -25,10 +25,8 @@ in vec2 _texCoord0;
|
|||
|
||||
|
||||
void main(void) {
|
||||
// Fetch maps
|
||||
vec4 albedo = texture(albedoMap, _texCoord0);
|
||||
float roughness = texture(roughnessMap, _texCoord0);
|
||||
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragment(
|
||||
|
|
|
@ -16,13 +16,9 @@
|
|||
|
||||
<@include model/Material.slh@>
|
||||
|
||||
// the albedo texture
|
||||
uniform sampler2D albedoMap;
|
||||
uniform sampler2D roughnessMap;
|
||||
|
||||
// the emissive map texture and parameters
|
||||
uniform sampler2D emissiveMap;
|
||||
uniform vec2 emissiveParams;
|
||||
<@include MaterialTextures.slh@>
|
||||
<$declareMaterialTextures(ALBEDO, ROUGHNESS)$>
|
||||
<$declareMaterialLightmap()$>
|
||||
|
||||
in vec4 _position;
|
||||
in vec2 _texCoord0;
|
||||
|
@ -31,10 +27,9 @@ in vec3 _normal;
|
|||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
// Fetch maps
|
||||
vec4 albedo = texture(albedoMap, _texCoord0);
|
||||
float roughness = texture(roughnessMap, _texCoord0);
|
||||
vec4 emissive = texture(emissiveMap, _texCoord1);
|
||||
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness)$>
|
||||
<$fetchMaterialLightmap(_texCoord1, emissive)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
|
|
|
@ -16,16 +16,9 @@
|
|||
|
||||
<@include model/Material.slh@>
|
||||
|
||||
// the albedo texture
|
||||
uniform sampler2D albedoMap;
|
||||
uniform sampler2D roughnessMap;
|
||||
|
||||
// the normal map texture
|
||||
uniform sampler2D normalMap;
|
||||
|
||||
// the emissive map texture and parameters
|
||||
uniform sampler2D emissiveMap;
|
||||
uniform vec2 emissiveParams;
|
||||
<@include MaterialTextures.slh@>
|
||||
<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL)$>
|
||||
<$declareMaterialLightmap()$>
|
||||
|
||||
in vec4 _position;
|
||||
in vec2 _texCoord0;
|
||||
|
@ -35,22 +28,15 @@ in vec3 _tangent;
|
|||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
// Fetch maps
|
||||
vec4 albedo = texture(albedoMap, _texCoord0);
|
||||
float roughness = texture(roughness, _texCoord0);
|
||||
vec4 emissive = texture(emissiveMap, _texCoord1);
|
||||
vec3 localNormal = vec3(texture(normalMap, _texCoord0)) - vec3(0.5, 0.5, 0.5);
|
||||
|
||||
// compute the view normal from the various bits
|
||||
vec3 normalizedNormal = normalize(_normal);
|
||||
vec3 normalizedTangent = normalize(_tangent);
|
||||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, normalTexel)$>
|
||||
<$fetchMaterialLightmap(_texCoord1, lightmapVal)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
vec3 viewNormal;
|
||||
<$tangentToViewSpace(normalTexel, _normal, _tangent, viewNormal)$>
|
||||
|
||||
packDeferredFragmentLightmap(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
|
||||
|
@ -58,5 +44,5 @@ void main(void) {
|
|||
getMaterialRoughness(mat),
|
||||
getMaterialMetallic(mat),
|
||||
getMaterialFresnel(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
lightmapVal);
|
||||
}
|
||||
|
|
|
@ -16,19 +16,9 @@
|
|||
|
||||
<@include model/Material.slh@>
|
||||
|
||||
// the albedo texture
|
||||
uniform sampler2D albedoMap;
|
||||
uniform sampler2D roughnessMap;
|
||||
|
||||
// the emissive map texture and parameters
|
||||
uniform sampler2D emissiveMap;
|
||||
uniform vec2 emissiveParams;
|
||||
|
||||
// the normal map texture
|
||||
uniform sampler2D normalMap;
|
||||
|
||||
// the specular map texture
|
||||
uniform sampler2D specularMap;
|
||||
<@include MaterialTextures.slh@>
|
||||
<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC)$>
|
||||
<$declareMaterialLightmap()$>
|
||||
|
||||
in vec4 _position;
|
||||
in vec2 _texCoord0;
|
||||
|
@ -38,21 +28,13 @@ in vec3 _tangent;
|
|||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
// Fetch maps
|
||||
vec4 albedo = texture(albedoMap, _texCoord0);
|
||||
float roughness = texture(roughnessMap, _texCoord0);
|
||||
vec3 specular = texture(specularMap, _texCoord0).rgb;
|
||||
vec4 emissive = texture(emissiveMap, _texCoord1);
|
||||
vec3 localNormal = vec3(texture(normalMap, _texCoord0)) - vec3(0.5, 0.5, 0.5);
|
||||
|
||||
// compute the view normal from the various bits
|
||||
vec3 normalizedNormal = normalize(_normal);
|
||||
vec3 normalizedTangent = normalize(_tangent);
|
||||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, normalTexel, specular)$>
|
||||
<$fetchMaterialLightmap(_texCoord1, lightmapVal)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
vec3 viewNormal;
|
||||
<$tangentToViewSpace(normalTexel, _normal, _tangent, viewNormal)$>
|
||||
|
||||
packDeferredFragmentLightmap(
|
||||
normalize(viewNormal.xyz),
|
||||
|
@ -61,5 +43,5 @@ void main(void) {
|
|||
getMaterialRoughness(mat) * roughness,
|
||||
getMaterialMetallic(mat),
|
||||
specular, // no use of getMaterialFresnel(mat)
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
lightmapVal);
|
||||
}
|
||||
|
|
|
@ -16,16 +16,9 @@
|
|||
|
||||
<@include model/Material.slh@>
|
||||
|
||||
// the albedo texture
|
||||
uniform sampler2D albedoMap;
|
||||
uniform sampler2D roughnessMap;
|
||||
|
||||
// the emissive map texture and parameters
|
||||
uniform sampler2D emissiveMap;
|
||||
uniform vec2 emissiveParams;
|
||||
|
||||
// the specular texture
|
||||
uniform sampler2D specularMap;
|
||||
<@include MaterialTextures.slh@>
|
||||
<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC)$>
|
||||
<$declareMaterialLightmap()$>
|
||||
|
||||
in vec4 _position;
|
||||
in vec2 _texCoord0;
|
||||
|
@ -34,12 +27,9 @@ in vec3 _normal;
|
|||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
// Fetch maps
|
||||
vec4 albedo = texture(albedoMap, _texCoord0);
|
||||
float roughness = texture(roughnessMap, _texCoord0);
|
||||
vec3 specular = texture(specularMap, _texCoord0).rgb;
|
||||
vec4 emissive = texture(emissiveMap, _texCoord1);
|
||||
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, _SCRIBE_NULL, specular)$>
|
||||
<$fetchMaterialLightmap(_texCoord1, lightmapVal)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragmentLightmap(
|
||||
|
@ -49,5 +39,5 @@ void main(void) {
|
|||
getMaterialRoughness(mat) * roughness,
|
||||
getMaterialMetallic(mat),
|
||||
specular, // no use of getMaterialFresnel(mat)
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
lightmapVal);
|
||||
}
|
||||
|
|
|
@ -15,14 +15,9 @@
|
|||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
<@include model/Material.slh@>
|
||||
<@include model/MaterialTextures.slh@>
|
||||
|
||||
// the albedo texture
|
||||
uniform sampler2D albedoMap;
|
||||
uniform sampler2D roughnessMap;
|
||||
|
||||
// the normal map texture
|
||||
uniform sampler2D normalMap;
|
||||
<@include MaterialTextures.slh@>
|
||||
<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL)$>
|
||||
|
||||
in vec4 _position;
|
||||
in vec2 _texCoord0;
|
||||
|
@ -31,21 +26,15 @@ in vec3 _tangent;
|
|||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
// compute the view normal from the various bits
|
||||
vec3 normalizedNormal = normalize(_normal.xyz);
|
||||
vec3 normalizedTangent = normalize(_tangent.xyz);
|
||||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||
vec3 localNormal = normalize(vec3(texture(normalMap, _texCoord0.st)) - vec3(0.5, 0.5, 0.5));
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
|
||||
vec4 albedo = texture(albedoMap, _texCoord0.st);
|
||||
float roughness = texture(roughnessMap, _texCoord0);
|
||||
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, normalTexel)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
vec3 viewNormal;
|
||||
<$tangentToViewSpace(normalTexel, _normal, _tangent, viewNormal)$>
|
||||
|
||||
packDeferredFragment(
|
||||
normalize(viewNormal.xyz),
|
||||
viewNormal,
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
|
||||
getMaterialAlbedo(mat) * albedo.rgb * _color,
|
||||
getMaterialRoughness(mat) * roughness,
|
||||
|
|
|
@ -16,15 +16,8 @@
|
|||
|
||||
<@include model/Material.slh@>
|
||||
|
||||
// the albedo texture
|
||||
uniform sampler2D albedoMap;
|
||||
uniform sampler2D roughnessMap;
|
||||
|
||||
// the normal map texture
|
||||
uniform sampler2D normalMap;
|
||||
|
||||
// the specular map texture
|
||||
uniform sampler2D specularMap;
|
||||
<@include MaterialTextures.slh@>
|
||||
<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC)$>
|
||||
|
||||
in vec4 _position;
|
||||
in vec2 _texCoord0;
|
||||
|
@ -33,27 +26,20 @@ in vec3 _tangent;
|
|||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
// compute the view normal from the various bits
|
||||
vec3 normalizedNormal = normalize(_normal);
|
||||
vec3 normalizedTangent = normalize(_tangent);
|
||||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||
vec3 localNormal = normalize(vec3(texture(normalMap, _texCoord0)) - vec3(0.5, 0.5, 0.5));
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
|
||||
// set the albedo, normal, specular data
|
||||
vec4 albedo = texture(albedoMap, _texCoord0);
|
||||
vec4 roughness = texture(roughnessMap, _texCoord0);
|
||||
vec3 specular = texture(specularMap, _texCoord0).rgb;
|
||||
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, normalTexel, specular)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
vec3 viewNormal;
|
||||
<$tangentToViewSpace(normalTexel, _normal, _tangent, viewNormal)$>
|
||||
|
||||
packDeferredFragment(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
|
||||
getMaterialAlbedo(mat) * albedo.rgb * _color,
|
||||
getMaterialRoughness(mat) * roughness,
|
||||
getMaterialMetallic(mat),
|
||||
specular //getMaterialFresnel(mat)
|
||||
vec3(specular) //getMaterialFresnel(mat)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -16,12 +16,8 @@
|
|||
|
||||
<@include model/Material.slh@>
|
||||
|
||||
// the albedo texture
|
||||
uniform sampler2D albedoMap;
|
||||
uniform sampler2D roughnessMap;
|
||||
|
||||
// the specular texture
|
||||
uniform sampler2D specularMap;
|
||||
<@include MaterialTextures.slh@>
|
||||
<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC)$>
|
||||
|
||||
in vec4 _position;
|
||||
in vec2 _texCoord0;
|
||||
|
@ -30,11 +26,9 @@ in vec3 _color;
|
|||
|
||||
|
||||
void main(void) {
|
||||
// set the albedo, normal, specular data
|
||||
vec4 albedo = texture(albedoMap, _texCoord0);
|
||||
float roughness = texture(roughnessMap, _texCoord0);
|
||||
vec3 specular = texture(specularMap, _texCoord0).rgb;
|
||||
|
||||
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, _SCRIBE_NULL, specular)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragment(
|
||||
|
@ -43,6 +37,6 @@ void main(void) {
|
|||
getMaterialAlbedo(mat) * albedo.rgb * _color,
|
||||
getMaterialRoughness(mat) * roughness,
|
||||
getMaterialMetallic(mat),
|
||||
specular //getMaterialFresnel(mat)
|
||||
vec3(specular) //getMaterialFresnel(mat)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ typedef TextTemplate::Block::Pointer BlockPointer;
|
|||
typedef TextTemplate::Config::Pointer ConfigPointer;
|
||||
typedef TextTemplate::Pointer TextTemplatePointer;
|
||||
|
||||
const std::string TextTemplate::Tag::NULL_VAR = "_SCRIBE_NULL";
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
TextTemplate::Config::Config() :
|
||||
_includes(),
|
||||
|
@ -370,7 +372,11 @@ bool TextTemplate::convertExpressionToFuncArguments(String& src, std::vector< St
|
|||
token += c;
|
||||
} else if (c == ',') {
|
||||
if (!token.empty()) {
|
||||
arguments.push_back(token);
|
||||
if (token == Tag::NULL_VAR) {
|
||||
arguments.push_back(Tag::NULL_VAR);
|
||||
} else {
|
||||
arguments.push_back(token);
|
||||
}
|
||||
nbTokens++;
|
||||
}
|
||||
token.clear();
|
||||
|
@ -750,7 +756,9 @@ int TextTemplate::evalBlockGeneration(std::ostream& dst, const BlockPointer& blo
|
|||
paramCache.push_back((*it).second);
|
||||
(*it).second = val;
|
||||
} else {
|
||||
vars.insert(Vars::value_type(funcBlock->command.arguments[i], val));
|
||||
if (val != Tag::NULL_VAR) {
|
||||
vars.insert(Vars::value_type(funcBlock->command.arguments[i], val));
|
||||
}
|
||||
paramCache.push_back("");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ public:
|
|||
static const char VAR = '$';
|
||||
static const char COM = '@';
|
||||
static const char REM = '!';
|
||||
|
||||
static const std::string NULL_VAR;
|
||||
};
|
||||
|
||||
class Command {
|
||||
|
|
Loading…
Reference in a new issue