More Glsl Shader Top Help, vertex shader question

I am trying to make this example in td en.wikibooks.org/wiki/GLSL_Prog … ed_Spheres

and I’m having trouble setting the gl_Postion in the vertex shader in the GLSL_Top. For one thing, I am not really sure how to convert the model, view, projection matrices into the appropriate touch functions. I had thought the TDWorldToProj or perhaps something in the matrix struct ‘uTDMat’ would be the answer but when I try to use any of the predefined variables like uTDMat.world or functions like TDWorldToProj I get undefined variable error:

Vertex Shader Compile Results:
0(15) : error C1008: undefined variable “TDWorldToProj”

?

A shader written for the GLSL TOP is generally a image based operation. It does essentially no geometry based work. So a GLSL TOP is simply a shader applied to a single quad that is drawn to cover up the entire viewport (also known as a full-screen-aligned quad). So generally you don’t manipulate the vertex position in a GLSL TOP, as it will cause the quad to not be aligned with the TOP output.

The functions you describe (TDWorldToProj etc.) are available in the GLSL MAT:
derivative.ca/wiki088/index … L_Material

that makes sense, thanks. I was able to port the shaders to a glsl material, however when I make a sphere sop and apply it, I only see the result I’m after with the ‘primitive’ geometric primitive type. With the ‘mesh’, ‘polygon’, ‘nurb’, the mapping is in a narrow band around the xy plane. I don’t understand why

here are the shaders

vertex:

[code]
out vec4 texCoords;

void main(void) {

texCoords = vec4(P, 1.0);

vec4 worldSpaceVert =TDDeform(P);
vec4 camSpaceVert = uTDMat.cam * worldSpaceVert;
gl_Position = TDCamToProj(camSpaceVert);

}[/code]
frag:

[code]
// GLSL Programming/GLUT/Textured Spheres - Wikibooks, open books for an open world

in vec4 texCoords;
out vec4 fragColor;
uniform sampler2D S1;
uniform vec2 scale;
uniform vec2 offset;

void main()
{
vec2 longitudeLatitude = vec2((atan(texCoords.y, texCoords.x) / 3.1415926 + 1.0) * 0.5,
1-(asin(texCoords.z ) / 3.1415926 + 0.5));

vec2 texCoordsTransformed = longitudeLatitude * scale.xy + offset.xy;
vec4 color = texture2D(S1,texCoordsTransformed.xy);

// uv's less than 0 or grater than 1, a = 0
float a = (texCoordsTransformed.x > 1.0) ? 0.0 : (texCoordsTransformed.x < 0.0) ? 0.0 : 1.0;
a *= (texCoordsTransformed.y > 1.0) ? 0.0 : (texCoordsTransformed.y < 0.0) ? 0.0 : 1.0;

//fragColor = vec4(a,a,a,1.0);
fragColor = vec4(color.x, color.y, color.z, a)*a;

}
[/code]

I recently stumbled upon the same GLSl example book and ran into the same problem. Can’t seem to figure out why these error are happening:

Vertex Shader Compile Results:
0(21) : error C1008: undefined variable “uTDMat”
0(22) : error C1008: undefined variable “TDCamToProj”

It’s way over my head and until I can fix the problem I cant progress through the chapter or the book :frowning:

Check the 099 version of the docs:
docs.derivative.ca/index.php?ti … L_Material

An example would be uTDMats[TDCameraIndex()].camProj

But a quick fix is to replace

vec4 worldSpaceVert =TDDeform(P); vec4 camSpaceVert = uTDMat.cam * worldSpaceVert; gl_Position = TDCamToProj(camSpaceVert);
with

gl_Position = TDWorldToProj(TDDeform(P));

Which book is this example in that you are having trouble with?

This link here:
nvoid.gitbooks.io/introduction- … stems.html

Is the book, and the page with the example.

Code removes errors, but still doesn’t give the results that the book provides. I’m trying to figure it out today, if I find a solution I’ll repost here.

Right, that should be the correct solution. I’ve submitted a change to the book for that. Thanks for pointing it out. If you can post your latest file I can take a look at that.

Here is my .toe that follows the book. GPUparticle.toe (6.94 KB)

I left the original code in and commented out the solution for the vertex shader.

-Not really sure what I’m doing wrong and never figured out why I couldn’t replicate the results in the book.

First thing I noticed is that the GLSL MAT isn’t applied to the Geometry COMP. That’ll need to happen for the MAT to get used.

Applied the GLSL MAT to the Geometry COMP, now I see the actual dot, just need to get the noise to change the point position, I’ll try and work on it some this weekend.

Fixed it! Needed to reference some of the older code to make it work, here is the fix for anyone who needs it. Thanks Malcom.

12.7.1GPUParticle_099.toe (7 KB)