Graphics: Separate pipeline state from Material into a new class, MaterialPipeline

This allows much more efficient batching, along with pipeline reusage and preparation for the Vulkan API


Former-commit-id: fd2de2f0e9612ea275ee69c5578c68e7169cd05b [formerly 53bd8a5ed5695311b7543ad717df63f93fad2da6] [formerly 171740929652ac9fe30e84983709388859cedd6b [formerly 25096a76678f1052e76f67d26b458077a0632cc3]]
Former-commit-id: 7978dbeb87af2eac9e5501a97afa83849648bf6e [formerly 81b6cce1ee81a2ca8873d3c70d468b2c71510c95]
Former-commit-id: 6663e2721c3f79d5f1e3f33c6183174378b502f4
This commit is contained in:
Lynix
2016-08-05 22:09:39 +02:00
parent 3cf4cd3d53
commit ac25df0126
31 changed files with 2249 additions and 1422 deletions

View File

@@ -132,7 +132,7 @@ void main()
vec2 texCoord = vTexCoord;
#endif
#if LIGHTING && PARALLAX_MAPPING
#if PARALLAX_MAPPING
float height = texture(MaterialHeightMap, texCoord).r;
float v = height*ParallaxScale + ParallaxBias;
@@ -159,17 +159,16 @@ void main()
discard;
#endif // ALPHA_TEST
#if LIGHTING
#if NORMAL_MAPPING
#if NORMAL_MAPPING
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, texCoord)) - 1.0));
#else
#else
vec3 normal = normalize(vNormal);
#endif // NORMAL_MAPPING
#endif // NORMAL_MAPPING
vec3 specularColor = MaterialSpecular.rgb;
#if SPECULAR_MAPPING
#if SPECULAR_MAPPING
specularColor *= texture(MaterialSpecularMap, texCoord).rgb;
#endif
#endif
/*
Texture0: Diffuse Color + Specular
@@ -179,9 +178,6 @@ void main()
RenderTarget0 = vec4(diffuseColor.rgb, dot(specularColor, vec3(0.3, 0.59, 0.11)));
RenderTarget1 = vec4(EncodeNormal(normal));
RenderTarget2 = vec4(FloatToColor(gl_FragCoord.z), (MaterialShininess == 0.0) ? 0.0 : max(log2(MaterialShininess), 0.1)/10.5); // http://www.guerrilla-games.com/publications/dr_kz2_rsx_dev07.pdf
#else // LIGHTING
RenderTarget0 = vec4(diffuseColor.rgb, 0.0);
#endif
#else // FLAG_DEFERRED
#if ALPHA_MAPPING
diffuseColor.a *= texture(MaterialAlphaMap, texCoord).r;
@@ -192,16 +188,15 @@ void main()
discard;
#endif
#if LIGHTING
vec3 lightAmbient = vec3(0.0);
vec3 lightDiffuse = vec3(0.0);
vec3 lightSpecular = vec3(0.0);
#if NORMAL_MAPPING
#if NORMAL_MAPPING
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, texCoord)) - 1.0));
#else
#else
vec3 normal = normalize(vNormal);
#endif
#endif
if (MaterialShininess > 0.0)
{
@@ -459,24 +454,21 @@ void main()
}
lightSpecular *= MaterialSpecular.rgb;
#if SPECULAR_MAPPING
#if SPECULAR_MAPPING
lightSpecular *= texture(MaterialSpecularMap, texCoord).rgb; // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
#endif
#endif
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
vec4 fragmentColor = vec4(lightColor, 1.0) * diffuseColor;
#if EMISSIVE_MAPPING
#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
RenderTarget0 = fragmentColor;
#endif // EMISSIVE_MAPPING
#endif // FLAG_DEFERRED
}

File diff suppressed because one or more lines are too long

View File

@@ -12,6 +12,7 @@ in vec3 VertexPosition;
in vec3 VertexNormal;
in vec3 VertexTangent;
in vec2 VertexTexCoord;
in vec4 VertexUserdata0;
/********************Sortant********************/
out vec4 vColor;
@@ -27,6 +28,7 @@ uniform vec3 EyePosition;
uniform mat4 InvViewMatrix;
uniform mat4 LightViewProjMatrix[3];
uniform float VertexDepth;
uniform mat4 ViewMatrix;
uniform mat4 ViewProjMatrix;
uniform mat4 WorldMatrix;
uniform mat4 WorldViewProjMatrix;
@@ -107,21 +109,19 @@ void main()
vColor = color;
#if LIGHTING
#if FLAG_INSTANCING
#if FLAG_INSTANCING
mat3 rotationMatrix = mat3(InstanceData0);
#else
#else
mat3 rotationMatrix = mat3(WorldMatrix);
#endif
#endif
#if COMPUTE_TBNMATRIX
#if COMPUTE_TBNMATRIX
vec3 binormal = cross(VertexNormal, VertexTangent);
vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);
vLightToWorld[1] = normalize(rotationMatrix * binormal);
vLightToWorld[2] = normalize(rotationMatrix * VertexNormal);
#else
#else
vNormal = normalize(rotationMatrix * VertexNormal);
#endif
#endif
#if SHADOW_MAPPING
@@ -133,12 +133,12 @@ void main()
vTexCoord = VertexTexCoord;
#endif
#if LIGHTING && PARALLAX_MAPPING
#if PARALLAX_MAPPING
vViewDir = EyePosition - VertexPosition;
vViewDir *= vLightToWorld;
#endif
#if LIGHTING && !FLAG_DEFERRED
#if !FLAG_DEFERRED
#if FLAG_INSTANCING
vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0));
#else

File diff suppressed because one or more lines are too long