Giter Club home page Giter Club logo

glsl2agal's People

Contributors

agd5f avatar airlied avatar amaasikas avatar anholt avatar aras-p avatar bnf avatar brianpaul avatar curro avatar cworth-gh avatar dbnicholson avatar gsapountzis avatar ianromanick avatar ickle avatar jonsmirl avatar jrfonseca avatar kaydenl avatar krh avatar luca-barbieri avatar marekolsak avatar mcencora avatar mostawesomedude avatar nhaehnle avatar olvaffe avatar suokko avatar versalinyaa avatar wallbraker avatar xhaihao avatar ymanton avatar zackr avatar zounanhai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glsl2agal's Issues

Fails to compile in certain scenarios when "Optimize" is enbaled

Fails to compile this piece of GLSL when "optimize" is enabled:

varying vec2 TexCoords;
void main()
{
    TexCoords = gl_MultiTexCoord0.xy;
    gl_Position = gl_Vertex;
}

Saying:

Error thrown by AGAL Assembler for vertex shader:
TypeError: Error #1009: Cannot access a property or method of a null object reference.Assembling AGAL fragment shader...

Problem with a function that can be inlined

glsl2agal fails with the conversion of glsl code posted below. If I inline the function atanSurrogate everything goes well, otherwise I get "Internal error" exception in RegisterAssigner.assignRegisters(). I am also not sure if I should implement inverse trigonometric functions on my own, maybe some not working approximations are provided?

Vertex shader does nothing (this is a 2D effect). Here is a fragment shader:

ifdef GL_ES

precision highp float;

endif

uniform float time;
uniform vec2 resolution;

float u( float x )
{
if (x > 0.0) return 1.0;
else return 0.0;
}

float atanSurrogate(float y, float x)
{
float z = y/x;
float ab = abs(z);
float res;

if (ab<0.9626995623)
{
    return z/(1.0 + 0.28*z*z);
}
else if(ab > 1.094294782)
{
    res = - z/(z*z + 0.28);

    if (z>0.0) return res + 3.14159/2.0;
    else return res - 3.14159/2.0;
}
else
{
    res = 0.5*z;
    if (z>0.0) return res + 0.283;
    else return res - 0.283;
}

}

void main(void)
{
vec2 p = (2.0*gl_FragCoord.xy-resolution)/resolution.y;

float a = atanSurrogate(p.x, p.y);

float r = length(p)*.75;

float w = cos(3.1415927*time-r*2.0);
float h = 0.5+0.5*cos(12.0*a-w*7.0+r*8.0);
float d = 0.25+0.75*pow(h,1.0*r)*(0.7+0.3*w);

float col = u( d-r ) * sqrt(1.0-r/d)*r*2.5;
col *= 1.25+0.25*cos((12.0*a-w*7.0+r*8.0)/2.0);
col *= 1.0 - 0.35*(0.5+0.5*sin(r*30.0))*(0.5+0.5*cos(12.0*a-w*7.0+r*8.0));
gl_FragColor = vec4(
    col,
    col-h*0.5+r*.2 + 0.35*h*(1.0-r),
    col-h*r + 0.1*h*(1.0-r),
    1.0);

}

Is this fork still active?

Hello team! (ping @alexmac),
My name is Fil and I’m from Adobe’s Open Source Office. I see this fork has been inactive for a long time (5+ years). Just wondering: is there still value in keeping this fork around? Do we foresee community usage/activity happening around this project? I see there have been issues filed by the community, but, as I said, it's been a while since there has been any activity here.

If no, is it OK if we delete this fork?

Thanks for any info.

-Fil

Syntax Error: Unterminated quoted string

I get the following error when I try to run the command on Linux:

./bin/glsl2agalopt -optimize -f input/shader.fs
./bin/glsl2agalopt -optimize -v input/shader.vs

./bin/glsl2agalopt: 1: ./bin/glsl2agalopt: Syntax error: Unterminated quoted string
./bin/glsl2agalopt: 1: ./bin/glsl2agalopt: Syntax error: Unterminated quoted string

And I use the sample shaders:

//shader.fs
varying vec4 vertexColor;
void main()
{
    gl_FragColor = vertexColor;
}
//shader.vs
varying vec4 vertexColor;
void main()
{
    vertexColor = gl_Color;
    gl_Position = ftransform();
}

How do I fix this?

Many matrix operations are translated into illegal AGAL code

void main()
{
mat4 m = mat4(1.0);
gl_Position = m * gl_Vertex;
}

yields

mul op.xyzw, mat4(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0), va0.xyzw


attribute vec3 _normal;
attribute vec3 _binormal;
attribute vec3 _tangent;

void main()
{
mat3 m = mat3(_normal, _binormal, _tangent);
gl_Position = vec4(m * vec3(1, 0, 0), 1);
}

yields

mov vt0.xyz, va0.xyzz
mov vt0.xyz, va1.xyzz
mov vt0.xyz, va2.xyzz
mov vt0.w, vc0.xxxx
m33 vt0.xyz, vc0.xyzz, vt0
mov op.xyzw, vt0.xyzw

It keeps overwriting vt0. This also happens with a mat4.


void main()
{
mat4 modelViewTranspose = transpose(gl_ModelViewMatrix);
gl_Position = modelViewTranspose * vec4(0, 0, 0, 1);
}

yields

mov vt0.x, vc0.xxxx
mov vt1.x, vc0.yyyy
mov vt2.x, vc0.zzzz
mov vt3.x, vc0.wwww
mov vt0.y, vc1.xxxx
mov vt1.y, vc1.yyyy
mov vt2.y, vc1.zzzz
mov vt3.y, vc1.wwww
mov vt0.z, vc2.xxxx
mov vt1.z, vc2.yyyy
mov vt2.z, vc2.zzzz
mov vt3.z, vc2.wwww
mov vt0.w, vc3.xxxx
mov vt1.w, vc3.yyyy
mov vt2.w, vc3.zzzz
mov vt3.w, vc3.wwww

mul op.xyzw, vt0, vc4.xyzw

The transpose seems to be correct, but it uses mul instead of m44.


uniform mat4 _modelMatrix;
uniform mat4 _viewMatrix;

void main()
{
mat4 modelView = _viewMatrix * _modelMatrix;
gl_Position = modelView * vec4(0, 0, 0, 1);
}

yields

mov vt0.xyzw, vc0
mul vt4.xyzw, vt0, vc4
m44 op.xyzw, vc8.xyzw, vt4

This is not a matrix multiplication.

Regards,
Georg

?: conditional operator conversion bug

It seems to me that glsl2agal has problem with proper conversion of glsl expressions using ?: operator. Problem is manifested by 'component read without being written to'. I am using swc available at the moment of speaking.

Code generation problem

This glsl code:

#version 100

attribute vec3 vertexPosition;
attribute vec2 texPosition;
uniform mat4 projectionMatrix;
varying vec2 texCoord;

void main() {
    gl_Position = projectionMatrix * vec4(vertexPosition, 1.0);
    texCoord = texPosition;
    gl_Position.z = 0.5;
}

Generates this agal:

mov vt0.w, vc0.x
mov vt0.xyz, va0.xyzz
mov v0, vc0
mov v0.xy, va1.xyyy
m44 op, vt0, vc1
mov op, vc0
mov op.z, vc0.y

and these const fields:

"consts": {
"vc0": [
1,
0.5,
0,
0
]
}

The mov op, vc0 instruction (second last) does not seem to make any sense at all. After removing it the shader works as intended.

Instruction node present twice in ir tree

I get an error from a compiler when I multiply 2 vec4 with each other. If I do "xyz" multiplication and "w" multiplications separately, there's no error.
Error is:

Instruction node present twice in ir tree:(expression vec2 + (swiz xy (var_ref fc5) )(swiz xy (var_ref v0) ))
1 [sig] glsl2agalopt 81672 open_stackdumpfile: Dumping stack trace to glsl2agalopt.exe.stackdump
Result: 34304

Not sure what exactly affecting it, so pasted whole shader code:
This one doesn't work. Line causing error is 29:
http://pastie.org/5822150#29
This one do work:
http://pastie.org/5822153#29-30

Many thanks.

length, distance, normalize return wrong result for certain vectors.

length() method only works for vec4.

varying vec2 texcoord0;

float l = length(texcoord0);

yields

dp4 ft1.x, v0.xyyy, v0.xyyy
sqt ft1.z, ft1.xxxx

So it calculates
sqrt(x_x + y_y + y_y + y_y)

Most likely distance() is also wrong (haven't checked).


varying vec2 texcoord0;

vec2 tc = normalize(texcoord0);

yields

nrm ft1.xy, v0.xyyy

Error #3628: AGAL validation failed: The destination operand for the nrm instruction must mask w (use .xyz or less) at token 2 of fragment program.

Swizzling not working like in AGALMiniAssembler

Compiling this fragment shader:

uniform float myConstant;
void main(void)
{
    gl_FragColor = vec4(myConstant, 0.0, 0.0, 1.0);
}

results in this AGAL asm code:

mov ft0.yzw, fc0.xyzz
mov ft0.x, fc1.x
mov oc, ft0

where fc0 = [0, 0, 1, 0]

When compiling with AGALMiniAssembler, apparently

mov ft0.yzw, fc0.xyzz 

is the same as

mov ft0.y, fc0.y
mov ft0.z, fc0.z
mov ft0.w, fc0.z

resulting in ft0 = [myConstant, 0, 1, 1]. The expected result would have been ft0 = [myConstant, 0, 0, 1].

I found this blog where the topic is discussed: http://gonchar.me/blog/goncharposts/1466

Multiple y per register?

Hi there,

Thanks for such a great tool!

I am having some problems converting a vertex shader, the original glsl looks like this:

attribute vec2 pos;
attribute vec4 aVertexColor;

        varying vec4 vColor;

        void main(void) {
            gl_Position = vec4(pos.x, pos.y, 0.0, 1.0);
            vColor = aVertexColor;
        }

Which translates to:

mov vt0.zw, vc0.xyyy
mov vt0.x, va0.x
mov vt0.y, va0.y
mov op, vt0
mov v0, va1

I am having difficulties to render the triangle with this agal code, although the render works perfectly with this other one:

m44 op, va0, vc0
mov v0, va1

Maybe it's just a newbie mistake.

Thanks!!

In Stage3d the only way to configure the sampler seems to be through agal. How do we deal we that ?

Hi,

First of all thanks for this nice tool. coding in glsl make far much sense :)

In Stage3d the only way to configure the sampler seems to be through agal. How do we deal we that ?

For example, let say I want the sampler to have the nearest filter instead of the linear filter.
In agal I add "nearest" instead of "linear" in the sampler options but since here the agal is generated from glsl, how can I specify to use nearest filter. Should we add this to the json config so that if you wanted to use the glsl on its own (in a native app) the native app could read that json and figure out what filter (or other sampler option) to apply?

Or maybe there a way to do it in glsl?

Thanks

Combining multiple non-vec4 constants

Would be cool if compiler could combine multiple contstants(unifoms) together in one vec4, and then tell in meta data which ones are where.
Right now for example if you have 4 uniform floats, compiler will put them in 4 different constants at position 0(x)

conditional branching

Conditional branching is available in extended profile in Flash 11.8 beta
along with rectangle textures and 4096 max texture size.

Is anybody currently working on adding this so we can get full conditional support.

slt and sge just do not get the same effect.

AGAL validation failed: Temporary register read without being written to

Hi, I just got the latest compiled swc, but encountered a compiler bug:

source:
uniform vec4 g_ViewMatrixInvVec;
uniform mat4 g_ShadowMapMatrix;
uniform vec4 g_ParametersPS;
uniform sampler2D depth;
uniform sampler2D normal;
void main()
{
gl_FragColor = vec4(texture2D(normal, gl_TexCoord[0].xy).g > 0.25f ? 1.f : 0.5f, 1, 0, 0);
};

compiled code:
tex ft1, v0.xyyy, fs0 <2d clamp linear nomip>
slt ft0.x, fc0.x, ft1.y
sub ft1.x, fc0.y, ft0.x
mul ft3.z, ft3.z, ft1.x
add ft3.z, ft3.z, ft0.x
sub ft2.x, fc0.y, ft0.x
sub ft1.y, fc0.y, ft2.x
mul ft3.z, ft3.z, ft1.y
mul ft1.z, fc0.z, ft2.x
add ft3.z, ft3.z, ft1.z
mov ft0.yzw, fc1.xyzz
mov ft0.x, ft3.z
mov oc, ft0

mul ft3.z, ft3.z, ft1.x has used ft3 which is undefined.

Cygwin independent windows binary

Hi,
I'm trying to make ant job which will compile all my shaders. But binary provided, requires cygwin. I have cygwin installed, but not sure how to run in ant using cygwin libraries? is it possible? Is it possible to do cygwin independent build with all libraries included?

Possible sat optimisation?

GLSL doesn't have a saturate function - so I'm using clamp( value, 0.0, 1.0 ) instead. Currently this is being compiled down to a pair of min/max instructions, and requires the use of an additional temporary register (Something I can't afford in complex shaders).

As AGAL supports sat, would it be possible to reduce this case down to a single instruction?

can't use the compiled swc

Both examples (starling and proscenium) can't find C_Run(.initLib, CModule, initLib, compileShader) etc. I also can't expand the glsl2agal.swc. Are the examples meant to work after just setting the correct classpaths?

Edit: this seems to be a fdt issue: it compiled and worked, although the swc was not recognized. Other swc's made with alchemy 2 had the same problem.

Any plan to reduce register usage?

Hello, we have some complex shader(deferred lighting process) that fails to compile because of the 9th temporary register was used. My work mate was trying to name the register like vec4 temp0, temp1, .., temp7 and reuse them in GLSL, but without a success.

The same shader logic can work in AGAL assembly.

AGAL has a very restrictive temporary register set and weak instructions(no modifiers, for example), but better instruction count limit than ps_2_0, I think a trade off between instruction count and register count should be acceptable. Is there any plans to optimize register further? Would be very beneficial to quick development.

Thanks,

Optimization throws exception

uniform sampler2D _diffuseMap;
varying vec2 texcoord0;

void main()
{
vec4 diffuseColor = texture2D(_diffuseMap, texcoord0);
if (diffuseColor.a < 0.1)
discard;

gl_FragColor = vec4(diffuseColor.rgb, diffuseColor.a);

}

compileShader(glslSource, false, true, false) is throwing

[Fault] exception, information=Error: Expected token not seen was: ft1

Without optimization it works. The unoptimized AGAL code is:

tex ft0.xyzw, v0.xyyy, fs0 <2d,wrap,linear>
slt ft1.x, ft0.wwww, fc0.xxxx
neg ft1.x ft1.x
kil ft1.x

mov ft1.xyz, ft0.xyzz
mov ft1.w, ft0.wwww
mov oc.xyzw, ft1.xyzw

Regards,
Georg

Unable to compile shaders

When trying to compile the following fragment shader:

varying vec3 vColor;
void main() {
    gl_FragColor = vColor;
}

I get the following errors in the info property from the returned JSON object:

0:2(20): error: invalid type `vec3' in declaration of `vColor'
0:4(11): error: function `main' has undeclared return type `void'
0:4(11): error: main() must return void
0:5(23): error: `vColor' undeclared
0:5(15): error: type mismatch
0:6(2): error: function `main' has non-void return type (null), but no return statement

I'm using the swc from the repository and I'm compiling it using FlashDevelop 4.0.4 (AS3 project, using Flash 11.3 as target). Are there any compiler options needed for this to function properly?

Feature request: Support for AGAL MRT

Could we get gl_FragData[n] mapped to oc?

I'm currently playing with the extended profile preview, and it'd be great to be able to use this tool to start targeting upcoming features.

Can't compile shader with struct uniform

Sample shader:

struct Foo
{
float bar1;
float bar2;
};

uniform Foo uFoo;

void main()
{
gl_Position.x = uFoo.bar1;
gl_Position.y = uFoo.bar2;
}

Output will be:

{
"info":"\nstructs still exist.\n\nstructs still exist.\n"
}

I can't understand what does this error mean. Could it be that struct uniforms isn't supported at all?

Using dot production results in unexpected AGAL code

Hi,

Using the dot operation results in unexpected AGAL code at least in this case:

varying vec4 vNormal;           
uniform vec3 color;
uniform vec3 directionalLight;

void main(void)
{
   vec3 normalizedNormal = normalize(vNormal.xyz);
   float lpow = dot(normalizedNormal, directionalLight);
   gl_FragColor = vec4(lpow * color, 1.0);
}

Result:

nrm ft0.xyz, v0.xyzz
dp3 ft0.x, ft0.xyyy, fc1.xyyy  <--- Why not ft0.xyzz, fc1.xyzz?
mul ft0, ft0.x, fc2
mov ft0.w, fc0.x
mov oc, ft0

The resulting dp3 operation doesn't include the z component. Why is this happening?

Flascc compiler error? (java.lang.NullPointerException)

Hi, we are able to use glsl2agal in our as3-only project. But when we want to link with flascc code, compiling fails:

java.lang.NullPointerException
at com.adobe.flash.compiler.internal.scopes.ASProjectScope.getCompilationUnitForDefinition(ASProjectScope.java:1358)
at com.adobe.flash.compiler.internal.scopes.ASProjectScope.removeDefinition(ASProjectScope.java:1123)

...(detailed error list can be seen here as well: http://forums.adobe.com/thread/1134928)

Could you give us some ideas?
Thanks very much!

vertex attribute order be changed

Here is my GLSL, POSITION is the first attribute and NORMAL should be the forth attribute

uniform vec4 g_eyePosition;
uniform mat4 g_worldMatrix;
uniform mat4 g_worldViewProjectionMatrix;
attribute vec4 POSITION;
attribute vec4 COLOR0;
attribute vec2 TEXCOORD0;
attribute vec3 NORMAL;
varying vec4 xlv_COLOR0;
varying vec2 xlv_TEXCOORD0;
varying vec3 xlv_TEXCOORD1;
varying vec3 xlv_TEXCOORD2;
void main ()
{
vec4 tmpvar_1;
tmpvar_1 = (g_worldViewProjectionMatrix * POSITION);
vec4 tmpvar_2;
tmpvar_2.w = 0.0;
tmpvar_2.xyz = NORMAL;
gl_Position = tmpvar_1;
xlv_COLOR0 = COLOR0;
xlv_TEXCOORD0 = TEXCOORD0;
xlv_TEXCOORD1 = (g_worldMatrix * tmpvar_2).xyz;
xlv_TEXCOORD2 = normalize((g_eyePosition.xyz - tmpvar_1.xyz));
}

But after after glsl2agal compiler the vertex attribute be like bottom text, POSITION be shifted to the va1, and NORMAL on the va0.

"COLOR0": "va2",
"unnamed_3": "vt2",
"g_worldViewProjectionMatrix": "vc1",
"POSITION": "va1",
"TEXCOORD0": "va3",
"gl_Position": "op0",
"g_worldMatrix": "vc5",
"g_eyePosition": "vc9",
"NORMAL": "va0",
"unnamed_0": "vc0"

Inverse parser?

Is there an inverse parser? Trying to implement the output from this into GLS3D but i need to know if there is an inverse parser? Or will I have to write my self one?

Also in order to compile the standalone converter without the agal optimizer, I needed to add the contrib folder from a fork. Might be interesting to add it to the master branch?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.