Hi, i tried the lighting MatDef from JME, but the parallax function doesn’t work (or work well).
It looks a but shitty^^, i dont know if i make some mistakes by using it, or if it doesn’t work generally??
If it works to you, you may give me a little tut how to use it…
But the main question is: How to use own shaders / shaders from other programs?
I downloadet a program where the parallax shader looked very well und tryed to use that shaders, but i realy dont know how to use it in JME
I tried these:
save the .vert / .frag in Shaders
vert:
#version 110
varying vec3 lightDir;
varying vec3 halfVector;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
vec3 n = normalize(gl_NormalMatrix * gl_Normal);
vec3 t = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz);
vec3 b = cross(n, t) * gl_MultiTexCoord1.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:
#version 110
uniform sampler2D colorMap;
uniform sampler2D normalMap;
uniform sampler2D heightMap;
uniform bool enableParallax;
uniform float scale;
uniform float bias;
varying vec3 lightDir;
varying vec3 halfVector;
void main()
{
vec2 newTexCoord;
vec3 h = normalize(halfVector);
if (enableParallax == true)
{
float height = texture2D(heightMap, gl_TexCoord[0].st).r;
height = height * scale + bias;
newTexCoord = gl_TexCoord[0].st + (height * h.xy);
}
else
{
newTexCoord = gl_TexCoord[0].st;
}
vec3 n = normalize(texture2D(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(colorMap, newTexCoord);
}
and wrote this as MatDef, and i think heres the problem, because i dont know how t write a good Matdef:
MaterialDef pn {
MaterialParameters {
Texture2D ColorMap
Texture2D NormalMap
Texture2D HeightMap
Boolean EnableParallax;
Float Scale;
Float Bias;
Vector3 LightDir;
Vector3 HalfVector;
}
Technique {
VertexShader GLSL110: Shaders/pn.vert
FragmentShader GLSL110: Shaders/pn.frag
WorldParameters {
WorldViewProjectionMatrix
}
Defines {
colorMap : ColorMap
normalMap : NormalMap
heightMap : HeightMap
scale : Scale
bias : bias
lightDir : LightDir
halfVector : HalfVector
}
}
}
And wrote this in the program:
Box redBox = new Box(new Vector3f(0,2.5f,0), 1,1,1);
Geometry redBGeo = new Geometry("Box2", redBox);
TangentBinormalGenerator.generate(redBox);
Material bumpMat = new Material(assetManager, "MatDefs/pn.j3md");
bumpMat.setTexture("HeightMap", assetManager.loadTexture("Textures/bricks_DISP.jpg"));
bumpMat.setTexture("NormalMap", assetManager.loadTexture("Textures/bricks_normal.jpg"));
bumpMat.setTexture("ColorMap", assetManager.loadTexture("Textures/bricks.jpg"));
bumpMat.setBoolean("EnableParallax", true);
bumpMat.setFloat("Scale", 1f);
bumpMat.setFloat("Bias", 1f);
bumpMat.setVector3("LightDir", new Vector3f(1,-1,-2).normalize());
bumpMat.setVector3("HalfVector", new Vector3f(1,-1,-2).normalize());
redBGeo.setMaterial(bumpMat);
//redBGeo.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(redBGeo);
As result i get this error:
28.06.2011 15:56:16 com.jme3.app.Application handleError
SCHWERWIEGEND: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Shaders/pn.vert, defines, type=Vertex] error:ERROR: 0:10: '1' : syntax error parse error
so i don't know how to write the matDef, or if theres a problem with the shader.
So please help me, and may give me a tut how to write a matdef file^^
And sorry for my bad english, its not my mother language :)