Author Topic: Shader preprocessor  (Read 1352 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Shader preprocessor
« on: October 29, 2012, 12:13:14 pm »
Please, is there anyone who knows a library that works with this?

Code: [Select]
#if USE_FOG
...shader code...
#endif
« Last Edit: November 03, 2012, 06:36:32 pm by Thomas. »

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Preprocessor shader
« Reply #1 on: November 03, 2012, 06:34:48 pm »
By GLSL ES specification it is supported. Could you implement it into jPCT-AE, please?

http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Shader preprocessor
« Reply #2 on: November 03, 2012, 07:57:24 pm »
I'm not sure what you mean!? I don't care about what the compiler does or does not, i'm just feeding the source code directly into the driver. What am i supposed to implement?
« Last Edit: November 03, 2012, 08:07:09 pm by EgonOlsen »

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Shader preprocessor
« Reply #3 on: November 03, 2012, 09:52:24 pm »
Preprocessor on page 11 :) It should be integrated in GPU, if I understood it correctly... I have to somehow send variables together with shader...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Shader preprocessor
« Reply #4 on: November 03, 2012, 10:23:16 pm »
... I have to somehow send variables together with shader...
I don't think so. You can define something in the source code and then ask somewhere else if it has been defined and stuff like that. Like in C/C++...correct me, if i'm wrong.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Shader preprocessor
« Reply #5 on: November 05, 2012, 08:15:59 pm »
Yes, you are right, I got it wrong...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Shader preprocessor
« Reply #6 on: November 06, 2012, 07:34:50 pm »
And please, have you idea, how it should be used? Now, I have in VS code for fog, even if is not needed in FS (FS is dynamically generated). I want leave out calculation of fog, if is not needed. So I did this....

Code: [Select]

...
        #ifdef USE_FOG
varying vec3 fogVertexColor;
varying float fogWeight;
#endif
...
#ifdef USE_FOG
fogWeight = clamp((-v_Position.z - fogStart) / (fogEnd - fogStart), 0.0, 1.0);
fogVertexColor = fogColor * fogWeight;
#endif

And if I need fog, I add "#define USE_FOG" on the first line of VS and FS, but it not works when I turn on fog.
Code: [Select]
11-06 15:40:34.768: I/jPCT-AE(11566): [ 1352212834770 ] - ERROR: Could not link shader program: L0008 Varying 'fogWeight' not found in vertex shader

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Shader preprocessor
« Reply #7 on: November 06, 2012, 08:26:05 pm »
No idea...looks fine to me, but then again, i don't trust my own understanding of these preprocessor commands nor the shader compilers on mobile devices. I would try to use two #define like USE_FOG and USE_FOG2 and then use the first on in the first #ifdef and the second one in the second. Just to see what happens then...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Shader preprocessor
« Reply #8 on: November 06, 2012, 08:45:20 pm »
I have it. I was sending old VS without #define ... line to the GPU ::)