Changeset 1392


Ignore:
Timestamp:
May 14, 2012, 9:46:28 PM (11 years ago)
Author:
sam
Message:

misc: move more shaders to .lolfx files.

Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/.gitignore

    r1383 r1392  
    1414.libs
    1515.deps
     16.dirstamp
    1617Makefile
    1718Makefile.in
  • trunk/orbital/shiny.lolfx

    r1390 r1392  
    4242    vec3 light = ambient + diffuse + specular;
    4343
    44     vec4 real_color = in_Damage * vec4(1.2, 0.2, 0.2, 1.0)
     44    vec4 real_color = in_Damage * vec4(1.2, 1.2, 1.2, 1.0)
    4545                    + (1.0 - in_Damage) * in_Color;
    4646    pass_Color = real_color * vec4(light, 1.0);
  • trunk/test/tutorial/02_cube.cpp

    r1326 r1392  
    2727#   include <direct.h>
    2828#endif
     29
     30extern char const *lolfx_02_cube;
    2931
    3032class Cube : public WorldEntity
     
    8284        if (!m_ready)
    8385        {
    84             m_shader = Shader::Create(
    85 #if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9
    86                 "#version 120\n"
    87                 "attribute vec3 in_Vertex;"
    88                 "attribute vec3 in_Color;"
    89                 "uniform mat4 in_Matrix;"
    90                 "varying vec3 pass_Color;"
    91                 ""
    92                 "void main(void) {"
    93                 "    gl_Position = in_Matrix * vec4(in_Vertex, 1.0);"
    94                 "    pass_Color = in_Color;"
    95                 "}",
     86            m_shader = Shader::Create(lolfx_02_cube);
    9687
    97                 "#version 120\n"
    98                 "varying vec3 pass_Color;"
    99                 ""
    100                 "void main(void) {"
    101                 "    gl_FragColor = vec4(pass_Color, 1.0);"
    102                 "}"
    103 #else
    104                 "void main(float3 in_Vertex : POSITION,"
    105                 "          float3 in_Color : COLOR,"
    106                 "          uniform float4x4 in_Matrix,"
    107                 "          out float4 out_Position : POSITION,"
    108                 "          out float3 pass_Color : COLOR) {"
    109                 "    pass_Color = in_Color;"
    110                 "    out_Position = mul(in_Matrix, float4(in_Vertex, 1.0));"
    111                 "}",
    112 
    113                 "void main(float3 pass_Color : COLOR,"
    114                 "          out float4 out_FragColor : COLOR) {"
    115                 "    out_FragColor = float4(pass_Color, 1.0);"
    116                 "}"
    117 #endif
    118             );
    11988            m_mvp = m_shader->GetUniformLocation("in_Matrix");
    12089            m_coord = m_shader->GetAttribLocation("in_Vertex",
  • trunk/test/tutorial/03_fractal.cpp

    r1369 r1392  
    3737#   include <direct.h>
    3838#endif
     39
     40extern char const *lolfx_03_fractal;
    3941
    4042#if defined USE_D3D9
     
    479481#endif
    480482
    481             m_shader = Shader::Create(
    482 #if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9
    483 #   if !defined HAVE_GLES_2X
    484                 "#version 120\n"
    485 #   else
    486                 "precision highp float;"
    487 #   endif
    488                 ""
    489                 "uniform mat4 u_ZoomSettings;"
    490                 "uniform vec4 u_TexelSize;"
    491                 "uniform vec4 u_ScreenSize;"
    492                 ""
    493                 "attribute vec2 a_TexCoord;"
    494                 "attribute vec2 a_Vertex;"
    495                 ""
    496                 "varying vec4 v_CenterX, v_CenterY, v_IndexX, v_IndexY;"
    497                 ""
    498                 "void main(void)"
    499                 "{"
    500                 "    gl_Position = vec4(a_Vertex, 0.0, 1.0);"
    501                      /* Center point in [-.5,.5], apply zoom and translation
    502                       * transformation, and go back to texture coordinates
    503                       * in [0,1]. That's the ideal point we would like to
    504                       * compute the value for. Then add or remove half the
    505                       * size of a texel: the distance from this new point to
    506                       * the final point will be our error. */
    507                 "    vec4 offsets = vec4(0.5, -0.5, 0.015625, -0.015625);"
    508                 "    vec4 zoomscale = vec4(u_ZoomSettings[0][2],"
    509                 "                          u_ZoomSettings[1][2],"
    510                 "                          u_ZoomSettings[2][2],"
    511                 "                          u_ZoomSettings[3][2]);"
    512                 "    vec4 zoomtx = vec4(u_ZoomSettings[0][0],"
    513                 "                       u_ZoomSettings[1][0],"
    514                 "                       u_ZoomSettings[2][0],"
    515                 "                       u_ZoomSettings[3][0]);"
    516                 "    vec4 zoomty = vec4(u_ZoomSettings[0][1],"
    517                 "                       u_ZoomSettings[1][1],"
    518                 "                       u_ZoomSettings[2][1],"
    519                 "                       u_ZoomSettings[3][1]);"
    520                 "    v_CenterX = zoomscale * a_TexCoord.x + zoomtx"
    521                 "              + offsets.xyxy * u_TexelSize.x;"
    522                 "    v_CenterY = zoomscale * a_TexCoord.y - zoomty"
    523                 "              + offsets.xyyx * u_TexelSize.y;"
    524                      /* Precompute the multiple of one texel where our ideal
    525                       * point lies. The fragment shader will call floor() on
    526                       * this value. We add or remove a slight offset to avoid
    527                       * rounding issues at the image's edges. */
    528                 "    v_IndexX = v_CenterX * u_ScreenSize.z - offsets.zwzw;"
    529                 "    v_IndexY = v_CenterY * u_ScreenSize.w - offsets.zwwz;"
    530                 "}",
    531 
    532 #   if !defined HAVE_GLES_2X
    533                 "#version 120\n"
    534 #   else
    535                 "precision highp float;"
    536 #   endif
    537                 ""
    538                 "uniform vec4 u_TexelSize;"
    539                 "uniform sampler2D u_Texture;"
    540                 ""
    541                 "varying vec4 v_CenterX, v_CenterY, v_IndexX, v_IndexY;"
    542                 ""
    543                 "void main(void)"
    544                 "{"
    545                 "    vec4 v05 = vec4(0.5, 0.5, 0.5, 0.5);"
    546                 "    vec4 rx, ry, t0, dx, dy, dd;"
    547                      /* Get a pixel coordinate from each slice into rx & ry */
    548                 "    rx = u_TexelSize.x + u_TexelSize.z * floor(v_IndexX);"
    549                 "    ry = u_TexelSize.y + u_TexelSize.w * floor(v_IndexY);"
    550                      /* Compute inverse distance to expected pixel in dd,
    551                       * and put zero if we fall outside the texture. */
    552                 "    t0 = step(abs(rx - v05), v05) * step(abs(ry - v05), v05);"
    553                 "    dx = rx - v_CenterX;"
    554                 "    dy = ry - v_CenterY;"
    555                 //"    vec4 dd = t0 * (abs(dx) + abs(dy));"
    556                 //"    vec4 dd = t0 / (0.001 + sqrt((dx * dx) + (dy * dy)));"
    557                 "    dd = t0 / (0.000001 + (dx * dx) + (dy * dy));"
    558                      /* Modify Y coordinate to select proper quarter. */
    559                 "    ry = ry * 0.25 + vec4(0.0, 0.25, 0.5, 0.75);"
    560                 ""
    561 #   if 1
    562                 "\n#if 0\n" /* XXX: disabled until we can autodetect i915 */
    563                      /* t1.x <-- dd.x > dd.y */
    564                      /* t1.y <-- dd.z > dd.w */
    565                 "    vec2 t1 = step(dd.xz, dd.yw);"
    566                      /* ret.x <-- max(rx.x, rx.y) wrt. t1.x */
    567                      /* ret.y <-- max(rx.z, rx.w) wrt. t1.y */
    568                      /* ret.z <-- max(ry.x, ry.y) wrt. t1.x */
    569                      /* ret.w <-- max(ry.z, ry.w) wrt. t1.y */
    570                 "    vec4 ret = mix(vec4(rx.xz, ry.xz),"
    571                 "                   vec4(rx.yw, ry.yw), t1.xyxy);"
    572                      /* dd.x <-- max(dd.x, dd.y) */
    573                      /* dd.z <-- max(dd.z, dd.w) */
    574                 "    dd.xy = mix(dd.xz, dd.yw, t1);"
    575                      /* t2 <-- dd.x > dd.z */
    576                 "    float t2 = step(dd.x, dd.y);"
    577                      /* ret.x <-- max(ret.x, ret.y); */
    578                      /* ret.y <-- max(ret.z, ret.w); */
    579                 "    ret.xy = mix(ret.xz, ret.yw, t2);"
    580                 "\n#else\n"
    581                      /* Fallback for i915 cards -- the trick to reduce the
    582                       * number of operations is to compute both step(a,b)
    583                       * and step(b,a) and hope that their sum is 1. This is
    584                       * almost always the case, and when it isn't we can
    585                       * afford to have a few wrong pixels. However, a real
    586                       * problem is when panning the image, because half the
    587                       * screen is likely to flicker. To avoid this problem,
    588                       * we cheat a little (see m_translate comment above). */
    589                 "    vec4 t1 = step(dd.xzyw, dd.ywxz);"
    590                 "    vec4 ret = vec4(rx.xz, ry.xz) * t1.zwzw"
    591                 "             + vec4(rx.yw, ry.yw) * t1.xyxy;"
    592                 "    dd.xy = dd.xz * t1.zw + dd.yw * t1.xy;"
    593                 "    vec2 t2 = step(dd.xy, dd.yx);"
    594                 "    ret.xy = ret.xz * t2.yy + ret.yw * t2.xx;"
    595                 "\n#endif\n"
    596                      /* Nearest neighbour */
    597                 "    gl_FragColor = texture2D(u_Texture, ret.xy);"
    598 #   else
    599                      /* Alternate version: some kind of linear interpolation */
    600                 "    vec4 p0 = texture2D(u_Texture, vec2(rx.x, ry.x));"
    601                 "    vec4 p1 = texture2D(u_Texture, vec2(rx.y, ry.y));"
    602                 "    vec4 p2 = texture2D(u_Texture, vec2(rx.z, ry.z));"
    603                 "    vec4 p3 = texture2D(u_Texture, vec2(rx.w, ry.w));"
    604                 "    gl_FragColor = 1.0 / (dd.x + dd.y + dd.z + dd.w)"
    605                 "          * (dd.x * p0 + dd.y * p1 + dd.z * p2 + dd.w * p3);"
    606 #   endif
    607                 "}"
    608 #else
    609                 "void main(float2 a_Vertex : POSITION,"
    610                 "          float2 a_TexCoord : TEXCOORD0,"
    611                 "          uniform float4x4 u_ZoomSettings,"
    612                 "          uniform float4 u_TexelSize,"
    613                 "          uniform float4 u_ScreenSize,"
    614                 "          out float4 out_Position : POSITION0,"
    615                 "          out float4 v_CenterX : TEXCOORD0,"
    616                 "          out float4 v_CenterY : TEXCOORD1,"
    617                 "          out float4 v_IndexX : TEXCOORD2,"
    618                 "          out float4 v_IndexY : TEXCOORD3)"
    619                 "{"
    620                 "    out_Position = float4(a_Vertex, 0.0, 1.0);"
    621                 "    float4 offsets = float4(0.5, -0.5, 0.015625, -0.015625);"
    622                 "    float4 zoomscale = float4(u_ZoomSettings[2][0],"
    623                 "                              u_ZoomSettings[2][1],"
    624                 "                              u_ZoomSettings[2][2],"
    625                 "                              u_ZoomSettings[2][3]);"
    626                 "    float4 zoomtx = float4(u_ZoomSettings[0][0],"
    627                 "                           u_ZoomSettings[0][1],"
    628                 "                           u_ZoomSettings[0][2],"
    629                 "                           u_ZoomSettings[0][3]);"
    630                 "    float4 zoomty = float4(u_ZoomSettings[1][0],"
    631                 "                           u_ZoomSettings[1][1],"
    632                 "                           u_ZoomSettings[1][2],"
    633                 "                           u_ZoomSettings[1][3]);"
    634                 "    v_CenterX = zoomscale * a_TexCoord.x + zoomtx"
    635                 "              + offsets.xyxy * u_TexelSize.x;"
    636                 "    v_CenterY = zoomscale * a_TexCoord.y - zoomty"
    637                 "              + offsets.xyyx * u_TexelSize.y;"
    638                 "    v_IndexX = v_CenterX * u_ScreenSize.z - offsets.zwzw;"
    639                 "    v_IndexY = v_CenterY * u_ScreenSize.w - offsets.zwwz;"
    640                 "}",
    641 
    642                 "void main(in float4 v_CenterX : TEXCOORD0,"
    643                 "          in float4 v_CenterY : TEXCOORD1,"
    644                 "          in float4 v_IndexX : TEXCOORD2,"
    645                 "          in float4 v_IndexY : TEXCOORD3,"
    646                 "          uniform float4 u_TexelSize,"
    647                 "          uniform sampler2D u_Texture,"
    648                 "          out float4 out_FragColor : COLOR)"
    649                 "{"
    650                 "    float4 v05 = float4(0.5, 0.5, 0.5, 0.5);"
    651                 "    float4 rx, ry, t0, dx, dy, dd;"
    652                 "    rx = u_TexelSize.x + u_TexelSize.z * floor(v_IndexX);"
    653                 "    ry = u_TexelSize.y + u_TexelSize.w * floor(v_IndexY);"
    654                 "    t0 = step(abs(rx - v05), v05) * step(abs(ry - v05), v05);"
    655                 "    dx = rx - v_CenterX;"
    656                 "    dy = ry - v_CenterY;"
    657                 "    dd = t0 / (0.000001 + (dx * dx) + (dy * dy));"
    658                 "    ry = ry * 0.25 + float4(0.0, 0.25, 0.5, 0.75);"
    659                 "    float2 t1 = step(dd.xz, dd.yw);"
    660                 "    float4 ret = lerp(float4(rx.xz, ry.xz),"
    661                 "                      float4(rx.yw, ry.yw), t1.xyxy);"
    662                 "    dd.xy = lerp(dd.xz, dd.yw, t1);"
    663                 "    float t2 = step(dd.x, dd.y);"
    664                 "    ret.xy = lerp(ret.xz, ret.yw, t2);"
    665                 "    out_FragColor = tex2D(u_Texture, ret.xy);"
    666                 "}"
    667 #endif
    668             );
     483            m_shader = Shader::Create(lolfx_03_fractal);
     484
    669485            m_vertexattrib = m_shader->GetAttribLocation("a_Vertex", VertexUsage::Position, 0);
    670486            m_texattrib = m_shader->GetAttribLocation("a_TexCoord", VertexUsage::TexCoord, 0);
  • trunk/test/tutorial/Makefile.am

    r1385 r1392  
    2828
    292902_cube_SOURCES = 02_cube.cpp
     30nodist_02_cube_SOURCES = 02_cube.lolfx.cpp
    303102_cube_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
    313202_cube_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
     
    3334
    343503_fractal_SOURCES = 03_fractal.cpp
     36nodist_03_fractal_SOURCES = 03_fractal.lolfx.cpp
    353703_fractal_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
    363803_fractal_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
  • trunk/win32/02_cube.vcxproj

    r1380 r1392  
    3131  </ItemGroup>
    3232  <ItemGroup>
     33    <LolFxCompile Include="..\test\tutorial\02_cube.lolfx" />
     34  </ItemGroup>
     35  <ItemGroup>
    3336    <ProjectReference Include="lolcore.vcxproj">
    3437      <Project>{9e62f2fe-3408-4eae-8238-fd84238ceeda}</Project>
  • trunk/win32/03_fractal.vcxproj

    r1380 r1392  
    3131  </ItemGroup>
    3232  <ItemGroup>
     33    <LolFxCompile Include="..\test\tutorial\03_fractal.lolfx" />
     34  </ItemGroup>
     35  <ItemGroup>
    3336    <ProjectReference Include="lolcore.vcxproj">
    3437      <Project>{9e62f2fe-3408-4eae-8238-fd84238ceeda}</Project>
Note: See TracChangeset for help on using the changeset viewer.