ncannasse / hxsl Goto Github PK
View Code? Open in Web Editor NEWHaxe Shader Language, a high level 3D shader language for Haxe
Haxe Shader Language, a high level 3D shader language for Haxe
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
Hi,
Here a big and a small problem.
The big one is about matrix multiplication.
To make an application targeting AS3, I took the example 2_texture as a base. As I wanted the projection matrix to affect the direction of the light (It was a mistake, but it doesn't matter here), so I replaced:
function vertex( mpos : M44, mproj : M44, light : Float3 ) {
out = input.pos.xyzw * mpos * mproj;
var tnorm = (input.norm * mpos).normalize();
lpow = light.dot(tnorm).max(0);
tuv = input.uv;
}
by
function vertex( mpos : M44, mproj : M44, light : Float3 ) {
out = input.pos.xyzw * mpos * mproj;
var tnorm = (input.norm * mpos * mproj).normalize();
lpow = light.dot(tnorm).max(0);
tuv = input.uv;
}
then I wanted to optimize by putting mpos_mproj in an variable, so I changed it for:
function vertex( mpos : M44, mproj : M44, light : Float3 ) {
var mposproj:M44 = mpos_mproj;
out = input.pos.xyzw * mposproj;
var tnorm = (input.norm * mposproj).normalize();
lpow = light.dot(tnorm).max(0);
tuv = input.uv;
}
and got an error on mpos_mproj:
M44 should be M44
I changed mposproj declaration for:
var mposproj = mpos_mproj;
and then got an error on input.pos.xyzw * mposproj:
M44 should be Float4
The small problem come with the Camera class that is given with the examples.
As the X,Y,Z vectors in Stage3D form a left-hand frame (see http://www.adobe.com/devnet/flashplayer/articles/3d-cameras.html) with X axis to right, Y to up and Z to front, the resulting projection matrix of Camera class comes reversing bottom and up.
In my case, I solved the problem replacing line 44:
var ay = az.cross(ax);
by
var ay = ax.cross(az);
It solved the problem with AS3 but it could cause it for other platforms. Maybe a better solution could be fine using precompilation instructions.
Should be an easy fix, when using latest Haxe: Shader.hx:95: characters 11-12 : Unmatched patterns: TArray(_,_)
Now boolean params can't contains null value
if( paramCount == 32 )
Context.error("Too many runtime parameters for this shader (max=32)", v.pos);
I see the vertexmap.like 0 16 32
but the 0 name?
thanks.
I try to compile a Flambe project using the new -D analyzer
, but I now get this error:
C:\HaxeToolkit\haxe\lib\hxsl/2,0,3/hxsl/RuntimeCompiler.hx:573: characters 17-20 : Unbound variable _g
Not sure if this is a Haxe or HXSL error.
In hxsl 1 this shader worked ok, now strange problem
class Batch2DShader extends Shader
{
static var SRC = {
var input : {
pos : Float2,
uv: Float2,
index:Float
};
var tuv:Float2;
var cTrans:Float4;
var pWrap:Param<Bool>;
var pFilter:Param<Bool>;
var pMipmap:Param<Bool>;
function vertex(mproj:Matrix, mpos:M44<20>, cTransArr:Float4<20>, regions:Float4<20>)
{
// http://code.google.com/p/hxformat/issues/detail?id=28#c8
//var i = input.pos.xyzw;
//i.x = input.index.x * 4;
//out = input.pos.xyzw * mpos[i.x] * mproj;
out = input.pos.xyzw * mpos[input.index * 4] * mproj;
var region = regions[input.index];
tuv = input.uv * region.zw + region.xy;
cTrans = cTransArr[input.index];
}
function fragment(tex:Texture)
{
out = tex.get(tuv, wrap=pWrap, filter=pFilter, mipmap=pMipmap) * cTrans;
}
};
}
[
[color1,color2],
[color1,color2],
]
Hi
I just downloaded the lib and the samples, and I cannot compile them,. Is it that this is not compatible with H3?
haxe -cp ../lib -swf C:/DEVEXAMPLES/haxe3/hxsl/samples/0_cube/test.swf -swf-header 800:600:60:FFFFFF --flash-strict -swf-version 11 -main Test -lib hxsl
Test.hx:13: characters 9-12 : Unknown variable 'pos'
c:\DEVTOOLS\HAXE\haxe\lib/hxsl/git/hxsl/Shader.hx:322: characters 2-11 : Build failure
Build halted with errors (haxe.exe
thanks
why here
https://github.com/ncannasse/hxsl/blob/master/hxsl/ShaderMacros.hx#L272
getter set modified=true; ?
Hi,
I noticed a Float/Bool conversion problem while trying to test an expression such as:
if ( xxx > 0.5) doSomething;
xxx being a Float
Compiler gives: "Float should be Bool" for the expression "xxx > 0.5"
The problem is that comparison operations between Float return a Float which value is 0 or 1 but if test requires a Bool and there is no conversion.
It seems to occurs in Compiler.hx when on line 206 is called "unify(cond.t, TBool, e.p);"
unify calls tryUnify which throws that error.
I also noticed that expressions such as if (aConstant == null) or if (aConstant!=null) do compile as they seem to return a Bool.
I presume that that exception is linked with the lines 801-817 of Compiler.hx, in the makeOp method.
That block starts with the comment: // if we have a null check, infer a VParam
On line 76, I tried to replace:
case CMin, CMax, CLt, CGte, CEq, CNeq, CLte, CGt: floats;
By:
case CMin, CMax: floats;
case CLt, CGte, CEq, CNeq, CLte, CGt: [ { p1 : TFloat4, p2 : TFloat4, r : TFloat4}, { p1 : TFloat3, p2 : TFloat3, r : TFloat3}, { p1 : TFloat2, p2 : TFloat2, r : TFloat2} , { p1 : TFloat, p2 : TFloat, r : TBool } ];
My shader compiled but failed at runtime.
I also tried to put in tryUnify, after the line 740:
case TFloat: return (t2 == TFloat || t2 == TBool);
but I had the same result. It compiled but failed at runtime.
Thank you for your work,
Olivier.
Test2.hx:20: vertex:
mov t0.xyz, c4.xxx
dp3 t1.x, t0.xyz, c0
dp3 t1.y, t0.xyz, c1
dp3 t1.z, t0.xyz, c2
mov out, t1.xyzz
fragment:
mov out, c0.xxxx
Now I see this error
C:\HaxeToolkit\haxe\lib/hxsl/2,0,0/hxsl/Shader.hx:308: characters 13-24 : You can't iterate on a Dynamic value, please specify Iterator or Iterable
C:\HaxeToolkit\haxe\lib/hxsl/2,0,0/hxsl/Shader.hx:136: characters 11-15 : hxsl.ShaderGlobals should be { instances : Map<Unknown<0>, Unknown<1>> }
C:\HaxeToolkit\haxe\lib/hxsl/2,0,0/hxsl/Shader.hx:136: characters 11-15 : The field instances is not public
C:\HaxeToolkit\haxe\lib/hxsl/2,0,0/hxsl/Shader.hx:136: characters 11-15 : For function argument 'x'
FIX: static var ALL:Array = new Array();
I write fragment func like this
function fragment(tex0:Texture, tex1:Texture, tex2:Texture, tex3:Texture)
but the problem is I don't the exact number of textures will used here
currently I uploaded 8 tex with some empty bitmapdata textures
but in agal I can dynamically make the agal opcode string to achieve this
for (var x:int;i < textureCount;i++){
"tex " + ftColor + "," + + "," + fsList[i] + "<2d,repeat,miplinear,linear>",
}
The thing I wanna achieve is similar like this:
http://blog.flash-core.com/?p=493
here's the google group thread
https://groups.google.com/forum/#!topic/haxelang/CF4ibEta5x4
I got little speed up in Builder.hx in buildShaderInfos method. I introduced local variables like here
https://github.com/profelis/dd/blob/master/dd/src/hxsl/Build.hx#L72
or here
https://github.com/profelis/dd/blob/master/dd/src/hxsl/Build.hx#L105
In my stress test I got 48-49 fps versus old 45 fps.
Btw, getVertexConstants and getFragmentConstants can be inlined for small speedup too
Something like https://github.com/andyli/puzzle
very usefull thing for lights, post effects, etc
I trying to compile HxSL with latest nightly version of 3.1.0 compiler and got an error:
/Users/fomkin/repos/thirdparty/hxsl/src/main/haxe/hxsl/Shader.hx:95: characters 11-12 : Unmatched patterns: TArray(_,_)
Very useful for batch, then one texture and one one shader render many times.
hi, ncannasse
Cannot compile the code.
You can provide h3d and hxsl under the haxe2.10 version?
thanks
D:\OpenSource\hxsl>haxe hxsl.hxml
hxsl/AgalCompiler.hx:724: characters 26-40 : Identifier 'TIgnoreSampler' is not
part of enum format.agal.TexFlag
hxsl/AgalCompiler.hx:724: characters 26-40 : For function argument 'x'
hxsl/AgalCompiler.hx:724: characters 26-40 : Identifier 'TIgnoreSampler' is not
part of enum format.agal.TexFlag
hxsl/AgalCompiler.hx:724: characters 26-40 : For function argument 'x'
It seems I have to combine all vertexbuffer to one,and call shader.bind(buf)?
How I wish I could do this:
shader.bind(buf1,buf2,buf3)...
I've got this when I try to run samples:
C:\Motion-Twin\Haxe\lib\hxsl/2,0/hxsl/Shader.hx:145: characters 17-23 : Unknown identifier : VParam
When I change:
Shader.hx line 26
from: import hxsl.Data.Tools;
to: import hxsl.Data;
samples worked.
What is my problem?
Now, I get error with atf with alpha
Error #3606: Sampler 0 format does not match texture format.
Looks like agal assembler some changed https://github.com/PrimaryFeather/Starling-Framework/commits/master/starling/src/com/adobe/utils/AGALMiniAssembler.as
class TestShader extends Shader {
var SRC = {
var matr:M44;
function vertex() {
out = [1, 1, 1, 1]*matr[0];
}
function fragment() {
out = [1,1,1,1];
}
};
}
Build.hx file (line 117)
if( vcount >> 2 >= format.agal.Tools.getProps(RConst, !shader.vertex).count )
Must be:
if( vcount >> 2 > format.agal.Tools.getProps(RConst, !shader.vertex).count )
We have 128 registers, not 127.
It would be great if HXSL was available on haxelib, so that it can be specified as a dependency.
In the file Shader.hx in the method unbind on line 321 at says:
ctx.setTextureAt(k, i.textures[k]);
After modify that line to:
ctx.setTextureAt(k, null);
the method unbind works as expected.
Because haxelib's format is not up to sync for format.agal...
Can you please release a new format version ?
thx
/home/bruno/.haxe/lib/hxsl/2,0,3/hxsl/AgalCompiler.hx:178: lines 178-181 : Object requires field version
/home/bruno/.haxe/lib/hxsl/2,0,3/hxsl/AgalCompiler.hx:120: lines 120-182 : Missing return format.agal.Data
This breaks new Flambe installs and anything else that depends on hxsl. :(
Do you think you could explicitly specify the dependency version in haxelib.json to prevent this from happening again in the future?
Something like
var uv:Float2;
function fragment(data:TextureFlags, tex:Texture2D)
{
out = tex.get(uv, data);
}
class PicoBuild {
macro public
// remove @ before macro
var decls = ["override function getData() return '"+s+"';",];
// add ";" at end
at PicoShaderInstance
for ( v in data.vars ) {
// replace with
var allVars = Tools.getAllVars(data);
for ( v in allVars ) {
Looks like Pico*-branch not supported?
Now realtypes are fixed in Build.hx
Will be great call something
Build.setRealType(TFloat3, "my.math.Float3");
hxsl/Parser.hx:516: characters 7-13 : This constructor is not part of the enum haxe.macro.ExprDef
after fix this bug
haxe hxsl.hxml
hxsl/RuntimeCompiler.hx:508: characters 3-49 : Invalid field access : length
hxsl/RuntimeCompiler.hx:549: characters 9-35 : Called from
hxsl/RuntimeCompiler.hx:540: characters 12-19 : Called from
hxsl/RuntimeCompiler.hx:566: characters 37-44 : Called from
hxsl/RuntimeCompiler.hx:257: characters 35-42 : Called from
hxsl/RuntimeCompiler.hx:171: characters 3-32 : Called from
hxsl/RuntimeCompiler.hx:70: characters 11-24 : Called from
test/Main.hx:28: characters 9-57 : Called from
test/Main.hx:41: characters 7-20 : Called from
test/Main.hx:40: characters 2-5 : Called from
test/Main.hx:129: lines 129-145 : Called from
Aborted
Mac os 10.7.3
$ haxe
Haxe Compiler 2.10 - (c)2005-2012 Motion-Twin
haxelib info format
Name: format
Tags: abc, amf, cross, flv, gz, mp3, pbj, pdf, swf, tar, zip
Desc: A haXe Library for supporting different file formats.
Website: http://code.google.com/p/hxformat
License: BSD
Owner: ncannasse
Version: 1.23.2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.