Author Topic: trying to get default shader code  (Read 3412 times)

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
trying to get default shader code
« 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");

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: trying to get default shader code
« Reply #1 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.
« Last Edit: August 12, 2020, 10:42:35 pm by AeroShark333 »

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: trying to get default shader code
« Reply #2 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.

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: trying to get default shader code
« Reply #3 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...
« Last Edit: August 13, 2020, 09:34:43 am by AeroShark333 »

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: trying to get default shader code
« Reply #4 on: August 13, 2020, 07:58:53 pm »
adding "/" to file name solved my problem, thank you !

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: trying to get default shader code
« Reply #5 on: August 15, 2020, 11:28:19 am »
first thing i change is the specular effect.

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: trying to get default shader code
« Reply #6 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...

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: trying to get default shader code
« Reply #7 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.

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: trying to get default shader code
« Reply #8 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

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: trying to get default shader code
« Reply #9 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: trying to get default shader code
« Reply #10 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.

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: trying to get default shader code
« Reply #11 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.