www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Thomas. on October 29, 2012, 12:13:14 pm

Title: Shader preprocessor
Post by: Thomas. 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
Title: Re: Preprocessor shader
Post by: Thomas. 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
Title: Re: Shader preprocessor
Post by: EgonOlsen 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?
Title: Re: Shader preprocessor
Post by: Thomas. 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...
Title: Re: Shader preprocessor
Post by: EgonOlsen 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.
Title: Re: Shader preprocessor
Post by: Thomas. on November 05, 2012, 08:15:59 pm
Yes, you are right, I got it wrong...
Title: Re: Shader preprocessor
Post by: Thomas. 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
Title: Re: Shader preprocessor
Post by: EgonOlsen 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...
Title: Re: Shader preprocessor
Post by: Thomas. on November 06, 2012, 08:45:20 pm
I have it. I was sending old VS without #define ... line to the GPU ::)