Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
How Access TextureSlot2 with GLSL Scripting?

hadoken
Guest
Quote
2022-04-05 12:12:02

Hi everyone,

I wonder how to get a scene node's second assigned texture
into CopperCube GLSL shader scripting? In my shader test behavior from the docs I tried changing 0 to 1 at those commands:

in vertex shader part:
gl_TexCoord[1] = gl_MultiTexCoord1;

in fragment shader part:
vec4 col = texture2D(myTexture, vec2(gl_TexCoord[1]));

Unfortunately that doesn't do the trick. Also tried various 0/1 combinations. Nothing ...

So what would I have to do to get my second texture's color information into the shader instead of the first texture's color?

Please help anyone. THX



🔎︎



/*
<behavior jsname="behavior_TestShaderGLSL" description="behavior_TestShaderGLSL">
</behavior>
*/

behavior_TestShaderGLSL = function()
{
}

behavior_TestShaderGLSL.prototype.onAnimate = function(currentNode)
{
var vertexShader =
"uniform mat4 mWorldViewProj; \n" +
"uniform mat4 mInvWorld; \n" +
"uniform mat4 mTransWorld; \n" +
" \n" +
"void main(void) \n" +
"{ \n" +
" gl_Position = mWorldViewProj * gl_Vertex; \n" +
" \n" +
" // normal would be this: \n" +
" vec4 normal = vec4(gl_Normal, 0.0); \n" +
" normal = mInvWorld * normal; \n" +
" normal = normalize(normal); \n" +
" \n" +
" // world position would be this: \n" +
" vec4 worldpos = gl_Vertex * mTransWorld; \n" +
" \n" +
" gl_FrontColor = gl_BackColor = vec4(1.0, 1.0, 1.0, 0.0); \n" +
" \n" +
" gl_TexCoord[0] = gl_MultiTexCoord0; \n" +
"}";


var fragmentShader =
"uniform sampler2D myTexture; \n" +
" \n" +
"void main (void) \n" +
"{ \n" +
" vec4 col = texture2D(myTexture, vec2(gl_TexCoord[0])); \n" +
" col *= gl_Color; \n" +
" gl_FragColor = col; \n" +
"}";

var newMaterial = ccbCreateMaterial(vertexShader, fragmentShader, 0, null);

var cube = ccbGetSceneNodeFromName('cubeMesh1');
ccbSetSceneNodeMaterialProperty(cube, 0, 'Type', newMaterial);

}



just_in_case
Moderator
Quote
2022-04-05 19:18:52

Unforunately, I don't know much about GLSL shaders, but as far as I think, You need to sample a second texture in order to use that, I don't know if you have tried that, You don't have to change the TEXCOORDS you can use the same TEXCOORDS unless you are doing something with the texcoords,

Try sampling a new texture something like "myTexture2" or "tex2", "Texture2", something like that.

If you were working on HLSL shaders then I could have helped.

Did you tried using the inbuilt material like fake reflective and Normal maps in openGL. Are they working? if not then there is probably no support for multiple texture slot usage for OpenGL.


hadoken
Guest
Quote
2022-04-05 21:29:54

Thanks @just_in_case for your plausible thoughts. So far I have already done a lot of research regarding the issue. Now I'm afraid CopperCube's old OpenGL convention (upt to v1.30) won't let me use more than one texture with vertex and fragment shader scripting only.

I've tried to load another texture to different CC scene node texture slots at runtime and also tested different material types. I've found hints about declaring other textures active to get them recognizable within the vertex shader part but this would take OpenGL commands which are not allowed in CC's javascript. Maybe there would be another way altering the game clients source code with CopperCube's studio edition. Seems like a sad drawback for OpenGL here since we both know how well the goal can be reached with DirectX HLSL shader scripting on the other hand.

Since I've found out that OpenGL can give my current project way more frames per seconds thus more performance I must prefer OpenGL over DirectX. That's why I'm trying to reforge all my tools for this side.

Based on well working OpenGL texture alpha transparency blending I've already got an acceptable workaround at hand - like most times when trying to solve things with CopperCube :-)

I've notice some longer absence of yours, so (just) in case (LOL) you missed my current project you're welcome to take a look here:
https://ambiera.com/forum.php?t=...


just_in_case
Moderator
Quote
2022-04-11 03:45:54

I haven't played that game, Downloading it right now to try it out. Screenshots looks awesome.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact