Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
normaltransform issue?

shadowman131
Registered User
Quote
2011-09-28 08:46:28

Hi, I set up the following vertex / fragment shader. It's supposed to just very simply implement a directional light... Something that by my understanding Copperlicht doesn't do implicitly? If there is an easier way (or more programmatic / going with copperlicht rather than shader specific code) please let me know.

Anyway, normaltransform always seems to return 0. The normals never have any effect on the color; I know that my normals are being loaded properly by the shader because if I use another transform supplied by copperlicht I get results varying according to the normal, as expected. Just not the right shading. Code below:


var vertex_shader = "\
ifdef GL_ES \n\
precision highp float; \n\
endif \n\
uniform mat4 worldviewproj; \n\
uniform mat4 normaltransform; \n\
attribute vec4 vPosition; \n\
attribute vec4 vNormal; \n\
attribute vec2 vTexCoord1; \n\
attribute vec2 vTexCoord2; \n\
varying vec2 v_texCoord1; \n\
varying vec2 v_texCoord2; \n\
varying float v_lighting; \n\
vec4 normal, lightDir; \n\
float nDotL; \n\
void main() { \n\
v_texCoord1 = vTexCoord1.st; \n\
v_texCoord2 = vTexCoord2.st; \n\
gl_Position = worldviewproj * vPosition; \n\
/* normal to world space */ \n\
normal = normalize(normaltransform * vNormal); \n\
/* light is in world space */ \n\
lightDir = normalize(vec4(1,0,0,0)); \n\
/* dot product / diffuse */ \n\
nDotL = max(dot(normal, lightDir), 0.0); \n\
v_lighting = nDotL * 0.7 + 0.3; \n\
}";
var frag_shader = "\
ifdef GL_ES \n\
precision highp float; \n\
endif \n\
uniform sampler2D texture1; \n\
uniform sampler2D texture2; \n\
varying vec2 v_texCoord1; \n\
varying vec2 v_texCoord2; \n\
varying float v_lighting; \n\
void main() { \n\
vec2 texCoord = vec2(v_texCoord1.s, v_texCoord1.t); \n\
gl_FragColor = vec4(1,1,1,1) * v_lighting; /* texture2D(texture1, texCoord); */ \n\
}";
var newMatType = sa.cl.getRenderer().createMaterialType(vertex_shader, frag_shader);


Thank you for your help!


niko
Moderator
Quote
2011-09-28 18:22:52

Hi,

yes, this one has probably a bug. In the upcoming release, dynamic light is supported, and support for stuff like this will be better. I think it should take about one week until this is out.
If you can't wait, you can simply use the Material callback of the renderer class, and set your own constants directly using WebGL as workaround.


shadowman131
Registered User
Quote
2011-09-29 02:01:25

I can wait a week. Thanks Niko!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Interna?ional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact