ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperLicht
forum topic indicator Skybox multitexturing
person icon
zexx
Registered User
Quote
2010-09-29 22:08:47

Hi Niko,

Since skybox node supports 2 texture layers, is it possible to make Tex1 programmatically "fade out" (get transparent) so that only Tex2 is visible? Then again "fade in" Tex1 so that it completely covers Tex2?

Just to make things clear, I'm trying to crossfade one skybox to another. Maybe I could create another skybox node, but I'm not sure how to make one box bigger than another, and how to make its textures transparent on demand.

person icon
niko
Moderator
Quote
2010-09-30 07:17:48

Could be possible, yes. You could do this either with one skybox and 2 texture layers or 2 skyboxes. In either way, you need to write a pixel shader to fade the texture.

for the vertex shader, use something like this (a normal transformation):
	
uniform mat4 worldviewproj;

attribute vec4 vPosition;
attribute vec4 vNormal;
attribute vec2 vTexCoord1;
attribute vec2 vTexCoord2;

varying vec2 v_texCoord1;
varying vec2 v_texCoord2;

void main()
{
gl_Position = worldviewproj * vPosition;
v_texCoord1 = vTexCoord1.st;
v_texCoord2 = vTexCoord2.st;
}


And for the pixel shader use something like this (fadeColor is the parameter to how to fade the color)

					
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform vec4v fadeColor;
varying vec2 v_texCoord1;
varying vec2 v_texCoord2;

void main()
{
vec2 texCoord1 = vec2(v_texCoord1.s, v_texCoord1.t);
vec2 texCoord2 = vec2(v_texCoord2.s, v_texCoord2.t);
vec4 col1 = texture2D(texture1, texCoord1);
vec4 col2 = texture2D(texture2, texCoord1);
gl_FragColor = col1 * col2 * fadeColor;
}


person icon
zexx
Registered User
Quote
2010-11-17 00:19:03

I made a shader by modifying your custom material example. It mixes two textures to produce skybox blending, using a uniform variable. The shader works, however the result is not what it should be.

Seems that Skybox node doesn't pass the second texture to the shader. To make things clear, for each side of the skybox I load 2 textures, like this:

for (var i = 0; i < 6; i++) {
this.skybox.getMaterial(i).Tex1 = texMan.getTexture (this.getFileName1(i), true);
this.skybox.getMaterial(i).Tex2 = texMan.getTexture (this.getFileName2(i), true);
this.skybox.getMaterial(i).Type = this.customMaterialType;
}

My skybox in total has 12 textures (6 sides, each with Tex1 and Tex2). The shader works, but the Tex2 is always empty, meaning it's never passed to the shader stage, so the blending doesn't work.


Create reply:










 

  

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


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






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