Hello All,
I have this error and can’t figure out what I am doing wrong. The code looks correct…
//vert shader
uniform mat4 g_WorldViewProjectionMatrix;
attribute vec3 inPosition;
attribute vec4 inTexCoord;
attribute vec4 inTexCoord1;
uniform mat3 g_NormalMatrix;
attribute vec3 inNormal;
varying vec3 lightDir;
varying vec3 halfVector;
void main()
{
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
gl_TexCoord[0] = inTexCoord;
vec3 n = normalize(g_NormalMatrix * inNormal);
vec3 t = normalize(g_NormalMatrix * inTexCoord1.xyz);
vec3 b = cross(n, t) * inTexCoord1.w;
mat3 tbnMatrix = mat3(t.x, b.x, n.x, t.y, b.y, n.y, t.z, b.z, n.z);
lightDir = gl_LightSource[0].position.xyz;
lightDir = tbnMatrix * lightDir;
halfVector = gl_LightSource[0].halfVector.xyz;
halfVector = tbnMatrix * halfVector;
}
//frag shader
uniform sampler2D m_ColorMap;
uniform sampler2D m_NormalMap;
uniform sampler2D m_HeightMap;
uniform float m_Bias;
uniform bool m_EnableParallax;
uniform float m_Scale;
varying vec3 lightDir;
varying vec3 halfVector;
void main()
{
vec2 newTexCoord;
vec3 h = normalize(halfVector);
if (m_EnableParallax == true)
{
float height = texture2D(m_HeightMap, gl_TexCoord[0].st).r;
height = height * m_Scale + m_Bias;
newTexCoord = gl_TexCoord[0].st + (height * h.xy);
}
else
{
newTexCoord = gl_TexCoord[0].st;
}
vec3 n = normalize(texture2D(m_NormalMap, newTexCoord).rgb * 2.0 - 1.0);
vec3 l = normalize(lightDir);
float nDotL = max(0.0, dot(n, l));
float nDotH = max(0.0, dot(n, h));
float power = (nDotL == 0.0) ? 0.0 : pow(nDotH, gl_FrontMaterial.shininess);
vec4 ambient = gl_FrontLightProduct[0].ambient;
vec4 diffuse = gl_FrontLightProduct[0].diffuse * nDotL;
vec4 specular = gl_FrontLightProduct[0].specular * power;
vec4 color = gl_FrontLightModelProduct.sceneColor + ambient + diffuse + specular;
gl_FragColor = color * texture2D(m_ColorMap, newTexCoord);
}
//jMonkeyCode
Box b = new Box(1, 1, 1);
geom = new Geometry("Box", b);
//Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
//mat.setColor("Color", ColorRGBA.Blue);
//geom.setMaterial(mat);
TangentBinormalGenerator.generate(geom);
Material bumpMat = new Material(assetManager, "MatDefs/ParallaxMapping.j3md");
bumpMat.setTexture("HeightMap", assetManager.loadTexture("Textures/BrickHM.png"));
bumpMat.setTexture("NormalMap", assetManager.loadTexture("Textures/BrickNM.png"));
bumpMat.setTexture("ColorMap", assetManager.loadTexture("Textures/BrickDM.png"));
bumpMat.setBoolean("EnableParallax", true);
bumpMat.setFloat("Scale", 1.0f);
bumpMat.setFloat("Bias", 1.0f);
bumpMat.setVector3("LightDir", new Vector3f(1.0f,-1.0f,-2.0f).normalize());
bumpMat.setVector3("HalfVector", new Vector3f(1.0f,-1.0f,-2.0f).normalize());
geom.setMaterial(bumpMat);
rootNode.attachChild(geom);