trying to get default shader code

Started by MichaelJPCT, August 12, 2020, 12:46:15 PM

Previous topic - Next topic

MichaelJPCT

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");

AeroShark333

#1
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.

MichaelJPCT

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.

AeroShark333

#3
I tried something that worked for me, the difference is the "/" in the filename.
So I suggest you to give this a try:
String shader = new ShaderLocator().getShaderCode("/defaultVertexShaderFog.src");

Alternatively:
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...

MichaelJPCT

adding "/" to file name solved my problem, thank you !

MichaelJPCT

first thing i change is the specular effect.

AeroShark333

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...

MichaelJPCT

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.

AeroShark333

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

MichaelJPCT

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.

EgonOlsen

There are some devices/drivers that will give you a black texture when these values exceed 1.0.

MichaelJPCT

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.