Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Texturing problem  (Read 1037 times)
0 Members and 1 Guest are viewing this topic.
Offline gregof

Junior Member




in code we trust


« Posted 2005-03-28 20:45:39 »

Hi
I have been working on a small terrain renderer which will use shaders for texturing. The texture coordinates are calculated in the vertexshader and the different textures are mixed in the pixelshader. My problem is that I repeat the textures with the texture coordinates, but the more times I repeat the texture, the more artifacts I get(well they show up closer and closer). i have 3 screenshots below, taken from the same coordinates, they show 3 repeat-rates 64x, 128x and 512x, As you see, the problem gets worse with more repeats.

64 times repeat:


128 times repeat:


512 times repeat:


So, any ideas whats going on here?

Thanks in advance  //
                                   Gregof
Offline Daire Quinlan

Junior Member





« Reply #1 - Posted 2005-03-28 21:21:47 »

I've never seen anything like that before ...
JOGL or LWJGL ??

As a rough guess judging by the way the artifacts seem to be distributed I'd say a MipMap level problem or corruption of some description. On the other hand Its far more likely to be something to do with your pixelshader. Post some code and a little more information as to how you're doing what you're doing and someone might be able to help you out.

D.
Offline gregof

Junior Member




in code we trust


« Reply #2 - Posted 2005-03-28 21:45:30 »

Hi, thanks for responding
Forgot to include same info on my setup... I use JOGL 1.1b10 and jre 1.4.2 running on a linuxsystem with an nvidia fx5200 and latest drivers (its the same problem in winxp too, I dual boot).
What I am trying to do here is to apply 4 different textures on my terrain, I use a "mask-image" to encode where the different textures should be, using red-channel as one texturemask, the green as another osv. This allows me to mask out where a specific texture (ex. grass) should be and at the same time repeat that textures. Hope i make some sense here....
I have my vertex and pixel-shaders below(Shaders are in CG btw):

Vertexshader looks like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
void main(
float4 position : POSITION,
float2 textureCoords : TEXCOORD0,
float2 lightMapCoords : TEXCOORD1,

out float4 oPosition : POSITION,
out float2 oTextureCoords : TEXCOORD0,
out float2 oLightMapCoords : TEXCOORD1
)
{
 int sizeOfTerrain = 2048;
 int numberOfTextureRepeats = 256;

 oTextureCoords.x = position.x / (sizeOfTerrain / numberOfTextureRepeats);
 oTextureCoords.y = position.z / (sizeOfTerrain / numberOfTextureRepeats);

 oLightMapCoords.x = position.x / sizeOfTerrain;
 oLightMapCoords.y = position.z / sizeOfTerrain;

 float4x4 modelViewProjectionMatrix = glstate.matrix.mvp;
 oPosition = mul(modelViewProjectionMatrix, position);
}


...and my pixelshader looks like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
void main(
float2 textureCoords : TEXCOORD0,
float2 lightMapCoords : TEXCOORD1,
float4 color : COLOR,
out float4 oColor : COLOR,
uniform sampler2D lightMap : TEXUNIT0,
uniform sampler2D grassMap : TEXUNIT1,
uniform sampler2D gravelMap : TEXUNIT2,
uniform sampler2D ironMap : TEXUNIT3,
uniform sampler2D mosaicMap : TEXUNIT4,
uniform sampler2D mask : TEXUNIT5


)
{

float4 grassMapColor = tex2D(grassMap, textureCoords).rgba;
float4 gravelMapColor = tex2D(gravelMap, textureCoords).rgba;
float4 ironMapColor = tex2D(ironMap, textureCoords).rgba;
float4 mosaicMapColor = tex2D(mosaicMap, textureCoords).rgba;

float4 maskColor = tex2D(mask, lightMapCoords).rgba;
float4 lightColor = tex2D(lightMap, lightMapCoords).rgba;

oColor = ((grassMapColor * maskColor.r) + (gravelMapColor * maskColor.g) + (ironMapColor * maskColor.b) + (mosaicMapColor * maskColor.a)) * lightColor;
oColor = grassMapColor * lightColor;
}


Thanks  //
                      Gregof




Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gregof

Junior Member




in code we trust


« Reply #3 - Posted 2005-03-30 22:34:52 »

Hi again.
I forgot to mention that the artifacts aren't static, the move when I move the camera, the effect is somewhat hard to describe, but it reminds me of the  MoirĂ© effect.  I also noted that this effect only is visible when I use mipmap textures, if I use LINEAR or NEAREST filtering it doesn't show up.  Is there somthing special I should do to use mipmaps and shaders? (I dont think so, but i'am known to be wrong :-) )

// Gregof
Offline tom
« Reply #4 - Posted 2005-03-30 22:53:47 »

You do not want to use mipmaps on the "mask-image". The image will be smeared and that might break the thing your doing in the shader.

Offline gregof

Junior Member




in code we trust


« Reply #5 - Posted 2005-04-01 07:56:38 »

Yes good point, I did use mipmaps for the maskimage, I tried to use linear or nearest just now, but then the terrain showed up black?
I did some further investigation and it seems to be the case that if I use linear or nearest and then try even the simplest case involving the maskColor, like maskColor.r * lightColor; which should give me a black and white terrain, it just becomes black Sad
Are there some restrictions/recommendations as to how the textures should be loaded when used in shaders?

// Gregof

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (14 views)
2014-04-15 18:08:23

BurntPizza (12 views)
2014-04-15 03:46:01

UprightPath (25 views)
2014-04-14 17:39:50

UprightPath (11 views)
2014-04-14 17:35:47

Porlus (28 views)
2014-04-14 15:48:38

tom_mai78101 (50 views)
2014-04-10 04:04:31

BurntPizza (109 views)
2014-04-08 23:06:04

tom_mai78101 (209 views)
2014-04-05 13:34:39

trollwarrior1 (177 views)
2014-04-04 12:06:45

CJLetsGame (184 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!