Separated Shaders from Manager

Former-commit-id: 7faddbd38bd729b2778f09be3f98105ef5219740
This commit is contained in:
Lynix 2013-08-25 19:55:03 +02:00
parent 881d6eb3e2
commit f1dc7b98e5
36 changed files with 1233 additions and 637 deletions

2
build/Encode Shaders.bat Normal file
View File

@ -0,0 +1,2 @@
premake4 encodeshaders
pause

View File

@ -0,0 +1,42 @@
function encodeShaders()
local targets = os.matchdirs("../src/Nazara/Renderer/Shaders/*")
for k, targetPath in pairs(targets) do
local shaders = os.matchfiles(targetPath .. "/*")
for k, filePath in pairs(shaders) do
local ext = filePath:sub(-5)
if (ext == ".frag" or ext == ".geom" or ext == ".vert") then
local shader, err = io.open(filePath, "rb")
if (not shader) then
error("Failed to read shader file: " .. err)
end
local header, err = io.open(filePath .. ".h", "w+")
if (not header) then
error("Failed to create header file: " .. err)
end
local str = shader:read(64)
repeat
local l = str:len()
for i = 1, l do
local byte = str:sub(i, i):byte()
if (byte >= 128) then
byte = byte - 256
end
header:write(string.format("%d,", byte))
end
str = shader:read(64)
until (not str)
header:close()
end
end
end
end
newaction
{
trigger = "encodeshaders",
description = "Generate a includable header version of shaders",
execute = encodeShaders
}

View File

@ -157,9 +157,9 @@ enum nzShaderFlags
{
nzShaderFlags_None = 0,
//nzShaderFlags_Deferred = 0x1,
nzShaderFlags_FlipUVs = 0x1,
nzShaderFlags_Instancing = 0x2,
nzShaderFlags_Deferred = 0x1,
nzShaderFlags_FlipUVs = 0x2,
nzShaderFlags_Instancing = 0x4,
nzShaderFlags_Max = nzShaderFlags_Instancing*2-1
};

View File

@ -85,10 +85,6 @@ namespace
std::unordered_map<NzShaderProgramManagerParams, NzShaderProgramRef, ParamsHash, ParamsEquality> s_programs;
NzString s_cacheDirectory("shaderCache");
NzString s_inKW;
NzString s_outKW;
NzString s_fragmentColorKW;
NzString s_textureLookupKW;
bool s_cacheEnabled = false;
bool s_earlyFragmentTest;
bool s_glsl140;
@ -163,7 +159,9 @@ const NzShaderProgram* NzShaderProgramManager::Get(const NzShaderProgramManagerP
else
program.reset(GenerateProgram(params));
if (!program)
if (program)
s_programs[params] = program.get();
else
{
NazaraWarning("Failed to build program, using default one...");
@ -191,507 +189,171 @@ NzString NzShaderProgramManager::BuildFragmentCode(const NzShaderProgramManagerP
#endif
NzString source;
source.Reserve(2048); // Le shader peut faire plus, mais cela évite déjà beaucoup de petites allocations
/********************Header********************/
source.Reserve(14 + 24 + 1);
source += "#version ";
source += NzString::Number(s_glslVersion);
source += "\n\n";
source += "#define FLAG_DEFERRED ";
source += (params.flags & nzShaderFlags_Deferred) ? '1' : '0';
source += '\n';
source += '\n';
switch (params.target)
{
case nzShaderTarget_FullscreenQuad:
{
char coreFragmentShader[] = {
#include <Nazara/Renderer/Shaders/FullscreenQuad/core.frag.h>
};
char compatibilityFragmentShader[] = {
#include <Nazara/Renderer/Shaders/FullscreenQuad/compatibility.frag.h>
};
const char* shaderSource = (s_glsl140) ? coreFragmentShader : compatibilityFragmentShader;
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreFragmentShader) : sizeof(compatibilityFragmentShader);
source.Reserve(source.GetCapacity() + 34 + 24 + 21 + 26 + 1 + shaderSourceSize);
// "discard" ne s'entend pas bien avec les early fragment tests
if (s_earlyFragmentTest && !params.fullscreenQuad.alphaMapping)
source += "layout(early_fragment_tests) in;" "\n\n";
source += "layout(early_fragment_tests) in;\n\n";
/********************Entrant********************/
if (params.fullscreenQuad.alphaMapping || params.fullscreenQuad.diffuseMapping)
source += s_inKW + " vec2 vTexCoord;" "\n\n";
source += "#define ALPHA_MAPPING ";
source += (params.fullscreenQuad.alphaMapping) ? '1' : '0';
source += '\n';
/********************Sortant********************/
if (s_glsl140)
source += "out vec4 RenderTarget0;" "\n\n";
source += "#define ALPHA_TEST ";
source += (params.fullscreenQuad.alphaTest) ? '1' : '0';
source += '\n';
/********************Uniformes********************/
if (params.fullscreenQuad.alphaMapping)
source += "uniform sampler2D MaterialAlphaMap;" "\n";
if (params.fullscreenQuad.alphaTest)
source += "uniform float MaterialAlphaThreshold;" "\n";
source += "uniform vec4 MaterialDiffuse;" "\n";
if (params.fullscreenQuad.diffuseMapping)
source += "uniform sampler2D MaterialDiffuseMap;" "\n";
source += "#define DIFFUSE_MAPPING ";
source += (params.fullscreenQuad.diffuseMapping) ? '1' : '0';
source += '\n';
source += '\n';
/********************Fonctions********************/
source += "void main()" "\n"
"{" "\n";
source += "\t" "vec4 fragmentColor = MaterialDiffuse";
if (params.fullscreenQuad.diffuseMapping)
source += '*' + s_textureLookupKW + "(MaterialDiffuseMap, vTexCoord)";
source += ";" "\n";
if (params.fullscreenQuad.alphaMapping)
source += "fragmentColor.a *= " + s_textureLookupKW + "(MaterialAlphaMap, vTexCoord).r";
source += ";" "\n";
if (params.fullscreenQuad.alphaMapping)
{
source += "\t" "if (fragmentColor.a < MaterialAlphaThreshold)" "\n"
"\t\t" "discard;" "\n";
}
source += "\t" + s_fragmentColorKW + " = fragmentColor;" "\n"
"}" "\n";
source.Append(shaderSource, shaderSourceSize);
break;
}
case nzShaderTarget_Model:
{
//bool parallaxMapping = (params.model.lighting && params.model.parallaxMapping);
bool uvMapping = (params.model.alphaMapping || params.model.diffuseMapping || params.model.normalMapping || params.model.specularMapping);
char coreFragmentShader[] = {
#include <Nazara/Renderer/Shaders/Model/core.frag.h>
};
char compatibilityFragmentShader[] = {
#include <Nazara/Renderer/Shaders/Model/compatibility.frag.h>
};
const char* shaderSource = (s_glsl140) ? coreFragmentShader : compatibilityFragmentShader;
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreFragmentShader) : sizeof(compatibilityFragmentShader);
source.Reserve(source.GetCapacity() + 34 + 24 + 21 + 26 + 27 + 19 + 25 + 27 + 27 + 1 + shaderSourceSize);
// "discard" ne s'entend pas bien avec les early fragment tests
if (s_earlyFragmentTest && !params.model.alphaMapping)
source += "layout(early_fragment_tests) in;" "\n\n";
source += "layout(early_fragment_tests) in;\n\n";
if (params.model.lighting)
{
source += "#define LIGHT_DIRECTIONAL 0" "\n"
"#define LIGHT_POINT 1" "\n"
"#define LIGHT_SPOT 2" "\n\n";
}
/********************Entrant********************/
if (params.model.lighting)
{
if (params.model.normalMapping)
source += s_inKW + " mat3 vLightToWorld;" "\n";
else
source += s_inKW + " vec3 vNormal;" "\n";
}
if (uvMapping)
source += s_inKW + " vec2 vTexCoord;" "\n";
if (params.model.lighting)
source += s_inKW + " vec3 vWorldPos;" "\n";
if (params.model.lighting || uvMapping)
source += "#define ALPHA_MAPPING ";
source += (params.model.alphaMapping) ? '1' : '0';
source += '\n';
/********************Sortant********************/
if (s_glsl140)
source += "out vec4 RenderTarget0;" "\n\n";
source += "#define ALPHA_TEST ";
source += (params.model.alphaTest) ? '1' : '0';
source += '\n';
/********************Uniformes********************/
if (params.model.lighting)
{
source += "struct Light" "\n"
"{" "\n"
"\t" "int type;" "\n"
"\t" "vec4 ambient;" "\n"
"\t" "vec4 diffuse;" "\n"
"\t" "vec4 specular;" "\n\n"
source += "#define DIFFUSE_MAPPING ";
source += (params.model.diffuseMapping) ? '1' : '0';
source += '\n';
"\t" "vec4 parameters1;" "\n"
"\t" "vec4 parameters2;" "\n"
"\t" "vec2 parameters3;" "\n"
"};" "\n\n"
source += "#define EMISSIVE_MAPPING ";
source += (params.model.emissiveMapping) ? '1' : '0';
source += '\n';
"uniform vec3 EyePosition;" "\n"
"uniform Light Lights[3];" "\n"
"uniform vec4 MaterialAmbient;" "\n";
}
source += "#define LIGHTING ";
source += (params.model.lighting) ? '1' : '0';
source += '\n';
if (params.model.alphaMapping)
source += "uniform sampler2D MaterialAlphaMap;" "\n";
source += "#define NORMAL_MAPPING ";
source += (params.model.normalMapping) ? '1' : '0';
source += '\n';
if (params.model.alphaTest)
source += "uniform float MaterialAlphaThreshold;" "\n";
source += "#define PARALLAX_MAPPING ";
source += (params.model.parallaxMapping) ? '1' : '0';
source += '\n';
source += "uniform vec4 MaterialDiffuse;" "\n";
if (params.model.diffuseMapping)
source += "uniform sampler2D MaterialDiffuseMap;" "\n";
if (params.model.emissiveMapping)
source += "uniform sampler2D MaterialEmissiveMap;" "\n";
if (params.model.lighting)
{
if (params.model.normalMapping)
source += "uniform sampler2D MaterialNormalMap;" "\n";
source += "uniform float MaterialShininess;" "\n"
"uniform vec4 MaterialSpecular;" "\n";
if (params.model.specularMapping)
source += "uniform sampler2D MaterialSpecularMap;" "\n";
source += "uniform vec4 SceneAmbient;" "\n";
}
source += "#define SPECULAR_MAPPING ";
source += (params.model.specularMapping) ? '1' : '0';
source += '\n';
source += '\n';
/********************Fonctions********************/
source += "void main()" "\n"
"{" "\n";
/*if (!parallaxMapping)
{*/
source += "\t" "vec4 fragmentColor = MaterialDiffuse";
if (params.model.diffuseMapping)
source += '*' + s_textureLookupKW + "(MaterialDiffuseMap, vTexCoord)";
source += ";" "\n";
//}
if (params.model.alphaMapping)
{
source += "\t" "fragmentColor.a *= ";
if (params.model.alphaMapping)
source += s_textureLookupKW + "(MaterialAlphaMap, vTexCoord).r";
/*if (parallaxMapping && params.model.diffuseMapping)
source += '*' + s_textureLookupKW + "(MaterialDiffuseMap, vTexCoord).a";*/
source += ";" "\n";
}
if (params.model.alphaTest)
{
source += "\t" "if (fragmentColor.a < MaterialAlphaThreshold)" "\n"
"\t\t" "discard;" "\n";
}
if (params.model.lighting)
{
source += "\t" "vec3 lightColor = vec3(0.0);" "\n";
if (params.model.specularMapping)
source += "\t" "vec3 specularColor = vec3(0.0);" "\n";
if (params.model.normalMapping)
source += "\t" "vec3 normal = normalize(vLightToWorld * (2.0 * vec3(" + s_textureLookupKW + "(MaterialNormalMap, vTexCoord)) - 1.0));" "\n";
else
source += "\t" "vec3 normal = normalize(vNormal);" "\n";
source += '\n';
source += "\t" "if (MaterialShininess > 0.0)" "\n"
"\t" "{" "\n"
"\t\t" "vec3 eyeVec = normalize(EyePosition - vWorldPos);" "\n\n"
"\t\t" "for (int i = 0; i < 3; ++i)" "\n"
"\t\t" "{" "\n";
if (s_glsl140)
{
source += "\t\t\t" "switch (Lights[i].type)" "\n"
"\t\t\t" "{" "\n"
"\t\t\t\t" "case LIGHT_DIRECTIONAL:" "\n";
}
else // Le GLSL 110 n'a pas d'instruction switch
source += "\t\t\t" "if (Lights[i].type == LIGHT_DIRECTIONAL)" "\n";
// Directional Light
source += "\t\t\t\t" "{" "\n"
"\t\t\t\t\t" "vec3 lightDir = normalize(-Lights[i].parameters1.xyz);" "\n"
"\t\t\t\t\t" "lightColor += Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);" "\n\n"
"\t\t\t\t\t" "float lambert = max(dot(normal, lightDir), 0.0);" "\n"
"\t\t\t\t\t" "lightColor += lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;" "\n\n"
"\t\t\t\t\t" "vec3 reflection = reflect(-lightDir, normal);" "\n"
"\t\t\t\t\t" "float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);" "\n";
if (params.model.specularMapping)
source += "\t\t\t\t\t" "specularColor";
else
source += "\t\t\t\t\t" "lightColor";
source += " += specular * Lights[i].specular.rgb * MaterialSpecular.rgb;" "\n";
if (s_glsl140)
{
source += "\t\t\t\t\t" "break;" "\n"
"\t\t\t\t" "}" "\n\n"
"\t\t\t\t" "case LIGHT_POINT:" "\n";
}
else
source += "\t\t\t" "}" "\n"
"\t\t\t" "else if (Lights[i].type == LIGHT_POINT)" "\n";
// Point Light
source += "\t\t\t\t" "{" "\n"
"\t\t\t\t\t" "vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;" "\n\n"
"\t\t\t\t\t" "float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);" "\n"
"\t\t\t\t\t" "lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);" "\n"
"\t\t\t\t\t" "lightDir = normalize(lightDir);" "\n"
"\t\t\t\t\t" "float lambert = max(dot(normal, lightDir), 0.0);" "\n"
"\t\t\t\t\t" "lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;" "\n\n"
"\t\t\t\t\t" "vec3 reflection = reflect(-lightDir, normal);" "\n"
"\t\t\t\t\t" "float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);" "\n";
if (params.model.specularMapping)
source += "\t\t\t\t\t" "specularColor";
else
source += "\t\t\t\t\t" "lightColor";
source += " += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;" "\n";
if (s_glsl140)
{
source += "\t\t\t\t\t" "break;" "\n"
"\t\t\t\t" "}" "\n\n"
"\t\t\t\t" "case LIGHT_SPOT:" "\n";
}
else
{
source += "\t\t\t" "}" "\n"
"\t\t\t" "else if (Lights[i].type == LIGHT_SPOT)" "\n";
}
// Spot Light
source += "\t\t\t\t" "{" "\n"
"\t\t\t\t\t" "vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;" "\n\n"
"\t\t\t\t\t" "float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*length(lightDir), 0.0);" "\n"
"\t\t\t\t\t" "lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);" "\n\n"
"\t\t\t\t\t" "lightDir = normalize(lightDir);" "\n\n"
"\t\t\t\t\t" "float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);" "\n"
"\t\t\t\t\t" "float outerAngle = Lights[i].parameters3.y;" "\n"
"\t\t\t\t\t" "float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;" "\n"
"\t\t\t\t\t" "float lambert = max(dot(normal, lightDir), 0.0);" "\n"
"\t\t\t\t\t" "att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);" "\n"
"\t\t\t\t\t" "lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;" "\n\n"
"\t\t\t\t\t" "vec3 reflection = reflect(-lightDir, normal);" "\n"
"\t\t\t\t\t" "float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);" "\n";
if (params.model.specularMapping)
source += "\t\t\t\t\t" "specularColor";
else
source += "\t\t\t\t\t" "lightColor";
source += " += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;\n";
if (s_glsl140)
{
source += "\t\t\t\t\t" "break;" "\n"
"\t\t\t\t" "}" "\n\n"
"\t\t\t\t" "default:" "\n"
"\t\t\t\t\t" "break;" "\n"
"\t\t\t" "}" "\n";
}
else
source += "\t\t\t" "}" "\n";
source += "\t\t" "}" "\n"
"\t" "}" "\n"
"\t" "else" "\n"
"\t" "{" "\n";
source += "\t\t" "for (int i = 0; i < 3; ++i)" "\n"
"\t\t" "{" "\n";
if (s_glsl140)
{
source += "\t\t\t" "switch (Lights[i].type)" "\n"
"\t\t\t" "{" "\n"
"\t\t\t\t" "case LIGHT_DIRECTIONAL:" "\n";
}
else // Le GLSL 110 n'a pas d'instruction switch
source += "\t\t\t" "if (Lights[i].type == LIGHT_DIRECTIONAL)" "\n";
// Directional Light
source += "\t\t\t\t" "{" "\n"
"\t\t\t\t\t" "vec3 lightDir = normalize(-Lights[i].parameters1.xyz);" "\n"
"\t\t\t\t\t" "lightColor += Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);" "\n\n"
"\t\t\t\t\t" "float lambert = max(dot(normal, lightDir), 0.0);" "\n"
"\t\t\t\t\t" "lightColor += lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;" "\n\n";
if (s_glsl140)
{
source += "\t\t\t\t\t" "break;" "\n"
"\t\t\t\t" "}" "\n\n"
"\t\t\t\t" "case LIGHT_POINT:" "\n";
}
else
source += "\t\t\t" "}" "\n"
"\t\t\t" "else if (Lights[i].type == LIGHT_POINT)" "\n";
// Point Light
source += "\t\t\t\t" "{" "\n"
"\t\t\t\t\t" "vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;" "\n\n"
"\t\t\t\t\t" "float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);" "\n"
"\t\t\t\t\t" "lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);" "\n"
"\t\t\t\t\t" "lightDir = normalize(lightDir);" "\n"
"\t\t\t\t\t" "float lambert = max(dot(normal, lightDir), 0.0);" "\n"
"\t\t\t\t\t" "lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;" "\n\n";
if (s_glsl140)
{
source += "\t\t\t\t\t" "break;" "\n"
"\t\t\t\t" "}" "\n\n"
"\t\t\t\t" "case LIGHT_SPOT:" "\n";
}
else
{
source += "\t\t\t" "}" "\n"
"\t\t\t" "else if (Lights[i].type == LIGHT_SPOT)" "\n";
}
// Spot Light
source += "\t\t\t\t" "{" "\n"
"\t\t\t\t\t" "vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;" "\n\n"
"\t\t\t\t\t" "float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*length(lightDir), 0.0);" "\n"
"\t\t\t\t\t" "lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);" "\n\n"
"\t\t\t\t\t" "lightDir = normalize(lightDir);" "\n\n"
"\t\t\t\t\t" "float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);" "\n"
"\t\t\t\t\t" "float outerAngle = Lights[i].parameters3.y;" "\n"
"\t\t\t\t\t" "float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;" "\n"
"\t\t\t\t\t" "float lambert = max(dot(normal, lightDir), 0.0);" "\n"
"\t\t\t\t\t" "att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);" "\n"
"\t\t\t\t\t" "lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;" "\n\n";
if (s_glsl140)
{
source += "\t\t\t\t\t" "break;" "\n"
"\t\t\t\t" "}" "\n\n"
"\t\t\t\t" "default:" "\n"
"\t\t\t\t\t" "break;" "\n"
"\t\t\t" "}" "\n";
}
else
source += "\t\t\t" "}" "\n";
source += "\t\t" "}" "\n"
"\t" "}" "\n\n"
"\t" "fragmentColor *= vec4(lightColor";
if (params.model.specularMapping)
source += "+ specularColor*" + s_textureLookupKW + "(MaterialSpecularMap, vTexCoord).rgb"; // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
source += ", 1.0);" "\n";
if (params.model.emissiveMapping)
{
if (params.model.specularMapping)
source += "\t" "float lightIntensity = dot(lightColor + specularColor, vec3(0.3, 0.59, 0.11));" "\n";
else
source += "\t" "float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));" "\n";
source += "\t" "vec3 emissionColor = MaterialDiffuse.rgb*" + s_textureLookupKW + "(MaterialEmissiveMap, vTexCoord).rgb;" "\n"
"\t" + s_fragmentColorKW + " = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);" "\n";
}
else
source += '\t' + s_fragmentColorKW + " = fragmentColor;" "\n";
}
else
source += '\t' + s_fragmentColorKW + " = fragmentColor;" "\n";
source += "}" "\n";
source.Append(shaderSource, shaderSourceSize);
break;
}
case nzShaderTarget_None:
{
char coreFragmentShader[] = {
#include <Nazara/Renderer/Shaders/None/core.frag.h>
};
char compatibilityFragmentShader[] = {
#include <Nazara/Renderer/Shaders/None/compatibility.frag.h>
};
const char* shaderSource = (s_glsl140) ? coreFragmentShader : compatibilityFragmentShader;
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreFragmentShader) : sizeof(compatibilityFragmentShader);
source.Reserve(source.GetCapacity() + 34 + shaderSourceSize);
if (s_earlyFragmentTest)
source += "layout(early_fragment_tests) in;" "\n\n";
source += "layout(early_fragment_tests) in;\n\n";
/********************Sortant********************/
if (s_glsl140)
source += "out vec4 RenderTarget0;" "\n\n";
/********************Uniformes********************/
source += "uniform vec4 MaterialDiffuse;" "\n\n";
/********************Fonctions********************/
source += "void main()" "\n"
"{" "\n";
source += '\t' + s_fragmentColorKW + " = MaterialDiffuse;" "\n";
source += "}" "\n";
source.Append(shaderSource, shaderSourceSize);
break;
}
case nzShaderTarget_Sprite:
{
char coreFragmentShader[] = {
#include <Nazara/Renderer/Shaders/Sprite/core.frag.h>
};
char compatibilityFragmentShader[] = {
#include <Nazara/Renderer/Shaders/Sprite/compatibility.frag.h>
};
const char* shaderSource = (s_glsl140) ? coreFragmentShader : compatibilityFragmentShader;
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreFragmentShader) : sizeof(compatibilityFragmentShader);
source.Reserve(source.GetCapacity() + 34 + 24 + 21 + 26 + 1 + shaderSourceSize);
// "discard" ne s'entend pas bien avec les early fragment tests
if (s_earlyFragmentTest && !params.sprite.alphaMapping)
source += "layout(early_fragment_tests) in;" "\n\n";
source += "layout(early_fragment_tests) in;\n\n";
/********************Entrant********************/
if (params.sprite.alphaMapping || params.sprite.diffuseMapping)
source += s_inKW + " vec2 vTexCoord;" "\n\n";
source += "#define ALPHA_MAPPING ";
source += (params.sprite.alphaMapping) ? '1' : '0';
source += '\n';
/********************Sortant********************/
if (s_glsl140)
source += "out vec4 RenderTarget0;" "\n\n";
source += "#define ALPHA_TEST ";
source += (params.sprite.alphaTest) ? '1' : '0';
source += '\n';
/********************Uniformes********************/
if (params.sprite.alphaMapping)
source += "uniform sampler2D MaterialAlphaMap;" "\n";
if (params.sprite.alphaTest)
source += "uniform float MaterialAlphaThreshold;" "\n";
source += "uniform vec4 MaterialDiffuse;" "\n";
if (params.sprite.diffuseMapping)
source += "uniform sampler2D MaterialDiffuseMap;" "\n";
source += "#define DIFFUSE_MAPPING ";
source += (params.sprite.diffuseMapping) ? '1' : '0';
source += '\n';
source += '\n';
/********************Fonctions********************/
source += "void main()" "\n"
"{" "\n";
source += "\t" "vec4 fragmentColor = MaterialDiffuse";
if (params.sprite.diffuseMapping)
source += '*' + s_textureLookupKW + "(MaterialDiffuseMap, vTexCoord)";
source += ";" "\n";
if (params.sprite.alphaMapping)
source += "fragmentColor.a *= " + s_textureLookupKW + "(MaterialAlphaMap, vTexCoord).r";
source += ";" "\n";
if (params.sprite.alphaMapping)
{
source += "\t" "if (fragmentColor.a < MaterialAlphaThreshold)" "\n"
"\t\t" "discard;" "\n";
}
source += "\t" + s_fragmentColorKW + " = fragmentColor;" "\n"
"}" "\n";
source.Append(shaderSource, shaderSourceSize);
break;
}
}
@ -710,225 +372,158 @@ NzString NzShaderProgramManager::BuildVertexCode(const NzShaderProgramManagerPar
#endif
NzString source;
source.Reserve(2048); // Le shader peut faire plus, mais cela évite déjà beaucoup de petites allocations
/********************Header********************/
source.Reserve(14 + 24 + 26 + 1);
source += "#version ";
source += NzString::Number(s_glslVersion);
source += "\n\n";
source += "#define FLAG_FLIP_UVS ";
source += (params.flags & nzShaderFlags_FlipUVs) ? '1' : '0';
source += '\n';
source += "#define FLAG_INSTANCING ";
source += (params.flags & nzShaderFlags_Instancing) ? '1' : '0';
source += '\n';
source += '\n';
switch (params.target)
{
case nzShaderTarget_FullscreenQuad:
{
bool uvMapping = (params.fullscreenQuad.alphaMapping || params.fullscreenQuad.diffuseMapping);
char coreVertexShader[] = {
#include <Nazara/Renderer/Shaders/FullscreenQuad/core.vert.h>
};
/********************Entrant********************/
source += s_inKW + " vec2 VertexPosition;" "\n\n";
char compatibilityVertexShader[] = {
#include <Nazara/Renderer/Shaders/FullscreenQuad/compatibility.vert.h>
};
/********************Sortant********************/
if (uvMapping)
source += s_outKW + " vec2 vTexCoord;" "\n\n";
const char* shaderSource = (s_glsl140) ? coreVertexShader : compatibilityVertexShader;
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreVertexShader) : sizeof(compatibilityVertexShader);
/********************Code********************/
source += "void main()" "\n"
"{" "\n"
"\t" "gl_Position = vec4(VertexPosition, 0.0, 1.0);" "\n";
source.Reserve(source.GetCapacity() + 24 + 21 + 26 + 1 + shaderSourceSize);
if (uvMapping)
{
if (params.flags & nzShaderFlags_FlipUVs)
source += "\t" "vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, 0.5 - VertexPosition.y*0.5;" "\n";
else
source += "\t" "vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, (VertexPosition.y + 1.0)*0.5);" "\n";
}
source += "#define ALPHA_MAPPING ";
source += (params.fullscreenQuad.alphaMapping) ? '1' : '0';
source += '\n';
source += "}" "\n";
source += "#define ALPHA_TEST ";
source += (params.fullscreenQuad.alphaTest) ? '1' : '0';
source += '\n';
source += "#define DIFFUSE_MAPPING ";
source += (params.fullscreenQuad.diffuseMapping) ? '1' : '0';
source += '\n';
source += '\n';
source.Append(shaderSource, shaderSourceSize);
break;
}
case nzShaderTarget_Model:
{
bool uvMapping = (params.model.diffuseMapping || params.model.normalMapping || params.model.specularMapping);
char coreVertexShader[] = {
#include <Nazara/Renderer/Shaders/Model/core.vert.h>
};
/********************Entrant********************/
if (params.flags & nzShaderFlags_Instancing)
source += s_inKW + " mat4 InstanceData0;" "\n";
char compatibilityVertexShader[] = {
#include <Nazara/Renderer/Shaders/Model/compatibility.vert.h>
};
source += s_inKW + " vec3 VertexPosition;" "\n";
const char* shaderSource = (s_glsl140) ? coreVertexShader : compatibilityVertexShader;
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreVertexShader) : sizeof(compatibilityVertexShader);
if (params.model.lighting)
{
source += s_inKW + " vec3 VertexNormal;" "\n";
source += s_inKW + " vec3 VertexTangent;" "\n";
}
source.Reserve(source.GetCapacity() + 24 + 21 + 26 + 27 + 19 + 25 + 27 + 27 + 1 + shaderSourceSize);
if (uvMapping)
source += s_inKW + " vec2 VertexTexCoord;" "\n";
source += "#define ALPHA_MAPPING ";
source += (params.model.alphaMapping) ? '1' : '0';
source += '\n';
source += "#define ALPHA_TEST ";
source += (params.model.alphaTest) ? '1' : '0';
source += '\n';
source += "#define DIFFUSE_MAPPING ";
source += (params.model.diffuseMapping) ? '1' : '0';
source += '\n';
source += "#define EMISSIVE_MAPPING ";
source += (params.model.emissiveMapping) ? '1' : '0';
source += '\n';
source += "#define LIGHTING ";
source += (params.model.lighting) ? '1' : '0';
source += '\n';
source += "#define NORMAL_MAPPING ";
source += (params.model.normalMapping) ? '1' : '0';
source += '\n';
source += "#define PARALLAX_MAPPING ";
source += (params.model.parallaxMapping) ? '1' : '0';
source += '\n';
source += "#define SPECULAR_MAPPING ";
source += (params.model.specularMapping) ? '1' : '0';
source += '\n';
source += '\n';
/********************Sortant********************/
if (params.model.lighting)
{
if (params.model.normalMapping)
source += s_outKW + " mat3 vLightToWorld;" "\n";
else
source += s_outKW + " vec3 vNormal;" "\n";
}
if (uvMapping)
source += s_outKW + " vec2 vTexCoord;" "\n";
if (params.model.lighting)
source += s_outKW + " vec3 vWorldPos;" "\n";
if (params.model.lighting || uvMapping)
source += '\n';
/********************Uniformes********************/
if (params.flags & nzShaderFlags_Instancing)
source += "uniform mat4 ViewProjMatrix;" "\n";
else
{
if (params.model.lighting)
source += "uniform mat4 WorldMatrix;" "\n";
source += "uniform mat4 WorldViewProjMatrix;" "\n";
}
source += '\n';
/********************Code********************/
source += "void main()" "\n"
"{" "\n";
if (params.flags & nzShaderFlags_Instancing)
source += "\t" "gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);" "\n";
else
source += "\t" "gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);" "\n";
if (params.model.lighting)
{
if (params.flags & nzShaderFlags_Instancing)
{
if (s_glsl140)
source += "\t" "mat3 rotationMatrix = mat3(InstanceData0);" "\n";
else
source += "\t" "mat3 rotationMatrix = mat3(InstanceData0[0].xyz, InstanceData0[1].xyz, InstanceData0[2].xyz);" "\n";
}
else
{
if (s_glsl140)
source += "\t" "mat3 rotationMatrix = mat3(WorldMatrix);" "\n";
else
source += "\t" "mat3 rotationMatrix = mat3(WorldMatrix[0].xyz, WorldMatrix[1].xyz, WorldMatrix[2].xyz);" "\n";
}
if (params.model.normalMapping)
{
source += "\n"
"\t" "vec3 binormal = cross(VertexNormal, VertexTangent);" "\n"
"\t" "vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);" "\n"
"\t" "vLightToWorld[1] = normalize(rotationMatrix * binormal);" "\n"
"\t" "vLightToWorld[2] = normalize(rotationMatrix * VertexNormal);" "\n\n";
}
else
source += "\t" "vNormal = normalize(rotationMatrix * VertexNormal);" "\n";
}
if (uvMapping)
{
if (params.flags & nzShaderFlags_FlipUVs)
source += "\t" "vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);" "\n";
else
source += "\t" "vTexCoord = VertexTexCoord;" "\n";
}
if (params.model.lighting)
{
if (params.flags & nzShaderFlags_Instancing)
source += "\t" "vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0));" "\n";
else
source += "\t" "vWorldPos = vec3(WorldMatrix * vec4(VertexPosition, 1.0));" "\n";
}
source += "}" "\n";
source.Append(shaderSource, shaderSourceSize);
break;
}
case nzShaderTarget_None:
{
/********************Entrant********************/
if (params.flags & nzShaderFlags_Instancing)
source += s_inKW + " mat4 InstanceData0;" "\n";
char coreVertexShader[] = {
#include <Nazara/Renderer/Shaders/None/core.vert.h>
};
source += s_inKW + " vec3 VertexPosition;" "\n\n";
char compatibilityVertexShader[] = {
#include <Nazara/Renderer/Shaders/None/compatibility.vert.h>
};
/********************Uniformes********************/
if (params.flags & nzShaderFlags_Instancing)
source += "uniform mat4 ViewProjMatrix;" "\n\n";
else
source += "uniform mat4 WorldViewProjMatrix;" "\n\n";
const char* shaderSource = (s_glsl140) ? coreVertexShader : compatibilityVertexShader;
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreVertexShader) : sizeof(compatibilityVertexShader);
/********************Code********************/
source += "void main()" "\n"
"{" "\n";
if (params.flags & nzShaderFlags_Instancing)
source += "\t" "gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);" "\n";
else
source += "\t" "gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);" "\n";
source += "}" "\n";
source.Append(shaderSource, shaderSourceSize);
break;
}
case nzShaderTarget_Sprite:
{
bool uvMapping = (params.fullscreenQuad.alphaMapping || params.fullscreenQuad.diffuseMapping);
char coreVertexShader[] = {
#include <Nazara/Renderer/Shaders/Sprite/core.vert.h>
};
/********************Entrant********************/
if (params.flags & nzShaderFlags_Instancing)
source += s_inKW + " mat4 InstanceData0;" "\n";
char compatibilityVertexShader[] = {
#include <Nazara/Renderer/Shaders/Sprite/compatibility.vert.h>
};
source += s_inKW + " vec3 VertexPosition;" "\n";
const char* shaderSource = (s_glsl140) ? coreVertexShader : compatibilityVertexShader;
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreVertexShader) : sizeof(compatibilityVertexShader);
if (uvMapping)
source += s_inKW + " vec2 VertexTexCoord;" "\n";
source.Reserve(source.GetCapacity() + 24 + 21 + 26 + 1 + shaderSourceSize);
source += "#define ALPHA_MAPPING ";
source += (params.fullscreenQuad.alphaMapping) ? '1' : '0';
source += '\n';
source += "#define ALPHA_TEST ";
source += (params.fullscreenQuad.alphaTest) ? '1' : '0';
source += '\n';
source += "#define DIFFUSE_MAPPING ";
source += (params.fullscreenQuad.diffuseMapping) ? '1' : '0';
source += '\n';
source += '\n';
/********************Sortant********************/
if (uvMapping)
source += s_outKW + " vec2 vTexCoord;" "\n\n";
/********************Uniformes********************/
if (params.flags & nzShaderFlags_Instancing)
source += "uniform mat4 ViewProjMatrix;" "\n";
else
source += "uniform mat4 WorldViewProjMatrix;" "\n";
source += '\n';
/********************Code********************/
source += "void main()" "\n"
"{" "\n";
if (params.flags & nzShaderFlags_Instancing)
source += "\t" "gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);" "\n";
else
source += "\t" "gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);" "\n";
if (uvMapping)
{
if (params.flags & nzShaderFlags_FlipUVs)
source += "\t" "vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);" "\n";
else
source += "\t" "vTexCoord = VertexTexCoord;" "\n";
}
source += "}" "\n";
source.Append(shaderSource, shaderSourceSize);
break;
}
}
@ -948,7 +543,6 @@ NzShaderProgram* NzShaderProgramManager::GenerateProgram(const NzShaderProgramMa
}
NzString fragmentSource = BuildFragmentCode(params);
NazaraDebug("Fragment shader source:\n" + fragmentSource);
if (!program->LoadShader(nzShaderType_Fragment, fragmentSource))
{
NazaraError("Failed to load fragment shader: " + program->GetLog());
@ -957,7 +551,6 @@ NzShaderProgram* NzShaderProgramManager::GenerateProgram(const NzShaderProgramMa
}
NzString vertexSource = BuildVertexCode(params);
NazaraDebug("Vertex shader source:\n" + vertexSource);
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
{
NazaraError("Failed to load vertex shader: " + program->GetLog());
@ -980,11 +573,6 @@ bool NzShaderProgramManager::Initialize()
s_earlyFragmentTest = (s_glslVersion >= 420 || NzOpenGL::IsSupported(nzOpenGLExtension_Shader_ImageLoadStore));
s_glsl140 = (s_glslVersion >= 140);
s_fragmentColorKW = (s_glsl140) ? "RenderTarget0" : "gl_FragColor";
s_inKW = (s_glsl140) ? "in" : "varying";
s_outKW = (s_glsl140) ? "out" : "varying";
s_textureLookupKW = (s_glsl140) ? "texture" : "texture2D";
NzShaderProgramManagerParams params;
params.target = nzShaderTarget_None;
for (unsigned int i = 0; i <= nzShaderFlags_Max; ++i)
@ -1056,8 +644,4 @@ bool NzShaderProgramManager::Initialize()
void NzShaderProgramManager::Uninitialize()
{
s_programs.clear();
s_fragmentColorKW.Clear(false);
s_inKW.Clear(false);
s_outKW.Clear(false);
s_textureLookupKW.Clear(false);
}

View File

@ -0,0 +1,32 @@
#if FLAG_DEFERRED
#error Deferred Shading needs core profile
#endif
/********************Entrant********************/
varying vec2 vTexCoord;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
/********************Fonctions********************/
void main()
{
vec4 fragmentColor = MaterialDiffuse;
#if DIFFUSE_MAPPING
fragmentColor *= texture2D(MaterialDiffuseMap, vTexCoord);
#endif
#if ALPHA_MAPPING
fragmentColor.a *= texture2D(MaterialAlphaMap, vTexCoord).r;
#endif
#if ALPHA_TEST
if (fragmentColor.a < MaterialAlphaThreshold)
discard;
#endif
gl_FragColor = fragmentColor;
}

View File

@ -0,0 +1 @@
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,10,35,101,110,100,105,102,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,97,114,121,105,110,103,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,50,68,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,118,84,101,120,67,111,111,114,100,41,59,10,35,101,110,100,105,102,10,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,50,68,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,118,84,101,120,67,111,111,114,100,41,46,114,59,10,35,101,110,100,105,102,10,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,10,9,105,102,32,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,10,9,9,100,105,115,99,97,114,100,59,10,35,101,110,100,105,102,10,10,9,103,108,95,70,114,97,103,67,111,108,111,114,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,10,125,

View File

@ -0,0 +1,29 @@
#if FLAG_DEFERRED
#error Deferred Shading needs core profile
#endif
/********************Entrant********************/
varying vec2 VertexPosition;
/********************Sortant********************/
varying vec2 vTexCoord;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
/********************Fonctions********************/
void main()
{
gl_Position = vec4(VertexPosition, 0.0, 1.0);
#if ALPHA_MAPPING || DIFFUSE_MAPPING
#if FLAG_FLIP_UVS
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, 0.5 - VertexPosition.y*0.5;
#else
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, (VertexPosition.y + 1.0)*0.5);
#endif // FLAG_FLIP_UVS
#endif
}

View File

@ -0,0 +1 @@
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,10,35,101,110,100,105,102,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,97,114,121,105,110,103,32,118,101,99,50,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,97,114,121,105,110,103,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,48,46,48,44,32,49,46,48,41,59,10,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,32,124,124,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,10,9,35,105,102,32,70,76,65,71,95,70,76,73,80,95,85,86,83,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,48,46,53,32,45,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,42,48,46,53,59,10,9,35,101,108,115,101,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,32,43,32,49,46,48,41,42,48,46,53,41,59,10,9,35,101,110,100,105,102,32,47,47,32,70,76,65,71,95,70,76,73,80,95,85,86,83,10,35,101,110,100,105,102,10,125,10,

View File

@ -0,0 +1,35 @@
/********************Entrant********************/
in vec2 vTexCoord;
/********************Sortant********************/
out vec4 RenderTarget0;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
/********************Fonctions********************/
void main()
{
vec4 fragmentColor = MaterialDiffuse;
#if DIFFUSE_MAPPING
fragmentColor *= texture(MaterialDiffuseMap, vTexCoord);
#endif
#if ALPHA_MAPPING
fragmentColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
#endif
#if ALPHA_TEST
if (fragmentColor.a < MaterialAlphaThreshold)
discard;
#endif
#if FLAG_DEFERRED
RenderTarget0 = vec4(fragmentColor.rgb, 0.0);
#else
RenderTarget0 = fragmentColor;
#endif
}

View File

@ -0,0 +1 @@
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,105,110,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,118,84,101,120,67,111,111,114,100,41,59,10,35,101,110,100,105,102,10,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,118,84,101,120,67,111,111,114,100,41,46,114,59,10,35,101,110,100,105,102,10,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,10,9,105,102,32,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,10,9,9,100,105,115,99,97,114,100,59,10,35,101,110,100,105,102,10,10,35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,114,103,98,44,32,48,46,48,41,59,10,35,101,108,115,101,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,10,35,101,110,100,105,102,10,125,

View File

@ -0,0 +1,29 @@
#if FLAG_DEFERRED
#error Deferred Shading needs core profile
#endif
/********************Entrant********************/
in vec2 VertexPosition;
/********************Sortant********************/
out vec2 vTexCoord;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
/********************Fonctions********************/
void main()
{
gl_Position = vec4(VertexPosition, 0.0, 1.0);
#if ALPHA_MAPPING || DIFFUSE_MAPPING
#if FLAG_FLIP_UVS
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, 0.5 - VertexPosition.y*0.5;
#else
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, (VertexPosition.y + 1.0)*0.5);
#endif // FLAG_FLIP_UVS
#endif
}

View File

@ -0,0 +1 @@
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,10,35,101,110,100,105,102,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,105,110,32,118,101,99,50,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,111,117,116,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,48,46,48,44,32,49,46,48,41,59,10,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,32,124,124,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,10,9,35,105,102,32,70,76,65,71,95,70,76,73,80,95,85,86,83,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,48,46,53,32,45,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,42,48,46,53,59,10,9,35,101,108,115,101,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,32,43,32,49,46,48,41,42,48,46,53,41,59,10,9,35,101,110,100,105,102,32,47,47,32,70,76,65,71,95,70,76,73,80,95,85,86,83,10,35,101,110,100,105,102,10,125,10,

View File

@ -0,0 +1,225 @@
#if FLAG_DEFERRED
#error Deferred Shading needs core profile
#endif
#define LIGHT_DIRECTIONAL 0
#define LIGHT_POINT 1
#define LIGHT_SPOT 2
/********************Entrant********************/
varying mat3 vLightToWorld;
varying vec3 vNormal;
varying vec2 vTexCoord;
varying vec3 vWorldPos;
/********************Uniformes********************/
struct Light
{
int type;
vec4 ambient;
vec4 diffuse;
vec4 specular;
vec4 parameters1;
vec4 parameters2;
vec2 parameters3;
};
uniform vec3 EyePosition;
uniform Light Lights[3];
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialAmbient;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
uniform sampler2D MaterialEmissiveMap;
uniform sampler2D MaterialNormalMap;
uniform float MaterialShininess;
uniform vec4 MaterialSpecular;
uniform sampler2D MaterialSpecularMap;
uniform vec4 SceneAmbient;
/********************Fonctions********************/
void main()
{
vec4 fragmentColor = MaterialDiffuse;
#if DIFFUSE_MAPPING
fragmentColor *= texture2D(MaterialDiffuseMap, vTexCoord);
#endif
#if ALPHA_MAPPING
fragmentColor.a *= texture2D(MaterialAlphaMap, vTexCoord).r;
#endif
#if ALPHA_TEST
if (fragmentColor.a < MaterialAlphaThreshold)
discard;
#endif
#if LIGHTING
vec3 lightColor = vec3(0.0);
#if SPECULAR_MAPPING
vec3 specularColor = vec3(0.0);
#endif
#if NORMAL_MAPPING
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture2D(MaterialNormalMap, vTexCoord)) - 1.0));
#else
vec3 normal = normalize(vNormal);
#endif
if (MaterialShininess > 0.0)
{
vec3 eyeVec = normalize(EyePosition - vWorldPos);
for (int i = 0; i < 3; ++i)
{
if (Lights[i].type == LIGHT_DIRECTIONAL)
{
vec3 lightDir = normalize(-Lights[i].parameters1.xyz);
// Ambient
lightColor += Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightColor += lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
#if SPECULAR_MAPPING
specularColor += specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#else
lightColor += specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#endif
}
else if (Lights[i].type == LIGHT_POINT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
lightDir = normalize(lightDir);
// Ambient
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
#if SPECULAR_MAPPING
specularColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#else
lightColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#endif
}
else if (Lights[i].type == LIGHT_SPOT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
lightDir = normalize(lightDir);
// Ambient
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Modification de l'atténuation
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
float outerAngle = Lights[i].parameters3.y;
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
float lambert = max(dot(normal, lightDir), 0.0);
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
// Diffuse
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
#if SPECULAR_MAPPING
specularColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#else
lightColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#endif
}
}
}
else
{
for (int i = 0; i < 3; ++i)
{
if (Lights[i].type == LIGHT_DIRECTIONAL)
{
vec3 lightDir = normalize(-Lights[i].parameters1.xyz);
// Ambient
lightColor += Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightColor += lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
}
else if (Lights[i].type == LIGHT_POINT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
lightDir = normalize(lightDir);
// Ambient
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
}
else if (Lights[i].type == LIGHT_SPOT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
lightDir = normalize(lightDir);
// Ambient
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Modification de l'atténuation
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
float outerAngle = Lights[i].parameters3.y;
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
float lambert = max(dot(normal, lightDir), 0.0);
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
// Diffuse
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
}
}
}
fragmentColor *= vec4(lightColor, 1.0);
#if SPECULAR_MAPPING
fragmentColor *= vec4(specularColor * texture2D(MaterialSpecularMap, vTexCoord).rgb, 1.0); // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
#endif
#if EMISSIVE_MAPPING
#if SPECULAR_MAPPING
float lightIntensity = dot(lightColor + specularColor, vec3(0.3, 0.59, 0.11));
#else
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
#endif // SPECULAR_MAPPING
vec3 emissionColor = MaterialDiffuse.rgb * texture2D(MaterialEmissiveMap, vTexCoord).rgb;
gl_FragColor = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);
#else
gl_FragColor = fragmentColor;
#endif // EMISSIVE_MAPPING
#else
gl_FragColor = fragmentColor;
#endif // LIGHTING
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,60 @@
/********************Entrant********************/
varying mat4 InstanceData0;
varying vec3 VertexPosition;
varying vec3 VertexNormal;
varying vec3 VertexTangent;
varying vec2 VertexTexCoord;
/********************Sortant********************/
varying mat3 vLightToWorld;
varying vec3 vNormal;
varying vec2 vTexCoord;
varying vec3 vWorldPos;
/********************Uniformes********************/
uniform mat4 ViewProjMatrix;
uniform mat4 WorldMatrix;
uniform mat4 WorldViewProjMatrix;
/********************Fonctions********************/
void main()
{
#if FLAG_INSTANCING
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
#else
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
#endif
#if LIGHTING
#if FLAG_INSTANCING
mat3 rotationMatrix = mat3(InstanceData0[0].xyz, InstanceData0[1].xyz, InstanceData0[2].xyz);
#else
mat3 rotationMatrix = mat3(WorldMatrix[0].xyz, WorldMatrix[1].xyz, WorldMatrix[2].xyz);
#endif
#if NORMAL_MAPPING
vec3 binormal = cross(VertexNormal, VertexTangent);
vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);
vLightToWorld[1] = normalize(rotationMatrix * binormal);
vLightToWorld[2] = normalize(rotationMatrix * VertexNormal);
#else
vNormal = normalize(rotationMatrix * VertexNormal);
#endif
#endif
#if ALPHA_MAPPING || DIFFUSE_MAPPING || EMISSIVE_MAPPING || NORMAL_MAPPING || PARALLAX_MAPPING || SPECULAR_MAPPING
#if FLAG_FLIP_UVS
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
#else
vTexCoord = VertexTexCoord;
#endif
#endif
#if LIGHTING
#if FLAG_INSTANCING
vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0));
#else
vWorldPos = vec3(WorldMatrix * vec4(VertexPosition, 1.0));
#endif
#endif
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,284 @@
#define LIGHT_DIRECTIONAL 0
#define LIGHT_POINT 1
#define LIGHT_SPOT 2
/********************Entrant********************/
in mat3 vLightToWorld;
in vec3 vNormal;
in vec2 vTexCoord;
in vec3 vWorldPos;
/********************Sortant********************/
out vec4 RenderTarget0;
out vec4 RenderTarget1;
out vec4 RenderTarget2;
/********************Uniformes********************/
struct Light
{
int type;
vec4 ambient;
vec4 diffuse;
vec4 specular;
vec4 parameters1;
vec4 parameters2;
vec2 parameters3;
};
uniform vec3 EyePosition;
uniform Light Lights[3];
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialAmbient;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
uniform sampler2D MaterialEmissiveMap;
uniform sampler2D MaterialNormalMap;
uniform float MaterialShininess;
uniform vec4 MaterialSpecular;
uniform sampler2D MaterialSpecularMap;
uniform vec4 SceneAmbient;
/********************Fonctions********************/
void main()
{
vec4 fragmentColor = MaterialDiffuse;
#if DIFFUSE_MAPPING
fragmentColor *= texture(MaterialDiffuseMap, vTexCoord);
#endif
#if FLAG_DEFERRED
#if ALPHA_TEST
#if ALPHA_MAPPING // Inutile de faire de l'alpha-mapping sans alpha-test en Deferred (l'alpha n'est pas sauvegardé)
fragmentColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
#endif
if (fragmentColor.a < MaterialAlphaThreshold)
discard;
#endif // ALPHA_TEST
#if LIGHTING
#if NORMAL_MAPPING
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, vTexCoord)) - 1.0));
#else
vec3 normal = normalize(vNormal);
#endif // NORMAL_MAPPING
vec3 specular = MaterialSpecular.rgb;
#if SPECULAR_MAPPING
specular *= texture(MaterialSpecularMap, vTexCoord).rgb;
#endif
/*
Texture0: Diffuse Color + Flags
Texture1: Normal map + Empty
Texture2: Specular value + Shininess
Texture3: Depth texture
*/
RenderTarget0 = vec4(fragmentColor.rgb, 1.0);
RenderTarget1 = vec4(normal, 0.0);
RenderTarget2 = vec4(specular, MaterialShininess);
#else // LIGHTING
RenderTarget0 = vec4(fragmentColor.rgb, 0.0);
#endif
#else // FLAG_DEFERRED
#if ALPHA_MAPPING
fragmentColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
#endif
#if ALPHA_TEST
if (fragmentColor.a < MaterialAlphaThreshold)
discard;
#endif
#if LIGHTING
vec3 lightColor = vec3(0.0);
#if SPECULAR_MAPPING
vec3 specularColor = vec3(0.0);
#endif
#if NORMAL_MAPPING
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, vTexCoord)) - 1.0));
#else
vec3 normal = normalize(vNormal);
#endif
if (MaterialShininess > 0.0)
{
vec3 eyeVec = normalize(EyePosition - vWorldPos);
for (int i = 0; i < 3; ++i)
{
switch (Lights[i].type)
{
case LIGHT_DIRECTIONAL:
{
vec3 lightDir = normalize(-Lights[i].parameters1.xyz);
// Ambient
lightColor += Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightColor += lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
#if SPECULAR_MAPPING
specularColor += specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#else
lightColor += specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#endif
break;
}
case LIGHT_POINT:
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
lightDir = normalize(lightDir);
// Ambient
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
#if SPECULAR_MAPPING
specularColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#else
lightColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#endif
break;
}
case LIGHT_SPOT:
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
lightDir = normalize(lightDir);
// Ambient
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Modification de l'atténuation
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
float outerAngle = Lights[i].parameters3.y;
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
float lambert = max(dot(normal, lightDir), 0.0);
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
// Diffuse
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
#if SPECULAR_MAPPING
specularColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#else
lightColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
#endif
break;
}
default:
break;
}
}
}
else
{
for (int i = 0; i < 3; ++i)
{
switch (Lights[i].type)
{
case LIGHT_DIRECTIONAL:
{
vec3 lightDir = normalize(-Lights[i].parameters1.xyz);
// Ambient
lightColor += Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightColor += lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
break;
}
case LIGHT_POINT:
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
lightDir = normalize(lightDir);
// Ambient
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
break;
}
case LIGHT_SPOT:
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
lightDir = normalize(lightDir);
// Ambient
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Modification de l'atténuation
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
float outerAngle = Lights[i].parameters3.y;
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
float lambert = max(dot(normal, lightDir), 0.0);
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
// Diffuse
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
break;
}
default:
break;
}
}
}
fragmentColor *= vec4(lightColor, 1.0);
#if SPECULAR_MAPPING
fragmentColor *= vec4(specularColor * texture(MaterialSpecularMap, vTexCoord).rgb, 1.0); // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
#endif
#if EMISSIVE_MAPPING
#if SPECULAR_MAPPING
float lightIntensity = dot(lightColor + specularColor, vec3(0.3, 0.59, 0.11));
#else
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
#endif // SPECULAR_MAPPING
vec3 emissionColor = MaterialDiffuse.rgb * texture(MaterialEmissiveMap, vTexCoord).rgb;
RenderTarget0 = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);
#else
RenderTarget0 = fragmentColor;
#endif // EMISSIVE_MAPPING
#else
RenderTarget0 = fragmentColor;
#endif // LIGHTING
#endif // FLAG_DEFERRED
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,60 @@
/********************Entrant********************/
in mat4 InstanceData0;
in vec3 VertexPosition;
in vec3 VertexNormal;
in vec3 VertexTangent;
in vec2 VertexTexCoord;
/********************Sortant********************/
out mat3 vLightToWorld;
out vec3 vNormal;
out vec2 vTexCoord;
out vec3 vWorldPos;
/********************Uniformes********************/
uniform mat4 ViewProjMatrix;
uniform mat4 WorldMatrix;
uniform mat4 WorldViewProjMatrix;
/********************Fonctions********************/
void main()
{
#if FLAG_INSTANCING
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
#else
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
#endif
#if LIGHTING
#if FLAG_INSTANCING
mat3 rotationMatrix = mat3(InstanceData0);
#else
mat3 rotationMatrix = mat3(WorldMatrix);
#endif
#if NORMAL_MAPPING
vec3 binormal = cross(VertexNormal, VertexTangent);
vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);
vLightToWorld[1] = normalize(rotationMatrix * binormal);
vLightToWorld[2] = normalize(rotationMatrix * VertexNormal);
#else
vNormal = normalize(rotationMatrix * VertexNormal);
#endif
#endif
#if ALPHA_MAPPING || DIFFUSE_MAPPING || EMISSIVE_MAPPING || NORMAL_MAPPING || PARALLAX_MAPPING || SPECULAR_MAPPING
#if FLAG_FLIP_UVS
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
#else
vTexCoord = VertexTexCoord;
#endif
#endif
#if LIGHTING
#if FLAG_INSTANCING
vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0));
#else
vWorldPos = vec3(WorldMatrix * vec4(VertexPosition, 1.0));
#endif
#endif
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,18 @@
#if FLAG_DEFERRED
#error Deferred Shading needs core profile
#endif
/********************Entrant********************/
varying vec2 vTexCoord;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
/********************Fonctions********************/
void main()
{
gl_FragColor = MaterialDiffuse;
}

View File

@ -0,0 +1 @@
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,10,35,101,110,100,105,102,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,97,114,121,105,110,103,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,103,108,95,70,114,97,103,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,125,

View File

@ -0,0 +1,17 @@
/********************Entrant********************/
varying mat4 InstanceData0;
varying vec3 VertexPosition;
/********************Uniformes********************/
uniform mat4 ViewProjMatrix;
uniform mat4 WorldViewProjMatrix;
/********************Fonctions********************/
void main()
{
#if FLAG_INSTANCING
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
#else
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
#endif
}

View File

@ -0,0 +1 @@
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,97,114,121,105,110,103,32,109,97,116,52,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,10,118,97,114,121,105,110,103,32,118,101,99,51,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,109,97,116,52,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,35,101,108,115,101,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,35,101,110,100,105,102,10,125,10,

View File

@ -0,0 +1,21 @@
/********************Entrant********************/
in vec2 vTexCoord;
/********************Sortant********************/
out vec4 RenderTarget0;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
/********************Fonctions********************/
void main()
{
#if FLAG_DEFERRED
RenderTarget0 = vec4(MaterialDiffuse.rgb, 0.0);
#else
RenderTarget0 = MaterialDiffuse;
#endif
}

View File

@ -0,0 +1 @@
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,105,110,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,46,114,103,98,44,32,48,46,48,41,59,10,35,101,108,115,101,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,35,101,110,100,105,102,10,125,

View File

@ -0,0 +1,17 @@
/********************Entrant********************/
in mat4 InstanceData0;
in vec3 VertexPosition;
/********************Uniformes********************/
uniform mat4 ViewProjMatrix;
uniform mat4 WorldViewProjMatrix;
/********************Fonctions********************/
void main()
{
#if FLAG_INSTANCING
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
#else
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
#endif
}

View File

@ -0,0 +1 @@
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,105,110,32,109,97,116,52,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,10,105,110,32,118,101,99,51,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,109,97,116,52,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,35,101,108,115,101,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,35,101,110,100,105,102,10,125,10,

View File

@ -0,0 +1,32 @@
#if FLAG_DEFERRED
#error Deferred Shading needs core profile
#endif
/********************Entrant********************/
varying vec2 vTexCoord;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
/********************Fonctions********************/
void main()
{
vec4 fragmentColor = MaterialDiffuse;
#if DIFFUSE_MAPPING
fragmentColor *= texture2D(MaterialDiffuseMap, vTexCoord);
#endif
#if ALPHA_MAPPING
fragmentColor.a *= texture2D(MaterialAlphaMap, vTexCoord).r;
#endif
#if ALPHA_TEST
if (fragmentColor.a < MaterialAlphaThreshold)
discard;
#endif
gl_FragColor = fragmentColor;
}

View File

@ -0,0 +1 @@
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,10,35,101,110,100,105,102,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,97,114,121,105,110,103,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,50,68,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,118,84,101,120,67,111,111,114,100,41,59,10,35,101,110,100,105,102,10,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,50,68,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,118,84,101,120,67,111,111,114,100,41,46,114,59,10,35,101,110,100,105,102,10,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,10,9,105,102,32,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,10,9,9,100,105,115,99,97,114,100,59,10,35,101,110,100,105,102,10,10,9,103,108,95,70,114,97,103,67,111,108,111,114,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,10,125,

View File

@ -0,0 +1,29 @@
#if FLAG_DEFERRED
#error Deferred Shading needs core profile
#endif
/********************Entrant********************/
varying vec2 VertexPosition;
/********************Sortant********************/
varying vec2 vTexCoord;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
/********************Fonctions********************/
void main()
{
gl_Position = vec4(VertexPosition, 0.0, 1.0);
#if ALPHA_MAPPING || DIFFUSE_MAPPING
#if FLAG_FLIP_UVS
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, 0.5 - VertexPosition.y*0.5;
#else
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, (VertexPosition.y + 1.0)*0.5);
#endif // FLAG_FLIP_UVS
#endif
}

View File

@ -0,0 +1 @@
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,10,35,101,110,100,105,102,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,97,114,121,105,110,103,32,118,101,99,50,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,97,114,121,105,110,103,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,48,46,48,44,32,49,46,48,41,59,10,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,32,124,124,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,10,9,35,105,102,32,70,76,65,71,95,70,76,73,80,95,85,86,83,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,48,46,53,32,45,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,42,48,46,53,59,10,9,35,101,108,115,101,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,32,43,32,49,46,48,41,42,48,46,53,41,59,10,9,35,101,110,100,105,102,32,47,47,32,70,76,65,71,95,70,76,73,80,95,85,86,83,10,35,101,110,100,105,102,10,125,10,

View File

@ -0,0 +1,35 @@
/********************Entrant********************/
in vec2 vTexCoord;
/********************Sortant********************/
out vec4 RenderTarget0;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
/********************Fonctions********************/
void main()
{
vec4 fragmentColor = MaterialDiffuse;
#if DIFFUSE_MAPPING
fragmentColor *= texture(MaterialDiffuseMap, vTexCoord);
#endif
#if ALPHA_MAPPING
fragmentColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
#endif
#if ALPHA_TEST
if (fragmentColor.a < MaterialAlphaThreshold)
discard;
#endif
#if FLAG_DEFERRED
RenderTarget0 = vec4(fragmentColor.rgb, 0.0);
#else
RenderTarget0 = fragmentColor;
#endif
}

View File

@ -0,0 +1 @@
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,105,110,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,118,84,101,120,67,111,111,114,100,41,59,10,35,101,110,100,105,102,10,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,118,84,101,120,67,111,111,114,100,41,46,114,59,10,35,101,110,100,105,102,10,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,10,9,105,102,32,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,10,9,9,100,105,115,99,97,114,100,59,10,35,101,110,100,105,102,10,10,35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,114,103,98,44,32,48,46,48,41,59,10,35,101,108,115,101,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,10,35,101,110,100,105,102,10,125,

View File

@ -0,0 +1,29 @@
#if FLAG_DEFERRED
#error Deferred Shading needs core profile
#endif
/********************Entrant********************/
in vec2 VertexPosition;
/********************Sortant********************/
out vec2 vTexCoord;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
/********************Fonctions********************/
void main()
{
gl_Position = vec4(VertexPosition, 0.0, 1.0);
#if ALPHA_MAPPING || DIFFUSE_MAPPING
#if FLAG_FLIP_UVS
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, 0.5 - VertexPosition.y*0.5;
#else
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, (VertexPosition.y + 1.0)*0.5);
#endif // FLAG_FLIP_UVS
#endif
}

View File

@ -0,0 +1 @@
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,10,35,101,110,100,105,102,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,105,110,32,118,101,99,50,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,111,117,116,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,48,46,48,44,32,49,46,48,41,59,10,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,32,124,124,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,10,9,35,105,102,32,70,76,65,71,95,70,76,73,80,95,85,86,83,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,48,46,53,32,45,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,42,48,46,53,59,10,9,35,101,108,115,101,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,32,43,32,49,46,48,41,42,48,46,53,41,59,10,9,35,101,110,100,105,102,32,47,47,32,70,76,65,71,95,70,76,73,80,95,85,86,83,10,35,101,110,100,105,102,10,125,10,