用于OpenGL ES Android的GLSL

问题描述 投票:1回答:3

我想在我的OpenGL对象上使用阴影,但是似乎无法访问我的opengl包中的GLSL函数。是否有GLSL软件包可用于Eclipse中的OpenGL ES?

EDIT:正如Tim所指出的。着色器被编写为文本文件,然后使用glShaderSoure加载,我有一个C ++着色器文件,我曾经为光线跟踪应用程序编写过一次。但是,我对如何实现Java感到非常困惑。假设我在我的Renderer类中使用gl对象MySquare绘制了一个2D正方形,如何实现下面的着色器文件的Java等效项。

Shader.vert

     varying vec3 N;
     varying vec3 v;

void main()
{

// Need to transform the normal into eye space.
N = normalize(gl_NormalMatrix * gl_Normal);


// Always have to transform vertex positions so they end
// up in the right place on the screen.
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

  // Fragment shader for per-pixel Phong interpolation and shading.

Shader.Frag

// The "varying" keyword means that the parameter's value is interpolated
// between the nearby vertices.
varying vec3 N;
varying vec3 v;

//Used for Environmental mapping shader calculations
const vec3 xUnitVec=vec3(1.0, 0.0, 0.0), yUnitVec=vec3(1.0, 1.0, 0.0);
uniform vec3 BaseColor, MixRatio;
uniform sampler2D EnvMap;


 void main()
{
    // The scene's ambient light.
    vec4 ambient = gl_LightModel.ambient * gl_FrontMaterial.ambient;

// The normal vectors is generally not normalized after being
// interpolated across a triangle.  Here we normalize it.
vec3 Normal = normalize(N);

// Since the vertex is in eye space, the direction to the
// viewer is simply the normalized vector from v to the
// origin.
vec3 Viewer = -normalize(v);

// Get the lighting direction and normalize it.
vec3 Light  = normalize(gl_LightSource[0].position.xyz);

// Compute halfway vector
vec3 Half = normalize(Viewer+Light);

// Compute factor to prevent light leakage from below the
// surface
float B = 1.0;
if(dot(Normal, Light)<0.0) B = 0.0;

// Compute geometric terms of diffuse and specular
float diffuseShade = max(dot(Normal, Light), 0.0);
float specularShade = 
  B * pow(max(dot(Half, Normal), 0.0), gl_FrontMaterial.shininess);

// Compute product of geometric terms with material and
// lighting values
vec4 diffuse = diffuseShade * gl_FrontLightProduct[0].diffuse;
vec4 specular = specularShade * gl_FrontLightProduct[0].specular;
ambient += gl_FrontLightProduct[0].ambient;

// Assign final color
gl_FragColor= ambient + diffuse + specular + gl_FrontMaterial.emission;
}
android eclipse opengl-es shader
3个回答
3
投票

learnopengles.com上查看教程。他们会回答您的所有问题。


0
投票

没有着色器文件的“ java等效项”。着色器是用GLSL编写的。无论您的opengl是用java,c ++,python还是其他任何东西包装,着色器都是相同的。除了OpenGL和OpenGLES之间的微小API差异外,您还可以在Java中上载与C ++中使用的着色器完全相同的着色器,一个又一个字符。


0
投票

您可以使用此来源:https://github.com/markusfisch/ShaderEditor

ShaderView类是关键!GLSL文件位于原始文件夹中。

© www.soinside.com 2019 - 2024. All rights reserved.