Help with shader error

I’m having the hardest time porting a shader to jme3 and the docs have help up to a point but I’m stuck, this the original shader works without issue in render monkey



what does that mean thats from jmp

[java]Error in scene!

(com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Shaders/toonSpecNorm.vert, defines, type=Vertex] error:0(29) : error C1020: invalid operands to “"

0(50) : error C1020: invalid operands to "


0(54) : error C1020: invalid operands to “-”

[/java]

It probably means that you have invalid operands … Honestly what do you excpect from us without even giving us the shader source, or even a few relevant lines.

my bad

its kinda crazy but does what I need sort of



original vert

[java]varying vec3 vLight;

varying vec4 vDiff;

varying vec4 vView;

varying vec3 vNormal;

varying vec4 vMat;

varying vec2 texCoord0;



attribute vec3 modelTangent;

uniform int numLights;

varying vec3 viewDirection;

varying vec3 lightDirections[1];

varying vec2 texcoords;



void main()

{

gl_Position = ftransform();

texcoords = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;



/* Get view and light directions in viewspace /

vec3 localViewDirection = -(gl_ModelViewMatrix * gl_Vertex).xyz;



/
Calculate tangent info - stored in attributes /

vec3 normal = gl_NormalMatrix * gl_Normal;

vec3 tangent = gl_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 );



for(int i = 0; i < 1; i++) {

vec3 localLightDirection = gl_LightSource.position.xyz + localViewDirection;

lightDirections.x = dot( tangent, localLightDirection );

lightDirections.y = dot( binormal, localLightDirection );

lightDirections.z = dot( normal, localLightDirection );

lightDirections = normalize( lightDirections );

} // for





vec3 vtx =(gl_ModelViewMatrix * gl_Vertex).xyz;

vLight = (gl_LightSource[0].position).xyz - vtx;

//texture

texCoord0 = gl_MultiTexCoord0.xy;

vView = gl_Vertex - gl_ModelViewMatrix[3];



vNormal = gl_NormalMatrix * gl_Normal;

vMat = gl_Color * gl_LightSource[0].diffuse;



gl_Position = ftransform();

}[/java]



original frag

[java]varying vec3 vLight;

varying vec4 vDiff;

varying vec3 vNormal;

varying vec4 vMat;

varying vec2 texCoord0;

varying vec3 viewDirection;

varying vec3 lightDirections[1];



uniform sampler2D colorMap;

uniform sampler2D specularMap;

uniform sampler2D normalMap;



uniform vec4 vWidths;

uniform vec4 noiseMod;

uniform vec4 vWidthFactor;

uniform float m_Time;

uniform float m_Strength;

uniform float blend;

uniform vec4 Material;





void main(){

vec3 vNorm = normalize(vNormal);

vec4 vColour = vMat;



vec3 vLightN = normalize(vLight);



float x = (texCoord0.x+4.0) * (texCoord0.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;



float ndotl = dot(vNorm, vLightN);

vec4 base0 = texture2D(colorMap, texCoord0);

//gl_FragColor = base0 * gl_FrontMaterial.diffuse;





vColour =mix(vWidthFactor.x+(grainnoiseMod.x), vec4(1.0), step(vWidths.x,ndotl ));

vColour =mix(vWidthFactor.y+(grainnoiseMod.y), vec4(1.0), step(vWidths.y,ndotl ));

vColour =mix(vWidthFactor.z+(grainnoiseMod.z), vec4(1.0), step(vWidths.z,ndotl ));

vColour =mix(vWidthFactor.w+(grainnoiseMod.w), vec4(1.0), step(vWidths.w,ndotl ));



float lum = dot(base0.rgb, vec3(0.299, 0.587, 0.114));

vec4 gray = vec4(lum, lum, lum, base0.a);

gl_FragColor = mix(base0, gray, blend);



gl_FragColor = ((mix(base0, gray, blend) + vColour) * gl_FrontMaterial.diffuse) Material;





/* Extract colors from baseMap and specularMap /

//vec4 baseColor = texture2D( baseMap, texcoords );

vec3 normal = normalize( ( texture2D( normalMap, texCoord0 ).xyz * 2.0 ) - 1.0 );

vec4 specularColor = texture2D( specularMap, texCoord0 );



vec3 normalizedViewDirection = normalize( 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;

vec4 totalSpecular;



//


LIGHTS
for(int i = 0; i < 1; i++) {
vec3 normalizedLightDirection = normalize( lightDirections );
float NDotL = dot( normal, normalizedLightDirection );
vec3 reflection = normalize( ( ( 2.0 * normal ) * NDotL ) - normalizedLightDirection );

/* Sum up lighting models with OpenGL provided light/material properties */
totalAmbient += gl_FrontLightProduct.ambient;
totalDiffuse += clamp( gl_FrontLightProduct.diffuse * max( 0.0, NDotL ), 0.0, 1.0 );
totalSpecular += gl_FrontLightProduct.specular * specularColor * ( pow( max( 0.0, dot( reflection, normalizedViewDirection ) ), gl_FrontMaterial.shininess ) );
} // for

/* Set final pixel color as sum of lighting models */
gl_FragColor *= (totalAmbient * base0 + totalDiffuse * base0 + totalSpecular)*2.5;
gl_FragColor += (((mix(base0, gray, blend) + vColour) * gl_FrontMaterial.diffuse * Material)*(totalAmbient * base0 + totalDiffuse * base0 + totalSpecular) )*0.75;
}

[/java]

attempted Ports
vert
[java]varying vec3 vLight;
varying vec4 vDiff;
varying vec4 vView;
varying vec3 vNormal;
varying vec4 vMat;
varying vec2 texCoord0;

attribute vec3 modelTangent;
attribute vec3 inPosition;
attribute vec4 inTexCoord;
attribute vec4 inColor;
attribute vec3 inNormal;

uniform mat4 g_WorldViewProjectionMatrix;
uniform mat3 g_NormalMatrix;
uniform mat3 g_WorldViewMatrix[];

varying vec3 viewDirection;
varying vec3 lightDirections[1];
varying vec2 texcoords;

void main()
{
gl_Position = ftransform();
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 );

for(int i = 0; i < 1; i++) {
vec3 localLightDirection = gl_LightSource.position.xyz + localViewDirection;
lightDirections.x = dot( tangent, localLightDirection );
lightDirections.y = dot( binormal, localLightDirection );
lightDirections.z = dot( normal, localLightDirection );
lightDirections = normalize( lightDirections );
} // for


vec3 vtx =(g_WorldViewMatrix * inPosition).xyz;
vLight = (gl_LightSource[0].position).xyz - vtx;

//texture
texCoord0 = inTexCoord.xy;
vView = inPosition - g_WorldViewMatrix[3];

vNormal = g_NormalMatrix * inNormal;
vMat = inColor * gl_LightSource[0].diffuse;

gl_Position = ftransform();
}[/java]

frag
[java]varying vec3 vLight;
varying vec4 vDiff;
varying vec3 vNormal;
varying vec4 vMat;
varying vec2 texCoord0;
varying vec3 viewDirection;
varying vec3 lightDirections[1];

uniform sampler2D m_colorMap;
uniform sampler2D m_specularMap;
uniform sampler2D m_normalMap;

uniform vec4 m_vWidths;
uniform vec4 m_noiseMod;
uniform vec4 m_vWidthFactor;
uniform float m_Time;
uniform float m_Strength;
uniform float m_blend;
uniform vec4 m_Material;


void main(){
vec3 vNorm = normalize(vNormal);
vec4 vColour = vMat;

vec3 vLightN = normalize(vLight);

float x = (texCoord0.x+4.0) * (texCoord0.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;

float ndotl = dot(vNorm, vLightN);
vec4 base0 = texture2D(colorMap, texCoord0);
//gl_FragColor = base0 * gl_FrontMaterial.diffuse;


vColour *=mix(vWidthFactor.x+(grain*noiseMod.x), vec4(1.0), step(vWidths.x,ndotl ));
vColour *=mix(vWidthFactor.y+(grain*noiseMod.y), vec4(1.0), step(vWidths.y,ndotl ));
vColour *=mix(vWidthFactor.z+(grain*noiseMod.z), vec4(1.0), step(vWidths.z,ndotl ));
vColour *=mix(vWidthFactor.w+(grain*noiseMod.w), vec4(1.0), step(vWidths.w,ndotl ));

float lum = dot(base0.rgb, vec3(0.299, 0.587, 0.114));
vec4 gray = vec4(lum, lum, lum, base0.a);
gl_FragColor = mix(base0, gray, blend);

gl_FragColor *= ((mix(base0, gray, blend) + vColour) * gl_FrontMaterial.diffuse)* Material;


/* Extract colors from baseMap and specularMap */
//vec4 baseColor = texture2D( baseMap, texcoords );
vec3 normal = normalize( ( texture2D( normalMap, texCoord0 ).xyz * 2.0 ) - 1.0 );
vec4 specularColor = texture2D( specularMap, texCoord0 );

vec3 normalizedViewDirection = normalize( 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;
vec4 totalSpecular;

//

LIGHTS
for(int i = 0; i < 1; i++) {
vec3 normalizedLightDirection = normalize( lightDirections );
float NDotL = dot( normal, normalizedLightDirection );
vec3 reflection = normalize( ( ( 2.0 * normal ) * NDotL ) - normalizedLightDirection );

/* Sum up lighting models with OpenGL provided light/material properties */
totalAmbient += gl_FrontLightProduct.ambient;
totalDiffuse += clamp( gl_FrontLightProduct.diffuse * max( 0.0, NDotL ), 0.0, 1.0 );
totalSpecular += gl_FrontLightProduct.specular * specularColor * ( pow( max( 0.0, dot( reflection, normalizedViewDirection ) ), gl_FrontMaterial.shininess ) );
} // for

/* Set final pixel color as sum of lighting models */
gl_FragColor *= (totalAmbient * base0 + totalDiffuse * base0 + totalSpecular)*2.5;
gl_FragColor += (((mix(base0, gray, blend) + vColour) * gl_FrontMaterial.diffuse * Material)*(totalAmbient * base0 + totalDiffuse * base0 + totalSpecular) )*0.75;
}

[/java]

intended result - there are some artifacts but that has to do with RMs tangent calculations..I've read

http://i.imgur.com/83URx.jpg

That shader has a lot of other bugs that will prevent it from working in jME3.

Please read this:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:jme3_shaders

yeah I read that through before I even started, there are some things that are still unclear to me, a bit more elaboration as to what I doing wrong or not doing would be helpful as fixing the shader within jmp is causing it’s own sets of headaches i.e. when the shader crashes it seems to take jmp rendering system hostage and I have to then restart it, I have also tried to find a thread that shows a “normal” shader and jme3 ported shader came across this but I can use as much info as I can get

You cannot use any variables that start with “gl_” except for gl_Position and gl_FragColor, and you cannot use ftransform(). All attributes should start with “in”. From what I see you haven’t really read the document because all of this is explained there.

Heya mcbeth, nice to see you are still working on that, have been wondering about it since you ran pretty quiet for a few weeks. May I ask why you are still trying to go this way? From my point of view, the post processing shaders I wrote back then could achieve pretty much the same results as you appear to be trying to achieve while keeping things way easier. The method I used allowed you to use the default jME materials and just edit settings for everything on the screen at the same time, seeing it was a post effect, thus allowing for easy tweaking, though it may prove more difficult if you want some parts of the scene to be affected only by other kinds of effects than the overal style.

I believe you had some trouble getting it to work, did you try them (working ofcourse) or do I need to help you a bit on that?

Just saying :wink:

baalgarnaal said:
though it may prove more difficult if you want some parts of the scene to be affected only by other kinds of effects than the overal style.
that's it right there plus I needed the noise effect to bleed out of or into darkened areas (lighting) and coverage to take account of object shape and normals while doing that in addition to "grading" the noise, your solution worked a bit but saturated the scene/screen quite a bit at times, added to that there is material colouring and colour desaturation/intensification( presently not working "totally"due the additional maps experiment causing it to not bleed totally into black and white some how) and I definitely don't want those settings affecting each node/object in the same way
I believe you had some trouble getting it to work, did you try them (working ofcourse) or do I need to help you a bit on that?
Just saying ;)

the long and short of it is I dont think it would be easy to do what I want with a post filter, this why I kept on working on that toon shader

@Momoko_Fan I did read the doc missed a couple of the external links somehow but yeah I read it....the gl_ g_ thing wasn't 100 percent clear...(to me) ....thats why I used the list provided, I'm guess gl_Material should be g_frontMaterial and such the like, will look into it
and um .... ftransform(); um hhm

I have this mostly figured out now, I still have an issue with replacing [java]texCoord0 = gl_MultiTexCoord0.xy;[/java] the texture either doesn’t show or the coordinates are messed up with everything I have tried so far

I’m doing this in baby step to fully understand my issues so I scaled down the shader a bit

scaled down vert

[java]varying vec3 vLight;

varying vec4 vDiff;

varying vec4 vView;

varying vec3 vNormal;

varying vec4 vMat;

varying vec2 texCoord0;

uniform mat4 g_WorldViewProjectionMatrix;

uniform mat3 g_NormalMatrix;

uniform mat4 g_WorldViewMatrix;

attribute vec3 inPosition;

attribute vec3 inNormal;

attribute vec4 inColor;

attribute vec2 inTexcoord;

void main()

{

gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);

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

vLight = (gl_LightSource[0].position).xyz - vtx;

//texture

//texCoord0 = gl_MultiTexCoord0.xy;

texCoord0 = inTexcoord;

vView = vec4(inPosition, 1.0) - g_WorldViewMatrix[3];

vNormal = g_NormalMatrix * inNormal;

vMat = inColor * gl_LightSource[0].diffuse;

}[/java]

If this:

texCoord0 = inTexcoord;



Is giving you garbage then the most likely cause is that your vertexes don’t have texture coordinates.



Hmmm… though I’d also note that it’s supposed to be inTexCoord (notice the capital ‘C’) and that’s probably significant.

and the forum seems to not cater for = and ( having no white spaces between them when posting code :? it tries to load smilies

pspeed said:
If this:
texCoord0 = inTexcoord;
Is giving you garbage then the most likely cause is that your vertexes don't have texture coordinates.
Hmmm... though I'd also note that it's supposed to be inTexCoord (notice the capital 'C') and that's probably significant.

strange.... I'm using Oto, I'll check your suggestion on the spelling
edit:
Texture coords are better now but still messed a bit .....sigh.... that and the model is showing transparent :? still more to do I suppose thank for the assist.
http://i.imgur.com/oaE9U.jpg

Well by no means this is a final solution to your problem but you could try adding this to the last bit of your frag shader to get rid of any transparancy:

[java]gl_FragColor.a = 1.0;[/java]

Though that also removes any alpha information you may have provided earlier in the code or the textures. Perhaps taking the alpha from the base0 would do better:

[java]gl_FragColor.a = base0.a;[/java]

But I suspect that the alpha is created by the numerous mathematical expressions in your shader, no clue why one would do it like that.

baalgarnaal said:
Well by no means this is a final solution to your problem but you could try adding this to the last bit of your frag shader to get rid of any transparancy:
[java]gl_FragColor.a = 1.0;[/java]
Though that also removes any alpha information you may have provided earlier in the code or the textures. Perhaps taking the alpha from the base0 would do better:
[java]gl_FragColor.a = base0.a;[/java]
But I suspect that the alpha is created by the numerous mathematical expressions in your shader, no clue why one would do it like that.

I'll try that thank,............... though I did get it to show solid on my several attempts to make the texture show yesterday (damn spelling error :x ) ....as for the math expressions they had the effect of balancing out some color and brightness issues that I encountered when adding multiplying the different elements of the look I am going for, trust me I knew it was an unorthodox approach from the get-go, but it all looked good in render monkey, wish they would update that thing though...............I'm much better at visual tools.

ok think I figured out part of my issue, it seems that the shader doesn’t play well with the edge filter, hence the transparency issue…why?.. and how might I fix …if known

and the texture coordinate problem might have to do with the fact that I directly reload Oto’s texture to pass it in the shader…um how do u retrieve, textures if they are preloaded…assuming that that is the root of the texture coordinate problems ofcourse



edit it seems that both bloom and edge adds transparent to varying degrees