3D object manipulation

Previous topic - Next topic

Slydog

#15
I'm pretty sure you can apply light only to certain objects, but I'm not sure how (or if GLBasic allows this).
I know when I created my custom shader, the light / fog wasn't applied to the affected objects by default.

I'd like to see a new 'X_' command that lets you specify a colour that is added / multiplied to the current vertex colours.
Gernot, I'm fairly new to this OpenGL stuff and how GLBasic works with it, does GLBasic have a set of default shaders it uses?
If so, you could create an alternate shader (or modify the default) to use this colour value to add to all the vertice colours, until told otherwise (by setting a '0' to the above 'X_' command or something).

This could be handy for special effects too!  And you could target only specific models.

Or, does anybody know a custom shader to do the above that works on iOS? 
(It'd be nice if it uses the lighting and fog specified by GLBasic too!)
For speed, could this be done only to the vertices, and not fragment/pixels?  Or does it matter?  This part confuses me!

In my fragment shader, the following line did the trick, but I think it didn't work on iOS or something:
(Does OpenGL 1.1 not allow fragment shaders? [Edit] If not, any plans on upgrading GLB to OpenGL ES 2.0?)
Code (glbasic) Select
gl_FragColor = texture2D(TextureID1,  gl_TexCoord[0].xy) + color;

If interested, here's my shaders I had before I gave up!  (Is something in the following not valid on OpenGL 1.1 / iOS?)
Code (glbasic) Select
// Vertice Shader
float FogEyeRadial(vec4 Rh) {
vec4 Re = Rh / Rh.w;
return length(Re);
}

void main(void) {
gl_FogFragCoord = FogEyeRadial(gl_ModelViewMatrix * gl_Vertex);
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}

// Fragment Shader
uniform sampler2D TextureID1;
uniform float r;
uniform float g;
uniform float b;

void main (void)
{
vec4 color = vec4(r, g, b, 0.5);
gl_FragColor = texture2D(TextureID1,  gl_TexCoord[0].xy) + color;
gl_FragColor = mix(gl_Fog.color, gl_FragColor, clamp((gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale / 5.0, 0.1, 1.0));
}
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

kanonet

If you want some Objects to not be affected by the lights, just draw them before the light. I did some Tests in the past, that showed that you can use multiple lights that only effect several objects, but ignore others (even works with toonshading, shadows,...). Its all about drawing order. ;)
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Crivens

QuoteIf you want some Objects to not be affected by the lights
That would work at a push although I use the 3ES plugin so would need to have a look at that. Bit cheeky Gernot but do you think you could have a look to add it as an attribute to 3ES like you did with the 2D sticky code? That still doesn't work for me BTW (the object moves so it obviously is trying to stick to the screen as a 2D object, but it doesn't move enough to work correctly and ends up moving off the screen).

More importantly though it would be good to fix the lighting problem with iOS (at least with 3ES if it's not a GLB problem as a whole). As I mentioned (with screenshots) in another thread it just looks washed out when lights are applied (while WebOS/Windows are fine). Changing brightness and colour does not have the required effect as it always looks washed out. Note the lighting does work as you can see effects on objects exactly like the other devices.

And finally yeah, the ability to change an objects vertex colour on the fly would be great. Individual vertexes would be great (I also have spheres that have no texture but alternative colours on each vertex), but to allow the whole object to change all it's vertexes to a different colour would be ideal.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Kitty Hello

don't use CREATESCREEN, but USESCREEN for each loop. Yes, that's very fast.

Crivens

Quotedon't use CREATESCREEN, but USESCREEN for each loop. Yes, that's very fast
You are losing me a bit there. How would you use this?

Any chance of the 3ES change to include a flag to exclude an object from lighting? Although I'd prefer another check on iOS lighting, or on the fly vertex re-colouring. Heh, sorry, I just pile it on :)

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Kitty Hello


This is very fast.

Code (glbasic) Select

CREATESCREEN 3, 101, w, h

WHILE TRUE

USESCREEN 3
CLEARSCREEN
PRINT GETTIMERALL(), 0,0
USESCREEN -1

X_SETTEXTURE 101, -1
X_DRAWOBJ 1
SHOWSCREEN
WEND


Crivens

In the end to keep my frame rate up I used a cycling alphamode value on the object in question (basically the background). It has a good effect of looking like the whole thing is pulsating (a siren goes off at the same time) which is what I was looking for. The other advantage is all the other objects stay the same so you can still navigate around perfectly fine. Good stuff.

Out of interest Gernot did you get a chance to look at the 2D sticky code for the 3ES system? You know the one you wrote about a month ago to keep a 3D object stuck at the same point on the screen? It never worked for me properly (object moves around but does not keep to the same point on the 2D screen) although my camera is constantly moving around quite a lot, rotating etc, so I don't know if that effect things. Would be great if could be sorted out though.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.