瀏覽代碼

Add support for detail map to the standard material shader code

Popov72 5 年之前
父節點
當前提交
4c0c43e6a5
共有 3 個文件被更改,包括 21 次插入0 次删除
  1. 2 0
      src/Shaders/ShadersInclude/defaultUboDeclaration.fx
  2. 4 0
      src/Shaders/default.fragment.fx
  3. 15 0
      src/Shaders/default.vertex.fx

+ 2 - 0
src/Shaders/ShadersInclude/defaultUboDeclaration.fx

@@ -21,7 +21,9 @@ uniform Material
 	vec2 vLightmapInfos;
 	vec2 vSpecularInfos;
 	vec3 vBumpInfos;
+	vec3 vDetailInfos;
 	mat4 diffuseMatrix;
+	mat4 detailMatrix;
 	mat4 ambientMatrix;
 	mat4 opacityMatrix;
 	mat4 reflectionMatrix;

+ 4 - 0
src/Shaders/default.fragment.fx

@@ -218,6 +218,10 @@ void main(void) {
 	baseColor.rgb *= vColor.rgb;
 #endif
 
+#ifdef DETAIL
+    baseColor.rgb = baseColor.rgb * (saturate(vec3(detailColor.r) + vDetailInfos.y));
+#endif
+
 #define CUSTOM_FRAGMENT_UPDATE_DIFFUSE
 
 	// Ambient color

+ 15 - 0
src/Shaders/default.vertex.fx

@@ -39,6 +39,10 @@ attribute vec4 color;
 varying vec2 vDiffuseUV;
 #endif
 
+#if defined(DETAIL) && DETAILDIRECTUV == 0
+varying vec2 vDetailUV;
+#endif
+
 #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
 varying vec2 vAmbientUV;
 #endif
@@ -184,6 +188,17 @@ void main(void) {
 	}
 #endif
 
+#if defined(DETAIL) && DETAILDIRECTUV == 0
+	if (vDetailInfos.x == 0.)
+	{
+		vDetailUV = vec2(detailMatrix * vec4(uvUpdated, 1.0, 0.0));
+	}
+	else
+	{
+		vDetailUV = vec2(detailMatrix * vec4(uv2, 1.0, 0.0));
+	}
+#endif
+
 #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
 	if (vAmbientInfos.x == 0.)
 	{