PVRShaderEditor - Loading shader code from external files

Hi There,



I’m trying to reduce the size of one of my PFX files that’s getting a little too large to manage, so I thought I’d put the shader code in separate text files and include them.



I’ve checked the PFX specification and it seems you include them like this:





[VERTEXSHADER]

NAME VertexShader

FILE moon.vsh

[/VERTEXSHADER]



[FRAGMENTSHADER]

NAME FragmentShader

FILE moon.fsh

[/FRAGMENTSHADER]





Here’s the full listing of the PFX if it helps





[HEADER]

VERSION 01.00.00.00

DESCRIPTION Moon shaders

COPYRIGHT

[/HEADER]





[TEXTURE]

NAME moon

PATH moon.pvr

MINIFICATION LINEAR

MAGNIFICATION LINEAR

MIPMAP NEAREST

[/TEXTURE]



[VERTEXSHADER]

NAME VertexShader

FILE moon.vsh

[/VERTEXSHADER]



[FRAGMENTSHADER]

NAME FragmentShader

FILE moon.fsh

[/FRAGMENTSHADER]



[EFFECT]

NAME MoonSurface



// GLOBALS UNIFORMS

UNIFORM WorldViewIT WORLDVIEWIT

UNIFORM WVPMatrix WORLDVIEWPROJECTION

UNIFORM LightDirection LIGHTDIREYE

UNIFORM sMoon TEXTURE0





// ATTRIBUTES

ATTRIBUTE inVertex POSITION

ATTRIBUTE inNormal NORMAL

ATTRIBUTE inTexCoord UV



VERTEXSHADER VertexShader

FRAGMENTSHADER FragmentShader

TEXTURE 0 moon

[/EFFECT]







Then in the plain text files I have this for the Vertex Shader:





attribute highp vec4 inVertex;

attribute mediump vec3 inNormal;

attribute mediump vec2 inTexCoord;



uniform highp mat4 WVPMatrix;

uniform mediump mat3 WorldViewIT;

uniform mediump vec3 LightDirection;



varying mediump vec2 TexCoord;



void main()

{

gl_Position = WVPMatrix * inVertex;

mediump vec3 transNormal = normalize(WorldViewIT * inNormal);

TexCoord = inTexCoord;

}





And for the Fragment Shader:





uniform sampler2D sMoon;

varying mediump vec2 TexCoord;



void main()

{

gl_FragColor.rgb = texture2D(sMoon, TexCoord).rgb;

gl_FragColor.a = 1.0;

}





Unfortunately I get an error in PVRShaderEditor saying:



Error while parsing PFX: Error loading file ‘moon.vsh’ in [VERTEXSHADER] on line 18





The PFX and the shader files are in the same directory, so I can’t see what the problem is.



Am I missing something?



Kind Regards,



Andre.

Hi Andre,

You’ve found a legitimate bug in PVRShaderEditor. The current working directory is not been correctly set up before the PFX is parsed, hence the problem. A nasty work-around would be to place the shader files with the PVRShaderEditor executable, but obviously this is an awful solution.



I’ve filed bug report BRN45433, and as this is a feature-breaking bug it should be fixed fairly quickly.



Regards.

Hi Arron,



Thanks for the fast response. I’ll hold off on refactoring my PFX files in this way until the fix.



Cheers



Andre.

Hi Andre.

You’ll be pleased to know that the fix made it into our 3.2 release, which went public yesterday.

Hopefully this should fix your problem.



Regards.

Hi Arron,



That’s great. I’ll check it out on monday :slight_smile:



Andre.

Hi Arron,



I’ve installed the latest SDK and Tools and the PVRShaderEditor is now happy with external shader files, and compiles the PFX without any issues :slight_smile:



However, having the shader code in external files causes a material using this PFX to fail in PVRShaman :frowning:



Kind Regards,



Andre.

Hi Arron,



Has anyone been able to replicate my problem with PVRShaman I mentioned above?



Regards,



Andre.

Hi Andre.



Apologies - I completely missed this thread! I’ve reproduced the problem you’ve described and I’m investigating it now.

Hi again Andre.

This was a simple bug and has now been fixed. It will be released publicly in the next SDK or subsequent updates of PVRShaman however if this is a blocking issue for you, please send an email to devtech@imgtec.com and we can provide you with a fixed version.



Regards.

Hi Arron,



Thanks for your response. I’m working on a different part of the system at present so it is not blocking my work at present. When is the next PVRShaman/PVRSDK release scheduled?



Regards,



Andre.

SDK 3.3 is due around late February 2014 but we can update individual utilities before this date if we find a major issue.

Hi Arron,



I’m back working within PVRShaman now, and having the issue I mentioned in this thread above.



Do you have a fixed version of PVRShaman you could give me so I can edit PFX’s which reference external shader sources?



Kind Regards,



Andre.

Hi Andre,



Arron has recently left our team. If you file a ticket through our developer support portal (https://pvrsupport.imgtec.com/), I’ll give you access to a new build of PVRShaman.



Regards,

Joe