Help with shader error

can’t quite make sense of this error, I worked on it in RM it works well there and I think the port to jme3 is okay-ish, I worked my way through the last shader I ported, but I dont actually understand this error as in what it means.



any help would be greatly appreciated



[java]com.jme3.renderer.RendererException: compile error in:ShaderSource[name=assets/Shaders/toonSpecNorm2.vert, defines, type=Vertex] error:0(21) : error C1101: ambiguous overloaded function reference “mul(mat3, vec4)”

(0) : mat1x3 mul(mat1x3, mat3)

(0) : vec1 mul(vec4, mat4x1)

(0) : vec2 mul(vec4, mat4x2)

(0) : vec3 mul(vec3, mat3)

(0) : vec3 mul(vec4, mat4x3)

(0) : vec4 mul(vec4, mat4)[/java]







vertex shader

[java]attribute vec3 modelTangent;

attribute vec3 inPosition;

attribute vec4 inTexCoord;

//attribute vec4 inColor;

attribute vec3 inNormal;



uniform mat3 g_NormalMatrix;

uniform mat3 g_WorldViewMatrix;

uniform mat4 g_WorldViewProjectionMatrix;



varying vec3 viewDirection;

varying vec3 lightDirections;

varying vec2 texCoords;



void main()

{

gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);

texCoords = (gl_TextureMatrix[0] * inTexCoord).xy;



/* Get view and light directions in viewspace /

vec3 localViewDirection = -(g_WorldViewMatrix * vec4(inPosition, 1.0)).xyz;



/
Calculate tangent info - stored in attributes /

vec3 normal = g_NormalMatrix * inNormal;

vec3 tangent = g_NormalMatrix * modelTangent;

vec3 binormal = cross( normal, tangent );



/
Transform localViewDirection into texture space */

viewDirection.x = dot( tangent, localViewDirection );

viewDirection.y = dot( binormal, localViewDirection );

viewDirection.z = dot( normal, localViewDirection );



vec3 localLightDirection = gl_LightSource[0].position.xyz + localViewDirection;

lightDirections.x = dot( tangent, localLightDirection );

lightDirections.y = dot( binormal, localLightDirection );

lightDirections.z = dot( normal, localLightDirection );

lightDirections = normalize( lightDirections );



}[/java]

I think I can integrate much of what this “TF2-ish toon style” does with the jme lighting shader but that huge, and I’m terribly afraid of it



any way this is what it looks like when it works RM tangent Normal calculations has artifacts



http://i.imgur.com/miXvc.jpg

vec3 localViewDirection = -(g_WorldViewMatrix * vec4(inPosition, 1.0)).xyz;



g_WorldViewMatrix is a mat3 but you are multiplying it by a vec4. There is no math operation for that. Either you meant something other than g_WorldViewMatrix or you do not need to upconvert inPosition to a vec4 in the first place.

yeah thanks I screwed up, it’s working now, well sort, of my program runs but the model is invisible :? I’ve seen this before… well kinda if you remove the lighting methods in some of the tests the terrain will disappear :? in my case the stats with the model is there but it cant be seen :o 8O

weird

No light, no visuals.

normen said:
No light, no visuals.


yeah I get that, maybe I should have been clearer there are lights in the scene in this instance model is just not showing, you see face and vertex data in the stats, but no model I applied the j3m file to the head of a two part model and that (the head) would also not appear it might be an issue with the j3m........really hoping its not an issue with the shaders and the jme3 lighting will investigate later today.

My bet is on the .frag shader file. There’s probably something wrong in there. Maybe the color is set wrong because of the changes above?

madjack said:
My bet is on the .frag shader file. There's probably something wrong in there. Maybe the color is set wrong because of the changes above?


yeah I'll look into it later and post back thanks

well I looked at this for a long time kill what seemed a couple glaring errors but still no joy something in there is not agreeing with jme3 but I cant figure out what and with no errors as feedback :?



any ways can some one take a look I might be missing a step jme needs somewhere



frag shader

[java]uniform sampler2D m_ColorMap;

uniform sampler2D m_SpecularMap;

uniform sampler2D m_NormalMap;

uniform sampler2D m_Ramps;



//grain

uniform float m_Time;

uniform float m_Strength;



//mat

uniform vec4 m_Material;



//rim lights - don’t think it’s correct but I like the result

uniform vec4 m_RimLighting;



varying vec2 texCoords;

varying vec3 viewDirection;

varying vec3 lightDirection;









void main(void)

{

vec4 base0 = texture2D(m_ColorMap, texCoords);

vec3 normal = normalize( ( texture2D( m_NormalMap, texCoords ).xyz * 2.0 ) - 1.0 );

vec4 specularColor = texture2D( m_SpecularMap, texCoords );



vec3 normalizedLight_ViewDirection = normalize( lightDirection + viewDirection );

float NDotL = dot( normal, normalizedLight_ViewDirection );



vec3 rampColor = texture2D(m_Ramps, vec2(NDotL, 0.0)).rgb;

vec3 reflection = normalize( ( ( 2.0 * normal ) * NDotL ) - normalizedLight_ViewDirection );



/* Sum up lighting models with OpenGL provided light/material properties /

vec4 totalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient; // init with global ambient

vec4 totalDiffuse = gl_FrontMaterial.diffuse * NDotL * base0;

vec4 totalSpecular = gl_FrontMaterial.specular * specularColor * ( pow( max( 0.0, dot( reflection, normalizedLight_ViewDirection ) ), gl_FrontMaterial.shininess ) );





// vec4 totalAmbient = gl_FrontLightProduct[0].ambient;

//vec4 totalDiffuse = clamp( gl_FrontLightProduct[0].diffuse * max( 0.0, NDotL ), 0.0, 1.0 );

//vec4 totalSpecular = gl_FrontLightProduct[0].specular * specularColor * ( pow( max( 0.0, dot( reflection, normalizedLight_ViewDirection ) ), gl_FrontMaterial.shininess ) );



//noise

float x = (texCoords.x+4.0) * (texCoords.y+4.0) * (m_Time
10.0);

vec4 grain = vec4(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01)-0.005) * m_Strength;



//rim lighting

vec4 rim = pow( 1.0 - dot( normal, normalizedLight_ViewDirection.xyz ), 1.5 ) * m_RimLighting * m_RimLighting.w;

rim.a = 0.0;



gl_FragColor = ((totalAmbient * base0) + (totalDiffuse * base0) + (totalSpecular * specularColor));

gl_FragColor = ((((totalAmbient + base0) + ( totalSpecular + specularColor + vec4(rampColor,0.0 ))) + (base0 + (grain.10))) + gl_FrontMaterial.diffuse * Material);

gl_FragColor += rimtotalDiffuse;

[/java]



vert



[java]attribute vec3 modelTangent;

attribute vec3 inPosition;

attribute vec4 inTexCoord;

//attribute vec4 inColor;

attribute vec3 inNormal;



uniform mat3 g_NormalMatrix;

uniform mat3 g_WorldViewMatrix;

uniform mat4 g_WorldViewProjectionMatrix;



varying vec3 viewDirection;

varying vec3 lightDirections;

varying vec2 texCoords;



void main()

{

gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);

texCoords = (gl_TextureMatrix[0] * inTexCoord).xy;



/
Get view and light directions in viewspace /

vec3 localViewDirection = -(g_WorldViewMatrix * inPosition).xyz;



/
Calculate tangent info - stored in attributes /

vec3 normal = g_NormalMatrix * inNormal;

vec3 tangent = g_NormalMatrix * modelTangent;

vec3 binormal = cross( normal, tangent );



/
Transform localViewDirection into texture space */

viewDirection.x = dot( tangent, localViewDirection );

viewDirection.y = dot( binormal, localViewDirection );

viewDirection.z = dot( normal, localViewDirection );



vec3 localLightDirection = gl_LightSource[0].position.xyz + localViewDirection;

lightDirections.x = dot( tangent, localLightDirection );

lightDirections.y = dot( binormal, localLightDirection );

lightDirections.z = dot( normal, localLightDirection );

lightDirections = normalize( lightDirections );



}[/java]



edit: posted unconverted .vert by accident

At first glance I can’t see anything glaring at me, but I’m far from being an expert.



What I would personally do until someone more knowledgeable comes along is to simplify things by a large factor or even use static values and see what changes. From there you can probably trace back to the guilty line/function/variable. If you’ve already done that then I’m sorry but I can’t really help more than that. :frowning: Hopefully someone else will pick up on this.

All of this kind of stuff:

gl_LightModel.

gl_FrontMaterial



Is suspicious to me. JME doesn’t use the old (and I think deprecated?) gl_ built-in inputs and I’m half thinking that there is probably a reason for that. It’s possible they are garbage values but I’m no expert. I just do things the way every other JME shader does and cross my fingers really tight.



Anyway, when I debug shader issues like this then the first thing I would do is put a gl_FragColor = vec4(1.0); at the bottom and make sure that you see your mesh. Then work backwards from there setting it to different things to validate assumptions about that the values are. You could also set gl_FragColor.a = 1.0; at the bottom to see if maybe your alpha is just 0 or something.



Debugging shaders is tricky but mucking with the output color is the best way.

Yes. jME3 does not use those variables since they are deprecated in OpenGL 3.0. jME3 has its own set of global uniforms, you can find more info on the wiki

the thing is I know it would be impossible but the information on the wiki isn’t exactly exhaustive on the issues so some times I make assumptions based on the fact that something I did previously worked in that instance, take gl_FrontMaterial for instance the other toon shader I worked on used that and displays correctly so there are deprecated calls that in some instance that seem to be treated correctly…at any rate I’ll look at the jme shaders ( scary huge code-wise ) and see what I can do

Shouldn’t it be inTangent instead of modelTangent?

How many vertices does your model have? I’m having problems with tangents too when too many vertices are present.

You can also check your tangents beforehand by doing a debug render(testtangentbad.java or so…)

well figured out part of it jme either doen’ts like the normal map, the way I process the normals or the operation ran on them

the deprecated functions will need to be replaced at some point but they are not the primary cause of my issues…it seems the source of my worries are somwhere in



here



[java]

vec3 normal = normalize( ( texture2D( m_NormalMap, texCoords ).xyz * 2.0 ) - 1.0 );

vec3 normalizedLight_ViewDirection = normalize( lightDirection + viewDirection );

float NDotL = dot( normal, normalizedLight_ViewDirection );[/java]



or the map itself… any clues

well finally got the time to get this working “almost correctly” in jme3, I didn’t organize some view stuff properly, the only thing left do is plug it into jme lighting system are any simplified example of doing that around… the lighting shader is so huge and my knowledge of glsl is pretty basic



anyways

this is what looks like in jme3 without jme3 lighting (sorry for the black background and no the ninjas wont be wearing hot pants)

http://www.youtube.com/watch?v=NvmOzPESwNw



vert
[java]attribute vec3 inPosition;
attribute vec4 inTexCoord;
attribute vec3 inNormal;

uniform mat3 g_NormalMatrix;
uniform mat3 g_WorldViewMatrix;
uniform mat4 g_WorldViewProjectionMatrix;

varying vec3 viewDirection;
varying vec3 lightDirections;
varying vec2 texCoords;


void main()
{
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
texCoords = (gl_TextureMatrix[0] * inTexCoord).xy;

/* Get view and light directions in viewspace */
vec3 localViewDirection = -(g_WorldViewMatrix * inPosition).xyz;

/* Calculate tangent info - stored in attributes */
vec3 normal = normalize(g_NormalMatrix * inNormal);
vec3 tangent = normalize(g_NormalMatrix * inTexCoord.xyz);
vec3 binormal = cross(normal, tangent) * inTexCoord.w;

//vec3 binormal = cross( normal, tangent );

mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
tangent.y, binormal.y, normal.y,
tangent.z, binormal.z, normal.z);

/* Transform localViewDirection into texture space */
viewDirection = tbnMatrix * localViewDirection;

vec3 localLightDirection = gl_LightSource[0].position.xyz + localViewDirection;
lightDirections = tbnMatrix * localLightDirection;


}

[/java]

frag
[java]uniform sampler2D m_ColorMap;
uniform sampler2D m_SpecularMap;
uniform sampler2D m_NormalMap;
uniform sampler2D m_Ramps;

//grain
uniform float m_Time;
uniform float m_Strength;

//mat
uniform vec4 m_Material;

//rim lights
uniform vec4 m_RimLighting;
//control
uniform float m_artifact;

varying vec2 texCoords;
varying vec3 viewDirection;
varying vec3 lightDirections;




void main(void)
{
vec4 base0 = texture2D(m_ColorMap, texCoords);
vec3 normal = normalize( ( texture2D( m_NormalMap, texCoords ).rgb * 2.0 ) - 1.0 );
vec4 specularColor = texture2D( m_SpecularMap, texCoords );

vec3 normalizedLight_ViewDirection = normalize( lightDirections + viewDirection );
float NDotL = max(0.0, dot(normal, normalizedLight_ViewDirection));

vec3 rampColor = texture2D(m_Ramps, vec2(NDotL, 0.0)).rgb;
//float x = (texCoords.x+4.0) * (texCoords.y+4.0) * (m_Time*10.0);
vec3 reflection = normalize( ( (m_artifact * normal ) * NDotL ) - (normalizedLight_ViewDirection));

/* Sum up lighting models with OpenGL provided light/material properties */
vec4 totalAmbient = gl_FrontLightProduct[0].ambient ;
vec4 totalDiffuse = clamp( gl_FrontLightProduct[0].diffuse * base0 * max( 0.0, NDotL ), 0.0, 1.0 );
vec4 totalSpecular = gl_FrontLightProduct[0].specular * specularColor /* ( pow( max( 0.0, dot( reflection, normalizedLight_ViewDirection ) ), gl_FrontMaterial.shininess ) )*/;

//noise
float x = (texCoords.x+4.0) * (texCoords.y+4.0) * (m_Time*10.0);
vec4 grain = vec4(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01)-0.005) * m_Strength;

//rim lighting
vec4 rim = pow( 1.0 - dot( normal, normalizedLight_ViewDirection.xyz ), 1.5 ) * m_RimLighting * m_RimLighting.w;
rim.a = 0.0;

gl_FragColor = ((totalAmbient * base0) + (totalDiffuse * base0) + (totalSpecular * specularColor))*1.25;
gl_FragColor *= ((((totalAmbient + base0) + ( totalSpecular + specularColor + (vec4(rampColor,0.0 )*.75))) + (base0 + grain)) + gl_FrontMaterial.diffuse * m_Material)/*1.25*/;
gl_FragColor += rim*totalDiffuse; //add rim and diffuse for matte like effect or mult for rich glossy effect


}


[/java]
1 Like

anybody? I need to know if there is a shorter clearer sample or docs for lighting support anywhere