on 24-04-2012 07:04 PM
Just testing out the public SDK and trying to do something I know works in OpenGL ES 2.0:
I just need to draw a simple primitive by setting it's coordinates via attributes.
Creating the shader:
program = new ShaderProgram("/Application/shaders/basic.cgx");
program.SetAttributeBinding(0, "position");
Rendering (simplified):
float[] squareVertices = {
x, y, x+w, y,
x, y+h, x+w, y+h,
};
program.SetAttributeValue(0, squareVertices);
gl.DrawArrays(DrawMode.TriangleStrip, 0, 4);//"gl" is the GraphicsContext
When it reaches 'SetAttribute' it throws this exception:
System.InvalidOperationException: Value argument has wrong size
Why does it do this? Which size does it expect? Is it really nessecary to create a VBO just for this?
Solved! Go to Solution.
on 25-04-2012 10:44 AM
What type is the position attribute in your shader?
I have to admit I've never seen this usage before and I'd expect position to be a float3[] array of some sort?
Defining a VertexBuffer in PSS is almst identical to how you've done it here anyway (since the framework provides methods for easily contstructing and assigning them.
One thing to note is that the Shader Compiler does not appear to be a true OpenGL ES 2.0 compiler, it's 'similar' in many respects but seems bugged and missing certain features and semantics.
on 25-04-2012 11:23 AM
Here is the shader
//Vertex
void main( float2 in position : POSITION,
float2 in texCoord : TEXCOORD0,
float4 out vPosition : POSITION,
float2 out texCoordinate : TEXCOORD0,
uniform float4x4 projectionMatrix
)
{
vPosition = mul(float4(position,1,1), projectionMatrix);
texCoordinate = texCoord;
}//Fragment: void main( float2 in texCoordinate : TEXCOORD0, float4 out fragColor : COLOR, uniform sampler2D tex : TEXUNIT0
) { fragColor = tex2D(tex, texCoordinate); }
Oddly enough it looks like it converts it correctly to GLSL (lookin inside the .gfx file) (despite looking horrible):
attribute vec2 position;
attribute vec2 texCoord;
varying vec4 vPosition;
varying vec2 texCoordinate;
uniform mat4 projectionMatrix;
vec4 _r0003;
vec4 _v0003;
// main procedure, the original name was main
void main()
{
vec4 _vPosition;
vec2 _texCoordinate;
_v0003 = vec4(position.x, position.y, 1.00000000E+000, 1.00000000E+000);
_r0003 = _v0003.x*projectionMatrix[0];
_r0003 = _r0003 + _v0003.y*projectionMatrix[1];
_r0003 = _r0003 + _v0003.z*projectionMatrix[2];
_r0003 = _r0003 + _v0003.w*projectionMatrix[3];
_vPosition = _r0003;
_texCoordinate = texCoord.xy;
gl_Position = _r0003;
texCoordinate.xy = texCoord.xy;
} // main endprecision highp float;
precision highp int;
varying vec2 texCoordinate;
uniform sampler2D tex;
// main procedure, the original name was main
void main()
{
vec4 _fragColor;
_fragColor = texture2D(tex, texCoordinate.xy);
gl_FragColor = _fragColor;
} // main end
The method I'm using isn't very widespread but it works pretty well when you need to update the vertices manually very often. It also means that you only have to upload the vertices before drawing and not having to create an entirely new projectionMatrix before drawing.
on 25-04-2012 11:30 AM
You know.. I haven't even looked at the 'compiled' shader files. I had assumed they were compiled down to a lower level, not just to GLSL. I may aswell just code my shaders direct in GLSL if I can do that rather than using this intermediate step with non-standard semantics...
As for your problem, I've no idea if it's perhaps not supported on the devices or of it's something else causing it not to work.
on 25-04-2012 12:05 PM
The .cgx files still contain the original CG shader and other information. I would keep programming them in CG (even though I prefer GLSL as well) as the PSS toolkit is designed for cross-platform compatibility. I'm quite sure there was a reason they chose CG. Probably because it is trivial to convert to HLSL on Microsoft platforms and because there are good tools for converting it to GLSL.
The original HLSL2GLSL converter by ATI:
http://sourceforge.net/projects/hlsl2glsl/
An improved fork of ATI's tool:
https://github.com/aras-p/hlsl2glslfork
If you need to go the other way (GLSL to HLSL) I believe the ANGLE project from google has a library that does just that:
http://code.google.com/p/angleproject/
It translates OpenGL ES 2.0 calls to Direct3D calls and converts the shaders. Chrome and Firefox uses this on windows to get around bad OpenGL drivers as DirectX is much better supported on Windows on virtuall all windows computers.
on 25-04-2012 11:09 PM
Hi,
I *think* SetAttributeValue just sets the 'default' value to be used for an attribute if no vertex buffer is attached for that attribute. It can therefore only have '1' vertex value, so I'm guessing the method accepts 1...4 floats. This is sort of similar to how you could set glColor in GL, and it would affect all subsequent glVertex's.
If you want multiple attribute values, you'll need to use a vertex buffer. Fortunately, this is very easy with pss, eg:
VertexBuffer vb=new VertexBuffer( 4,VertexFormat.Float2 );
vb.SetVertices( 0,new float[]{ x,y, x+w,y, x,y+h, x+w, y+h } );
on 26-04-2012 10:00 AM
Looks like you are right about the vertex attributes if there is no vertex buffer attached. I wonder why this is enforced like this if my method is valid.
PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.
フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと
PSM DevPortalを一度ログアウトし、再度ログインしてください。


Website ©2013 Sony Computer Entertainment Europe
All content, game titles, trade names and/or trade dress, trademarks, artwork and associated imagery are trademarks and/or copyright material of their respective owners. All rights reserved. [more info]
%%http://community.eu.playstation.com/t5/Announcements/Beta-Trial-Information/td-p/11386362
best_shooter.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_driver.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_performer.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_footballer.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_fighter.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_creator.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_action_player.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
dev2.png%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/Producer-and-Developer-Ranks/td-p/18407352
trophy.gif%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/The-Community-Awards-FAQ/td-p/18407096
PSlogoSM.png%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/Online-Support-Coordinator-rank/td-p/18414870