Merge branch 'OpenGL3-upgrade' into NDK

Conflicts:
	src/Nazara/Graphics/SkyboxBackground.cpp
	src/Nazara/Renderer/RenderTexture.cpp
	src/Nazara/Renderer/Renderer.cpp

Former-commit-id: e8914d4e32a689b7df365dca15a438f10722530c
This commit is contained in:
Lynix
2015-09-24 21:35:43 +02:00
30 changed files with 185 additions and 1136 deletions

View File

@@ -8,27 +8,16 @@
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Graphics/Debug.hpp>
NzAbstractRenderTechnique::NzAbstractRenderTechnique()
NzAbstractRenderTechnique::NzAbstractRenderTechnique() :
m_instancingEnabled(true)
{
#ifdef NAZARA_DEBUG
if (!NzRenderer::IsInitialized())
{
NazaraError("NazaraRenderer is not initialized");
return;
}
#endif
m_instancingEnabled = NzRenderer::HasCapability(nzRendererCap_Instancing);
}
NzAbstractRenderTechnique::~NzAbstractRenderTechnique() = default;
void NzAbstractRenderTechnique::EnableInstancing(bool instancing)
{
if (NzRenderer::HasCapability(nzRendererCap_Instancing))
m_instancingEnabled = instancing;
else if (instancing)
NazaraError("NazaraRenderer does not support instancing");
m_instancingEnabled = instancing;
}
NzString NzAbstractRenderTechnique::GetName() const

View File

@@ -395,12 +395,8 @@ void NzDeferredRenderTechnique::SetPass(nzRenderPassType relativeTo, int positio
bool NzDeferredRenderTechnique::IsSupported()
{
// On ne va pas s'embêter à écrire un Deferred Renderer qui ne passe pas par le MRT, ce serait trop lent pour servir...
return NzOpenGL::GetGLSLVersion() >= 140 && // On ne va pas s'embêter non plus avec le mode de compatibilité
NzRenderer::HasCapability(nzRendererCap_RenderTexture) &&
NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets) &&
NzRenderer::GetMaxColorAttachments() >= 4 &&
NzRenderer::GetMaxRenderTargets() >= 4;
// Depuis qu'OpenGL 3.3 est la version minimale, le Renderer supporte ce qu'il faut, mais par acquis de conscience...
return NzRenderer::GetMaxColorAttachments() >= 4 && NzRenderer::GetMaxRenderTargets() >= 4;
}
bool NzDeferredRenderTechnique::Resize(const NzVector2ui& dimensions) const

View File

@@ -16,21 +16,22 @@
namespace
{
const nzUInt8 r_coreFragmentShader[] = {
const nzUInt8 r_basicFragmentShader[] = {
#include <Nazara/Graphics/Resources/Shaders/Basic/core.frag.h>
};
const nzUInt8 r_coreVertexShader[] = {
const nzUInt8 r_basicVertexShader[] = {
#include <Nazara/Graphics/Resources/Shaders/Basic/core.vert.h>
};
const nzUInt8 r_compatibilityFragmentShader[] = {
#include <Nazara/Graphics/Resources/Shaders/Basic/compatibility.frag.h>
const nzUInt8 r_phongLightingFragmentShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h>
};
const nzUInt8 r_compatibilityVertexShader[] = {
#include <Nazara/Graphics/Resources/Shaders/Basic/compatibility.vert.h>
const nzUInt8 r_phongLightingVertexShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h>
};
}
bool NzMaterialParams::IsValid() const
@@ -722,24 +723,12 @@ bool NzMaterial::Initialize()
return false;
}
bool glsl140 = (NzOpenGL::GetGLSLVersion() >= 140);
// Basic shader
{
NzUberShaderPreprocessorRef uberShader = NzUberShaderPreprocessor::New();
NzString fragmentShader;
NzString vertexShader;
if (glsl140)
{
fragmentShader.Set(reinterpret_cast<const char*>(r_coreFragmentShader), sizeof(r_coreFragmentShader));
vertexShader.Set(reinterpret_cast<const char*>(r_coreVertexShader), sizeof(r_coreVertexShader));
}
else
{
fragmentShader.Set(reinterpret_cast<const char*>(r_compatibilityFragmentShader), sizeof(r_compatibilityFragmentShader));
vertexShader.Set(reinterpret_cast<const char*>(r_compatibilityVertexShader), sizeof(r_compatibilityVertexShader));
}
NzString fragmentShader(reinterpret_cast<const char*>(r_basicFragmentShader), sizeof(r_basicFragmentShader));
NzString vertexShader(reinterpret_cast<const char*>(r_basicVertexShader), sizeof(r_basicVertexShader));
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_TEXTUREOVERLAY ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING");
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_BILLBOARD FLAG_INSTANCING FLAG_VERTEXCOLOR TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");
@@ -751,34 +740,8 @@ bool NzMaterial::Initialize()
{
NzUberShaderPreprocessorRef uberShader = NzUberShaderPreprocessor::New();
NzString fragmentShader;
NzString vertexShader;
if (glsl140)
{
const nzUInt8 coreFragmentShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h>
};
const nzUInt8 coreVertexShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h>
};
fragmentShader.Set(reinterpret_cast<const char*>(coreFragmentShader), sizeof(coreFragmentShader));
vertexShader.Set(reinterpret_cast<const char*>(coreVertexShader), sizeof(coreVertexShader));
}
else
{
const nzUInt8 compatibilityFragmentShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/compatibility.frag.h>
};
const nzUInt8 compatibilityVertexShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/compatibility.vert.h>
};
fragmentShader.Set(reinterpret_cast<const char*>(compatibilityFragmentShader), sizeof(compatibilityFragmentShader));
vertexShader.Set(reinterpret_cast<const char*>(compatibilityVertexShader), sizeof(compatibilityVertexShader));
}
NzString fragmentShader(reinterpret_cast<const char*>(r_phongLightingFragmentShader), sizeof(r_phongLightingFragmentShader));
NzString vertexShader(reinterpret_cast<const char*>(r_phongLightingVertexShader), sizeof(r_phongLightingVertexShader));
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_DEFERRED FLAG_TEXTUREOVERLAY ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING EMISSIVE_MAPPING LIGHTING NORMAL_MAPPING PARALLAX_MAPPING SPECULAR_MAPPING");
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_BILLBOARD FLAG_DEFERRED FLAG_INSTANCING FLAG_VERTEXCOLOR COMPUTE_TBNMATRIX LIGHTING PARALLAX_MAPPING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");

View File

@@ -1,37 +0,0 @@
/********************Entrant********************/
varying vec2 vTexCoord;
varying vec4 vColor;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
uniform vec2 InvTargetSize;
/********************Fonctions********************/
void main()
{
vec4 fragmentColor = MaterialDiffuse; * vColor;
#if AUTO_TEXCOORDS
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
#else
vec2 texCoord = vTexCoord;
#endif
#if DIFFUSE_MAPPING
fragmentColor *= texture2D(MaterialDiffuseMap, texCoord);
#endif
#if ALPHA_MAPPING
fragmentColor.a *= texture2D(MaterialAlphaMap, texCoord).r;
#endif
#if ALPHA_TEST
if (fragmentColor.a < MaterialAlphaThreshold)
discard;
#endif
gl_FragColor = fragmentColor;
}

View File

@@ -1 +0,0 @@
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,13,10,118,97,114,121,105,110,103,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,118,97,114,121,105,110,103,32,118,101,99,52,32,118,67,111,108,111,114,59,13,10,13,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,13,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,13,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,13,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,13,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,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,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,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,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,32,42,32,118,67,111,108,111,114,59,13,10,13,10,35,105,102,32,65,85,84,79,95,84,69,88,67,79,79,82,68,83,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,35,101,108,115,101,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,118,84,101,120,67,111,111,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,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,116,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,13,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,116,101,120,67,111,111,114,100,41,46,114,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,13,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,13,10,9,9,100,105,115,99,97,114,100,59,13,10,35,101,110,100,105,102,13,10,13,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,13,10,125,

View File

@@ -1,99 +0,0 @@
/********************Entrant********************/
#if FLAG_BILLBOARD
varying vec3 InstanceData0; // center
varying vec4 InstanceData1; // size | sin cos
varying vec4 InstanceData2; // color
#else
varying mat4 InstanceData0;
#endif
varying vec4 VertexColor;
varying vec3 VertexPosition;
varying vec2 VertexTexCoord;
/********************Sortant********************/
varying vec2 vTexCoord;
varying vec4 vColor;
/********************Uniformes********************/
uniform float VertexDepth;
uniform mat4 ViewProjMatrix;
uniform mat4 WorldViewProjMatrix;
/********************Fonctions********************/
void main()
{
#if FLAG_VERTEXCOLOR
vec4 color = VertexColor;
#else
vec4 color = vec4(1.0);
#endif
vec2 texCoords;
#if FLAG_BILLBOARD
#if FLAG_INSTANCING
vec3 billboardCenter = InstanceData0;
vec2 billboardSize = InstanceData1.xy;
vec2 billboardSinCos = InstanceData1.zw;
vec4 billboardColor = InstanceData2;
vec2 rotatedPosition;
rotatedPosition.x = VertexPosition.x*billboardSinCos.y - VertexPosition.y*billboardSinCos.x;
rotatedPosition.y = VertexPosition.y*billboardSinCos.y + VertexPosition.x*billboardSinCos.x;
rotatedPosition *= billboardSize;
vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]);
vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]);
vec3 vertexPos = billboardCenter + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y;
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
color = billboardColor;
texCoords = VertexPosition.xy + vec2(0.5, 0.5);
#else
vec2 billboardCorner = VertexTexCoord - vec2(0.5, 0.5);
vec2 billboardSize = VertexUserdata0.xy;
vec2 billboardSinCos = VertexUserdata0.zw;
vec2 rotatedPosition;
rotatedPosition.x = billboardCorner.x*billboardSinCos.y - billboardCorner.y*billboardSinCos.x;
rotatedPosition.y = billboardCorner.y*billboardSinCos.y + billboardCorner.x*billboardSinCos.x;
rotatedPosition *= billboardSize;
vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]);
vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]);
vec3 vertexPos = VertexPosition + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y;
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
texCoords = VertexTexCoord;
#endif
#else
#if FLAG_INSTANCING
#if TRANSFORM
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
#else
#if UNIFORM_VERTEX_DEPTH
gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0);
#else
gl_Position = InstanceData0 * vec4(VertexPosition, 1.0);
#endif
#endif
#else
#if TRANSFORM
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
#else
#if UNIFORM_VERTEX_DEPTH
gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0);
#else
gl_Position = vec4(VertexPosition, 1.0);
#endif
#endif
#endif
texCoords = VertexTexCoord;
#endif
vColor = color;
#if TEXTURE_MAPPING
vTexCoord = vec2(texCoords);
#endif
}

File diff suppressed because one or more lines are too long

View File

@@ -1,237 +0,0 @@
#if FLAG_DEFERRED
#error Deferred Shading is not supported by compatibility shaders
#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;
varying vec4 vColor;
/********************Uniformes********************/
struct Light
{
int type;
vec4 color;
vec2 factors;
vec4 parameters1;
vec4 parameters2;
vec2 parameters3;
};
// Lumières
uniform Light Lights[3];
// Matériau
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;
// Autres
uniform vec3 EyePosition;
uniform vec4 SceneAmbient;
/********************Fonctions********************/
void main()
{
vec4 diffuseColor = MaterialDiffuse * vColor;
#if AUTO_TEXCOORDS
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
#else
vec2 texCoord = vTexCoord;
#endif
#if DIFFUSE_MAPPING
diffuseColor *= texture(MaterialDiffuseMap, texCoord);
#endif
#if ALPHA_MAPPING
diffuseColor.a *= texture(MaterialAlphaMap, texCoord).r;
#endif
#if ALPHA_TEST
if (diffuseColor.a < MaterialAlphaThreshold)
discard;
#endif
#if LIGHTING
vec3 lightAmbient = vec3(0.0);
vec3 lightDiffuse = vec3(0.0);
vec3 lightSpecular = vec3(0.0);
#if NORMAL_MAPPING
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, texCoord)) - 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 = -Lights[i].parameters1.xyz;
// Ambient
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, MaterialShininess);
lightSpecular += specularFactor * Lights[i].color.rgb;
}
else if (Lights[i].type == LIGHT_POINT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float lightDirLength = length(lightDir);
lightDir /= lightDirLength; // Normalisation
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
// Ambient
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, MaterialShininess);
lightSpecular += att * specularFactor * Lights[i].color.rgb;
}
else if (Lights[i].type == LIGHT_SPOT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float lightDirLength = length(lightDir);
lightDir /= lightDirLength; // Normalisation
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
// Ambient
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
// Modification de l'atténuation pour gérer le spot
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
float outerAngle = Lights[i].parameters3.y;
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, MaterialShininess);
lightSpecular += att * specularFactor * Lights[i].color.rgb;
}
}
}
else
{
for (int i = 0; i < 3; ++i)
{
if (Lights[i].type == LIGHT_DIRECTIONAL)
{
vec3 lightDir = -Lights[i].parameters1.xyz;
// Ambient
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
}
else if (Lights[i].type == LIGHT_POINT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float lightDirLength = length(lightDir);
lightDir /= lightDirLength; // Normalisation
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
// Ambient
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
}
else if (Lights[i].type == LIGHT_SPOT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float lightDirLength = length(lightDir);
lightDir /= lightDirLength; // Normalisation
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
// Ambient
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
// Modification de l'atténuation pour gérer le spot
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
float outerAngle = Lights[i].parameters3.y;
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
}
}
}
lightSpecular *= MaterialSpecular.rgb;
#if SPECULAR_MAPPING
lightSpecular *= texture(MaterialSpecularMap, texCoord).rgb; // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
#endif
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
vec4 fragmentColor = vec4(lightColor, 1.0) * diffuseColor;
#if EMISSIVE_MAPPING
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
vec3 emissionColor = MaterialDiffuse.rgb * texture(MaterialEmissiveMap, texCoord).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 = diffuseColor;
#endif // LIGHTING
}

File diff suppressed because one or more lines are too long

View File

@@ -1,135 +0,0 @@
/********************Entrant********************/
#if FLAG_BILLBOARD
varying vec3 InstanceData0; // center
varying vec4 InstanceData1; // size | sin cos
varying vec4 InstanceData2; // color
#else
varying mat4 InstanceData0;
#endif
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;
varying vec4 vColor;
/********************Uniformes********************/
uniform float VertexDepth;
uniform mat4 ViewProjMatrix;
uniform mat4 WorldMatrix;
uniform mat4 WorldViewProjMatrix;
/********************Fonctions********************/
void main()
{
#if FLAG_VERTEXCOLOR
vec4 color = VertexColor;
#else
vec4 color = vec4(1.0);
#endif
vec2 texCoords;
#if FLAG_BILLBOARD
#if FLAG_INSTANCING
vec3 billboardCenter = InstanceData0;
vec2 billboardSize = InstanceData1.xy;
vec2 billboardSinCos = InstanceData1.zw;
vec4 billboardColor = InstanceData2;
vec2 rotatedPosition;
rotatedPosition.x = VertexPosition.x*billboardSinCos.y - VertexPosition.y*billboardSinCos.x;
rotatedPosition.y = VertexPosition.y*billboardSinCos.y + VertexPosition.x*billboardSinCos.x;
rotatedPosition *= billboardSize;
vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]);
vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]);
vec3 vertexPos = billboardCenter + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y;
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
color = billboardColor;
texCoords = VertexPosition.xy + vec2(0.5, 0.5);
#else
vec2 billboardCorner = VertexTexCoord - vec2(0.5, 0.5);
vec2 billboardSize = VertexUserdata0.xy;
vec2 billboardSinCos = VertexUserdata0.zw;
vec2 rotatedPosition;
rotatedPosition.x = billboardCorner.x*billboardSinCos.y - billboardCorner.y*billboardSinCos.x;
rotatedPosition.y = billboardCorner.y*billboardSinCos.y + billboardCorner.x*billboardSinCos.x;
rotatedPosition *= billboardSize;
vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]);
vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]);
vec3 vertexPos = VertexPosition + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y;
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
texCoords = VertexTexCoord;
#endif
#else
#if FLAG_INSTANCING
#if TRANSFORM
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
#else
#if UNIFORM_VERTEX_DEPTH
gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0);
#else
gl_Position = InstanceData0 * vec4(VertexPosition, 1.0);
#endif
#endif
#else
#if TRANSFORM
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
#else
#if UNIFORM_VERTEX_DEPTH
gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0);
#else
gl_Position = vec4(VertexPosition, 1.0);
#endif
#endif
#endif
texCoords = VertexTexCoord;
#endif
vColor = color;
#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 TEXTURE_MAPPING
vTexCoord = vec2(texCoords);
#endif
#if LIGHTING && PARALLAX_MAPPING
vViewDir = EyePosition - VertexPosition;
vViewDir *= vLightToWorld;
#endif
#if LIGHTING && !FLAG_DEFERRED
#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

@@ -156,4 +156,4 @@ void NzSkyboxBackground::Uninitialize()
s_indexBuffer.Reset();
s_shader.Reset();
s_vertexBuffer.Reset();
}
}