Closed matrix3d closed 10 years ago
Unsure how it is supposed to work or how to resolve it but here are some ideas ...
It could work to set the lights in the vertex shader to another parameter. Usually you precalculate the lightning for each vertex and then set this value for the fragment shader to use. If you have a static value for each vertex and want to set it directly to the fragment shader it might work similar to Textures by passing it to the fragment shader as an argument.
@ScrambledRK thanks
This is not a bug. In that case, HxSL will assume that the light direction is dynamic so can be changed every frame. It does not slow down the shader versus having a constant light because constants are also part of the shader parameters.
thanks.
where the .1,.2,.3?
package ; import flash.display.Sprite; import flash.geom.Vector3D; import hxsl.Shader; class TestShader extends Shader { static var SRC = { var lights:Param <{ var lights:Array<{position:Float3}>; }>; function vertex() { out = [1, 1, 1, 1]; } function fragment() { var color:Float4 = [0,0,0,0]; for (light in lights.lights) { color.xyz += light.position; } out = color; } } } class TestHxsl extends Sprite { public static function main():Void { var shader = new TestShader(); shader.lights = { lights:[ {position:new Vector3D(.1, .2, .3) } ] }; var shaderInstance = shader.getInstance(); trace(shader.getDebugShaderCode(true)); trace(shaderInstance.fragmentVars); }
}
output
TestHxsl.hx:32: vertex: mov out, c0.xxxx fragment: mov t0, c1.xxxx add t0.xyz, t0.xyz, c0.xyz mov out, t0 TestHxsl.hx:33: 0,0,0,0,0,1,1,1