Author Topic: Allowed shader types?  (Read 1825 times)

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Allowed shader types?
« on: March 11, 2014, 01:27:04 am »
Is it feasible to use shaders such as this for creating glassy effects? Or can JPCT only contain certain uniforms names?

// from the Orange Book 2nd edition

const float Eta = 0.66;
const float FresnelPower = 0.5;
const float F = ((1.0-Eta)*(1.0-Eta))/((1.0+Eta)*(1.0+Eta));

varying vec3 Reflect;
varying vec3 Refract;
uniform float Ratio;

void main()
{
    vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
    vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;

    vec3 i = normalize(ecPosition3);
    vec3 n = normalize(gl_NormalMatrix * gl_Normal);

    Ratio = F + (1.0 - F) * pow((1.0 - dot(-i, n)), FresnelPower);

    Refract = refract(i, n, Eta);
    Refract = vec3(gl_TextureMatrix[0] * vec4 (Refract, 1.0));

    Reflect = reflect(i, n);
    Reflect = vec3(gl_TextureMatrix[0] * vec4 (Reflect, 1.0));

    gl_Position = ftransform();
}








Fragment shader


// from the Orange Book 2nd edition

varying vec3 Reflect;
varying vec3 Refract;
uniform float Ratio;

uniform sampler2D MyTex;

void main (void)
{
vec3 refractColor = vec3(texture2D( MyTex, Refract));
vec3 reflectColor = vec3(texture2D( MyTex, Reflect));

vec3 color = mix(refractColor, reflectColor, Ratio);

gl_FragColor = vec4(color, 1.0);
}




Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Allowed shader types?
« Reply #1 on: March 11, 2014, 08:53:09 am »
There are some default names for certain uniforms, but you can add as many others as you wish (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/GLSLShader.html#setUniform(java.lang.String, float)). However, that particular shader won't work on Android, because it uses gl_XXX and stuff that isn't available on Android. One has to convert it to use jPCT-AE's build in replacements for these first.

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Allowed shader types?
« Reply #2 on: March 13, 2014, 01:38:20 am »
Is their a page with a list of the acceptable keywords? I think i found it before but im having difficulty finding it again.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Allowed shader types?
« Reply #3 on: March 13, 2014, 10:09:55 am »
Here are the default uniforms:  http://www.jpct.net/jpct-ae/doc/com/threed/jpct/GLSLShader.html

You are free to use any other names for your own stuff.