Imagination PowerVR SDK Blog

RenderDiffuse , lost in translation


#1

Dear Team

i am trying to adapt the sample occlusionQuery sample to it s equivalent in opengl es 2 using my custom lib to manage occlusion query(super good sample).



i have problem with your effect effect.pfx , i dont know really glsl for opengl es 3 and the OUT keyword translation

I was wondering if you kindly be able to provide a translation for glsl es 2 of the effect in OcclusionQueries demo ?

really the problem is the RenderDIffusion .



thanks in advance if you can



daviid



[HEADER]

VERSION 01.00.00.00

DESCRIPTION OGLES3OcclusionQueries

COPYRIGHT Imagination Technologies

[/HEADER]



//

// Effect to render the scene using a cube shadow map

//



[EFFECT]

NAME RenderDiffuse



// GLOBALS UNIFORMS

UNIFORM uWorldViewProjMatrix WORLDVIEWPROJECTION

UNIFORM uWorldViewMatrix WORLDVIEW

UNIFORM uWorldViewIT WORLDVIEWIT

UNIFORM uLightPosView LIGHTPOSEYE

UNIFORM uColour MATERIALCOLORDIFFUSE



UNIFORM sTextureMap TEXTURE0



// ATTRIBUTES

ATTRIBUTE inVertex POSITION

ATTRIBUTE inNormal NORMAL

ATTRIBUTE inTexCoord UV



// SHADERS

VERTEXSHADER DiffuseVertexShader

FRAGMENTSHADER DiffuseFragmentShader

[/EFFECT]



[VERTEXSHADER]

NAME DiffuseVertexShader



[GLSL_CODE]

#version 300 es



#define VERTEX_ARRAY 0

#define NORMAL_ARRAY 1

#define TEXCOORD_ARRAY 2



layout (location = VERTEX_ARRAY) in highp vec3 inVertex;

layout (location = NORMAL_ARRAY) in highp vec3 inNormal;

layout (location = TEXCOORD_ARRAY) in mediump vec2 inTexCoord;



uniform highp mat4 uWorldViewProjMatrix;

uniform highp mat4 uWorldViewMatrix;

uniform highp mat3 uWorldViewIT;

uniform highp vec3 uLightPosView;



out mediump vec2 vTexCoord;

out highp float vDiffuse;



void main()

{

gl_Position = uWorldViewProjMatrix * vec4(inVertex, 1.0);

vTexCoord = inTexCoord;



highp vec3 posView = (uWorldViewMatrix * vec4(inVertex, 1.0)).xyz;

highp vec3 lightDirView = normalize(uLightPosView - posView);

highp vec3 normalView = uWorldViewIT * inNormal;

vDiffuse = max(dot(lightDirView, normalView), 0.0);

}

[/GLSL_CODE]

[/VERTEXSHADER]





[FRAGMENTSHADER]

NAME DiffuseFragmentShader



[GLSL_CODE]

#version 300 es



uniform sampler2D sTexture;

uniform lowp vec4 uColour;



in mediump vec2 vTexCoord;

in highp float vDiffuse;



layout(location = 0) out lowp vec4 oColour;



void main()

{

oColour = texture(sTexture, vTexCoord) * uColour * vDiffuse;

}

[/GLSL_CODE]

[/FRAGMENTSHADER]





//

// Renders a single constant material colour

//



[EFFECT]

NAME RenderMaterialColour



// GLOBALS UNIFORMS

UNIFORM uWorldViewProjMatrix WORLDVIEWPROJECTION

UNIFORM uMaterialColour MATERIALCOLORDIFFUSE



// ATTRIBUTES

ATTRIBUTE inVertex POSITION



// SHADERS

VERTEXSHADER MaterialColourVertexShader

FRAGMENTSHADER MaterialColourFragmentShader

[/EFFECT]



[VERTEXSHADER]

NAME MaterialColourVertexShader



[GLSL_CODE]

#version 300 es



#define VERTEX_ARRAY 0

#define NORMAL_ARRAY 1

#define TEXCOORD_ARRAY 2



layout (location = VERTEX_ARRAY) in highp vec3 inVertex;



uniform highp mat4 uWorldViewProjMatrix;



void main()

{

gl_Position = uWorldViewProjMatrix * vec4(inVertex, 1.0);

}

[/GLSL_CODE]

[/VERTEXSHADER]



[FRAGMENTSHADER]

NAME MaterialColourFragmentShader



[GLSL_CODE]

#version 300 es



uniform lowp vec4 uMaterialColour;



layout(location = 0) out lowp vec4 oColour;



void main()

{

oColour = uMaterialColour;

}

[/GLSL_CODE]

[/FRAGMENTSHADER]




#2

Hi David,



Here’s an overview of how ES 3.0’s in/out’s compare to ES 2.0:


  1. Vertex shader in (ES 3.0) = vertex shader attribute (ES 2.0)

  2. Vertex shader out (ES 3.0) = vertex shader varying (ES 2.0)

  3. Vertex shader gl_Position (ES 3.0) = vertex shader gl_Position (ES 2.0)

  4. Fragment shader in (ES 3.0) = fragment shader varying (ES 2.0)

  5. Fragment shader out (ES 3.0) = fragment shader gl_FragColor/gl_FragData[n] (ES 2.0)



The change was made to simplify the API. It also makes the API cleaner when rendering to Multiple Render Targets (MRTs) in fragments shaders.
gl_Position is an exception to the in/out rules, as the data is passed on to a fixed stage of the graphics pipeline.

Thanks,
Joe

#3

Thank you very much Joe , i missed the OUT completely, (i didnt check the glsl spec ) i came directly to the forum :slight_smile:


#4

Joe



i am still having error with the translation , may you tell me what is wrong ??



[HEADER]

VERSION 01.00.00.00

DESCRIPTION OGLES3OcclusionQueries

COPYRIGHT Imagination Technologies

[/HEADER]



//

// Effect to render the scene using a cube shadow map

//



[EFFECT]

NAME RenderDiffuse



// GLOBALS UNIFORMS

UNIFORM uWorldViewProjMatrix WORLDVIEWPROJECTION

UNIFORM uWorldViewMatrix WORLDVIEW

UNIFORM uWorldViewIT WORLDVIEWIT

UNIFORM uLightPosView LIGHTPOSEYE

UNIFORM uColour MATERIALCOLORDIFFUSE



UNIFORM sTextureMap TEXTURE0



// ATTRIBUTES

ATTRIBUTE inVertex POSITION

ATTRIBUTE inNormal NORMAL

ATTRIBUTE inTexCoord UV



// SHADERS

VERTEXSHADER DiffuseVertexShader

FRAGMENTSHADER DiffuseFragmentShader

[/EFFECT]



[VERTEXSHADER]

NAME DiffuseVertexShader



[GLSL_CODE]





#define VERTEX_ARRAY 0

#define NORMAL_ARRAY 1

#define TEXCOORD_ARRAY 2



attribute highp vec3 inVertex;

attribute highp vec3 inNormal;

attribute mediump vec2 inTexCoord;



uniform highp mat4 uWorldViewProjMatrix;

uniform highp mat4 uWorldViewMatrix;

uniform highp mat3 uWorldViewIT;

uniform highp vec3 uLightPosView;



varying mediump vec2 vTexCoord;

varying highp float vDiffuse;



void main()

{

gl_Position = uWorldViewProjMatrix * vec4(inVertex, 1.0);

vTexCoord = inTexCoord;



highp vec3 posView = (uWorldViewMatrix * vec4(inVertex, 1.0)).xyz;

highp vec3 lightDirView = normalize(uLightPosView - posView);

highp vec3 normalView = uWorldViewIT * inNormal;

vDiffuse = max(dot(lightDirView, normalView), 0.0);

}

[/GLSL_CODE]

[/VERTEXSHADER]





[FRAGMENTSHADER]

NAME DiffuseFragmentShader



[GLSL_CODE]





uniform sampler2D sTexture;

uniform lowp vec4 uColour;



varying mediump vec2 vTexCoord;

varying highp float vDiffuse;



varying lowp vec4 oColour;



void main()

{

oColour = texture(sTexture, vTexCoord) * uColour * vDiffuse;

}

[/GLSL_CODE]

[/FRAGMENTSHADER]





//

// Renders a single constant material colour

//



[EFFECT]

NAME RenderMaterialColour



// GLOBALS UNIFORMS

UNIFORM uWorldViewProjMatrix WORLDVIEWPROJECTION

UNIFORM uMaterialColour MATERIALCOLORDIFFUSE



// ATTRIBUTES

ATTRIBUTE inVertex POSITION



// SHADERS

VERTEXSHADER MaterialColourVertexShader

FRAGMENTSHADER MaterialColourFragmentShader

[/EFFECT]



[VERTEXSHADER]

NAME MaterialColourVertexShader



[GLSL_CODE]





#define VERTEX_ARRAY 0

#define NORMAL_ARRAY 1

#define TEXCOORD_ARRAY 2



layout (location = VERTEX_ARRAY) in highp vec3 inVertex;



uniform highp mat4 uWorldViewProjMatrix;



void main()

{

gl_Position = uWorldViewProjMatrix * vec4(inVertex, 1.0);

}

[/GLSL_CODE]

[/VERTEXSHADER]



[FRAGMENTSHADER]

NAME MaterialColourFragmentShader



[GLSL_CODE]





uniform lowp vec4 uMaterialColour;



layout(location = 0) out lowp vec4 oColour;



void main()

{

oColour = uMaterialColour;

}

[/GLSL_CODE]

[/FRAGMENTSHADER]





thanks if you can



david