www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: MichaelJPCT on August 12, 2020, 12:46:15 pm

Title: trying to get default shader code
Post by: MichaelJPCT on August 12, 2020, 12:46:15 pm
hi Egon,
i try to modify some code of default shader by java programming.
when i call getshadercode , program crashes, but my app can work with default shader, why?
my code is like this:
locator=glslshader.getshaderlocator();
String s=locator.getshadercode("defaultVertexShaderFog.src");
Title: Re: trying to get default shader code
Post by: AeroShark333 on August 12, 2020, 10:34:09 pm
I think you need to set the shader locator before being able to use it... It probably throws a NullPointerException as a crash now. I'm not sure how this entirely works in the first place either...

I think there should be a way to still access the default shader code. I believe because these shader files are in the base of the jar library, they'd also go to the base of the apk file. I think you should be able to use these shader text files from there.

I believe the best way to alter the default shaders is to re-use them by copying.
That means to extract the jPCT-AE jar using a zip-extractor like WinRAR or something. In here you can find the shaders in plain text.
Copy two shaderfiles (vertex+fragment), which you need, to your Android project.
You can edit these text files and load them into a new GLSLShader as you want.
Title: Re: trying to get default shader code
Post by: MichaelJPCT on August 13, 2020, 06:31:09 am
hi,
i know i can get code from jar file using winrar, but that's not my intention.
i want to let my app read shader code then modify something in it , then create another shader.
now the problem is how to read the source code into my java program.
Title: Re: trying to get default shader code
Post by: AeroShark333 on August 13, 2020, 09:26:51 am
I tried something that worked for me, the difference is the "/" in the filename.
So I suggest you to give this a try:
Code: [Select]
String shader = new ShaderLocator().getShaderCode("/defaultVertexShaderFog.src");
Alternatively:
Code: [Select]
final InputStream is = getClass().getResourceAsStream("/defaultVertexShaderFog.src");
String shader = Loader.loadTextFile(is);

Nonetheless, I suppose it would have been nice if the library gave an output of what went wrong instead of crashing on null InputStream...
Title: Re: trying to get default shader code
Post by: MichaelJPCT on August 13, 2020, 07:58:53 pm
adding "/" to file name solved my problem, thank you !
Title: Re: trying to get default shader code
Post by: MichaelJPCT on August 15, 2020, 11:28:19 am
first thing i change is the specular effect.
(https://i.ibb.co/MfMs4jc/specular.jpg) (https://ibb.co/MfMs4jc)
Title: Re: trying to get default shader code
Post by: AeroShark333 on August 15, 2020, 06:45:44 pm
Oh that's cool!

Did you change the shininess value or implement a different lighting algorithm altogether?
Not sure if the shininess value could've been altered from the GLSLShader.setUniform method though...
Title: Re: trying to get default shader code
Post by: MichaelJPCT on August 15, 2020, 08:13:01 pm
i just removed the WHITE color restriction and multiplied the pow() output by a value larger than 1 (say 5 or 10).
fragment shader is not changed at all.
but the texture color can't be 0, or the result is still 0.
this is a simple method. not much research was done.
some other engines use more complex methods.
Title: Re: trying to get default shader code
Post by: AeroShark333 on August 15, 2020, 11:06:36 pm
Hmmm oh, I thought it was generally good practice to make sure the gl_FragColor values are between 0.0 and 1.0.
I don't think it'd hurt to multiply the specular lighting so much but I believe some devices might produce different results if the final value for gl_FragColor isn't limited by 'WHITE'.
I believe keeping the WHITE limit would still produce the same results as now? I'm not sure though
Title: Re: trying to get default shader code
Post by: MichaelJPCT on August 16, 2020, 06:41:48 am
white limit was in default vertex shader. i removed that one.
in fragment shader a white limit can be added, i haven't though.
i tested on mali 450 and powerVR 6250, both results correct.
Title: Re: trying to get default shader code
Post by: EgonOlsen on August 17, 2020, 07:22:29 am
There are some devices/drivers that will give you a black texture when these values exceed 1.0.
Title: Re: trying to get default shader code
Post by: MichaelJPCT on August 17, 2020, 01:01:14 pm
then i 'd better add a limit at the output of fragment shader.
the output vertexcolor of vertex shader should not matter because it's just another varying value passing from vertex shader to fragment shader.