Jump to content
  • Advertisement
Sign in to follow this  
EternityZA

OpenGL Mip mapping issue

This topic is 1377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi.

 

I am busy writing a directx renderer for my engine that up until now was opengl only. Here is a screenshot rendered in opengl that demonstrates what Im trying to achieve.

 

sR6n5y.png

 

Here is the same scene rendered in directx

 

c0jNt4.png

 

Looking at the far away terrain the mipmapping in the directx version seems a bit of (well I think its the mipmapping). You can clearly see some ugly patterns forming the further you go.

 

The only only difference between the 2 (that i can think of) is the way the mip maps are generated. In the opengl one the mipmaps are created using gluBuild2DMipmaps. In the direcx one I generate the mipmaps myself and i  simply average the nearest 4 pixels together when downscaling. So my first thought was that gluBuild2DMipmaps uses a different algorithm to downscale the image but I cant seem to find more information on it. Maybe the problem is something else entirely? Either way any help will appreciated.

 

Thnx in Advance!

 

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

Since gluBuild2DMipmaps is more of a utility function to get things running than a final solution, I would be surprised if it was doing anything more complicated than a simple box filter (like what you're doing in your DirectX version right now). 

 

However, you can rule out gluBuild2DMipmaps as the source of your problem by simply doing the same thing you do in DirectX in OpenGL. Have you tried generating mips yourself in OpenGL, the same way you do in DirectX, and seeing if that produces results that look the same?

 

Also, are you sure your DirectX mip map generation is correct? Have you looked at the generated mips directly and verified that they're correct? It can be kind of hard to tell just from an in-game screenshot whether the mips are exactly right (or exactly what you're expecting, since "right" is kind of subjective).

Share this post


Link to post
Share on other sites

Can you provide the code that shows how you generate and use the texture?

 

Why aren't you using DirectX functions (When creating the resource or with GenerateMipMaps)?

 

Also, make sure you're rendering state is correct - you didn't specify which DX version you are using, but it can be due to incorrect ShaderResourceView::MipLevels and SamplerState::MaxLod fields.

Share this post


Link to post
Share on other sites

GenerateMips is only valid if the base resource is created with D3D11_BIND_RENDER_TARGET (you don't say which D3D version you're using here so I'm assuming 11).

 

Per-spec, gluBuild2DMipmaps uses a box filter, which is exactly what you say you're using for your D3D code, so the error may be in your box filter code.

 

What I'd advise you check first, however, is your D3D sampler states.  The min/mag/mip filtering modes work quite differently in D3D than they do in GL, with sampler states being decoupled from the textures rather than being part of a texture object, so this is one likely source of error: I consider it at least possible that this is wrong and you've ended up with a nearest filter where you probably want min/map/mip linear.

 

(Yes, later versions of GL have sampler objects too, but I'm assuming - from mention of gluBuild2DMapmaps - that the OP is using an earlier version.)

Edited by mhagain

Share this post


Link to post
Share on other sites

Ok.

 

I use directX 11. And yes the opengl is quite a bit older. 

 

filter options in opengl:

[source]

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
[/source]
 
filter options in directx
 
[source]
D3D11_SAMPLER_DESC sampDesc;
ZeroMemory(&sampDesc, sizeof(sampDesc));
sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
sampDesc.MinLOD = 0;
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
[/source]
 
Shaders. The first 4 textures contain height, normal and tile weight information. the next 8 textures are the actual colour textures for the terrain. all textures and samplers are bound to the vertex and pixel shader using the same slots (for compatibility with opengl). The pixel shader contains 1 sampler for each texture but theyre all the same. The vertex shader is probaly pretty irrelevent to the question.
 
vertex shader
 
[source]
Texture2D tex1  : register( t0 );
SamplerState samp1  : register( s0 );
 
Texture2D tex2  : register( t1 );
SamplerState samp2  : register( s1 );
 
Texture2D tex3  : register( t2 );
SamplerState samp3  : register( s2 );
 
Texture2D tex4  : register( t3 );
SamplerState samp4  : register( s3 );
 
 
 
 
 
  struct VSInput
 {
float4 pos : a_position;
float2 textCoordA : v_textCoordA;
 };
 
 
  struct PSInput
 {
  float4 pos : SV_Position;
  float3 p : v_pos;
float2 textCoordA : v_textCoordA;
float3 normal : v_normal;
float2 gridPos : v_gridPos;
float w1 : v_w1;
float w2 : v_w2;
float w3 : v_w3;
float w4 : v_w4;
float w5 : v_w5;
float w6 : v_w6;
float w7 : v_w7;
float w8 : v_w8;
float2 c : v_c;
 };
 
 
 
 
 
 
PSInput main(VSInput attrib)
{
 
        PSInput ps;
   
float4 vpos = attrib.pos;
ps.gridPos = float2(vpos.x*128,vpos.y*128);
 
 
float2 coord = float2(vpos.x/(8*lod)+tOffset.x,vpos.y/(8*lod)+tOffset.y);
 
ps.c = coord;
 
coord.x = clamp(coord.x,1.0/1024.0,1023.0/1024.0);
coord.y = clamp(coord.y,1.0/1024.0,1023.0/1024.0);
coord = float2(coord.x+1.0/2048, coord.y+1.0/2048);
 
float2 ic = float2(vpos.x/(8*lod)+tOffset.x,vpos.y/(8*lod)+tOffset.y);
ic = ic * 1024;
ic.x = clamp(ic.x,1.0,1023.0);
ic.y = clamp(ic.y,1.0,1023.0);
 
uint3 ici = uint3(ic.x,ic.y,0);
 
float4 t1 = tex1.Load(ici);
float4 t2 = tex2.Load(ici);
float4 t3 = tex3.Load(ici);
float4 t4 = tex4.Load(ici);
 
 
float h = (t1.r-(127.0/255.0)) * 65280.0 +
 t1.g * 255.0 +
                  t1.b * 1.0;
 
vpos.z = vpos.z + h;
 
ps.normal =  t2.rgb*2-1;
 
 
float4 vertPos = mul(vpos,modelMatrix);
    ps.pos = mul(vertPos,projectionAndViewMatrix);
    ps.p = vertPos.xyz;
   
    ps.w1 = t3.r;
    ps.w2 = t3.g;
    ps.w3 = t3.b;
    ps.w4 = t3.a;
    ps.w5 = t4.r;
    ps.w6 = t4.g;
    ps.w7 = t4.b;
    ps.w8 = t4.a;
   
    ps.textCoordA = attrib.textCoordA*(8.0/lod);
   
    return ps;
 
}
 
[/source]
 
Pixel shader
 
[source]
 
Texture2D tex1  : register( t0 );
Texture2D tile1  : register( t4 );
Texture2D tile2  : register( t5 );
Texture2D tile3  : register( t6 );
Texture2D tile4  : register( t7 );
Texture2D tile5  : register( t8 );
Texture2D tile6  : register( t9 );
Texture2D tile7  : register( t10 );
Texture2D tile8  : register( t11 );
 
SamplerState samp1  : register( s4 );
SamplerState samp2  : register( s5 );
SamplerState samp3  : register( s6 );
SamplerState samp4  : register( s7 );
SamplerState samp5  : register( s8 );
SamplerState samp6  : register( s9 );
SamplerState samp7  : register( s10 );
SamplerState samp8  : register( s11 );
 
  struct PSInput
 {
  float4 pos : SV_Position;
  float3 p : v_pos;
float2 textCoordA : v_textCoordA;
float3 normal : v_normal;
float2 gridPos : v_gridPos;
float w1 : v_w1;
float w2 : v_w2;
float w3 : v_w3;
float w4 : v_w4;
float w5 : v_w5;
float w6 : v_w6;
float w7 : v_w7;
float w8 : v_w8;
float2 c : v_c;
 };
 
 
 
float4 main(PSInput ps) : SV_Target
{
 
uint x = int(floor(ps.p.x));
uint y = int(floor(ps.p.y));
x = x % 1024;
y = y % 1024;
 
 
float4 t1 = tex1.Load(uint3(ps.c.x*1024,ps.c.y*1024,0));
 
if (t1.a == 0.0) //indicates a hole in the terrain. Caves etc.
{
discard;
}
 
 
 
float3 n = normalize(ps.normal);
 
 
 
 
float4 c1 = tile1.Sample(samp1, ps.textCoordA);
float4 c2 = tile2.Sample(samp2, ps.textCoordA);
float4 c3 = tile3.Sample(samp3, ps.textCoordA);
float4 c4 = tile4.Sample(samp4, ps.textCoordA);
float4 c5 = tile5.Sample(samp5, ps.textCoordA);
float4 c6 = tile6.Sample(samp6, ps.textCoordA);
float4 c7 = tile7.Sample(samp7, ps.textCoordA);
float4 c8 = tile8.Sample(samp8, ps.textCoordA);
 
float4 fvBaseColor = c1;
 
float total = ps.w1+ps.w2+ps.w3+ps.w4+ps.w5+ps.w6+ps.w7+ps.w8;
 
if (total > 0.0)
{
fvBaseColor = c1 * ps.w1 +  c2 * ps.w2 +  c3 * ps.w3 +  c4 * ps.w4 +  c5 * ps.w5 +  c6 * ps.w6 +  c7 * ps.w7 +  c8 * ps.w8;
fvBaseColor.a = 0.0;
}
 
 
 
float NdotL = max(dot(n, normalize(float3(1000,-1000,1000))),0.0);
 
 
  float cut = 0.3;
  float shade = 0.85;
 
if (NdotL > cut + 0.05)
{
NdotL = 1.0;
}
else if (NdotL < cut)
{
NdotL = shade;
}
else
{
NdotL = ((NdotL - cut)*20)*(1.0-shade)+shade;
}
 
 
 
     NdotL = 1.0 - NdotL;
 float4 diffuse = float4(fvBaseColor.r-NdotL,fvBaseColor.g-NdotL,fvBaseColor.b-NdotL,1.0);
 
 
 
 
 
 
float4 colour1 = diffuse;
 
 
 
 
 
 
 
 
 
 
 
 
 
float len = length(ps.p-camera);
float start = 500.0;
float end = 700.0;
float4 fadeColor = float4(0.3,0.3,0.9,1.0);
if (len > start)
{
if (len > end)
{
colour1 = fadeColor;
}
else
colour1 = lerp(colour1,fadeColor,(len-start)/(end-start));
}
}
 
 
 
float4 cc2 = colour1;
cc2.a = 1.0;
 
 
 if (death == 1)
 {
  float grey = (cc2.r+cc2.g+cc2.b)/3.0;
  cc2.r = grey;
  cc2.g = grey;
  cc2.b = grey;
 }
 
 return cc2;
 
}
 
[/source]
 
Here is the code that creates the texture. My game engine is written in Java but since you cant do directx in java directly I wrote my directx calls in c++). I create and concatenate all the mip levels in java before calling this c++ method. If the mipLevel is higher than one this method will only work for textures that has width and height values that is multiples of 2 I will improve that as soon as this problem is sorted out. This is probably the part that I'm the most unsure of. especially where I load all the mipmaps into the SUB_RESOURCE_DATA array.
[source]
 
struct Texture
{
ID3D11ShaderResourceView* textureView;
ID3D11DepthStencilView* depthStencilView;
ID3D11RenderTargetView* renderTargetView;
ID3D11SamplerState* sampler;
};
 
JNIEXPORT jint JNICALL Java_dmdx11_DmdxNative_createTexture(JNIEnv* env, jobject, jobject data, jint width, jint height, jint type,jint mipLevel)
{
Texture texture = Texture();
ID3D11Texture2D* pTexture;
if (type == 0)//color
{
D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
D3D11_TEXTURE2D_DESC sTexDesc;
 
sTexDesc.Width = width;
sTexDesc.Height = height;
sTexDesc.MipLevels = mipLevel;
sTexDesc.ArraySize = 1;
sTexDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sTexDesc.SampleDesc.Count = 1;
sTexDesc.SampleDesc.Quality = 0;
sTexDesc.Usage = D3D11_USAGE_IMMUTABLE;
sTexDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
sTexDesc.CPUAccessFlags = 0;
sTexDesc.MiscFlags = 0;
 
D3D11_SUBRESOURCE_DATA *sSubData = new D3D11_SUBRESOURCE_DATA[mipLevel];
 
int sofar = 0;
for (int i = 0; i < mipLevel; i++)
{
 
 
sSubData.pSysMem = (jbyte*)env->GetDirectBufferAddress(data) + sofar;
sSubData.SysMemPitch = (UINT)(width * 4);
sSubData.SysMemSlicePitch = (UINT)(width * height * 4);
 
sofar += (int)(width * height * 4);
 
width = width / 2;
height = height / 2;
 
}
hr = g_pd3dDevice->CreateTexture2D(&sTexDesc, sSubData, &pTexture);
delete[] sSubData;
 
 
 
shaderResourceViewDesc.Format = sTexDesc.Format;
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture2D.MipLevels = mipLevel;
 
g_pd3dDevice->CreateShaderResourceView(pTexture, &shaderResourceViewDesc, &texture.textureView);
 
 
D3D11_SAMPLER_DESC sampDesc;
ZeroMemory(&sampDesc, sizeof(sampDesc));
sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
sampDesc.MinLOD = 0;
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
 
g_pd3dDevice->CreateSamplerState(&sampDesc, &texture.sampler);
}
... 
...
...
}
 
[/source]
 
If theres any more information needed please ask.
 
Thank you for your time ^^
Edited by Wilhelm van Huyssteen

Share this post


Link to post
Share on other sites

Also, and unrelated to your problem, because sampler states are fully decoupled from textures, you can do this:

 

float4 c1 = tile1.Sample(samp1, ps.textCoordA);
float4 c2 = tile2.Sample(samp1, ps.textCoordA);
float4 c3 = tile3.Sample(samp1, ps.textCoordA);
float4 c4 = tile4.Sample(samp1, ps.textCoordA);
float4 c5 = tile5.Sample(samp1, ps.textCoordA);
float4 c6 = tile6.Sample(samp1, ps.textCoordA);
float4 c7 = tile7.Sample(samp1, ps.textCoordA);
float4 c8 = tile8.Sample(samp1, ps.textCoordA);

Share this post


Link to post
Share on other sites


0 isn't a valid value for MaxAnisotropy; it needs to be between 1 and 16: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476207%28v=vs.85%29.aspx
(Note that 1, not 0, is for anisotropic filtering disabled).
I suggest correcting this first, then see if the problems still happen.

 

This value is ignored in case the filter type is not anisotropic.

Appraently, 0 is indeed a valid value even if the filter type is anisotropic.

D3D11 ERROR: ID3D11Device::CreateSamplerState: MaxAnisotropy must be in the range [0 to 16].  20 specified. [ STATE_CREATION ERROR #226: CREATESAMPLERSTATE_INVALIDMAXANISOTROPY]

Share this post


Link to post
Share on other sites

So. since mhagain mentioned that gluBuild2DMipmaps uses a box filter as well I went back to my mipmap generation code and I discovered that (as part of some earlier testing/debugging) I commented out the line of code that averages the 4 nearest pixels together and instead replaced it with a line that that just uses the value of the top-left pixel and ignores the rest...

 

Undoing that bit of test code the directx version now renders perfectly. Feel kind of silly. Should probably take it easy with all the late night coding.

 

Thank you for your time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Similar Content

    • By nOoNEE
      hello guys , i have some questions  what does glLinkProgram  and  glBindAttribLocation do?  i searched but there wasnt any good resource 
    • By owenjr
      Hi, I'm a Multimedia Engineering student. I am about to finish my dergree and I'm already thinking about what topic to cover in my final college project.
      I'm interested in the procedural animation with c++ and OpenGL of creatures, something like a spider for example. Can someone tell me what are the issues I should investigate to carry it out? I understand that it has some dependence on artificial intelligence but I do not know to what extent. Can someone help me to find information about it? Thank you very much.
       
      Examples: 
      - Procedural multi-legged walking animation
      - Procedural Locomotion of Multi-Legged Characters in Dynamic Environments
    • By Lewa
      So, i'm still on my quest to unterstanding the intricacies of HDR and implementing this into my engine. Currently i'm at the step to implementing tonemapping. I stumbled upon this blogposts:
      http://filmicworlds.com/blog/filmic-tonemapping-operators/
      http://frictionalgames.blogspot.com/2012/09/tech-feature-hdr-lightning.html
      and tried to implement some of those mentioned tonemapping methods into my postprocessing shader.
      The issue is that none of them creates the same results as shown in the blogpost which definitely has to do with the initial range in which the values are stored in the HDR buffer. For simplicity sake i store the values between 0 and 1 in the HDR buffer (ambient light is 0.3, directional light is 0.7)
      This is the tonemapping code:
      vec3 Uncharted2Tonemap(vec3 x) { float A = 0.15; float B = 0.50; float C = 0.10; float D = 0.20; float E = 0.02; float F = 0.30; return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F; } This is without the uncharted tonemapping:
      This is with the uncharted tonemapping:
      Which makes the image a lot darker.
      The shader code looks like this:
      void main() { vec3 color = texture2D(texture_diffuse, vTexcoord).rgb; color = Uncharted2Tonemap(color); //gamma correction (use only if not done in tonemapping code) color = gammaCorrection(color); outputF = vec4(color,1.0f); } Now, from my understanding is that tonemapping should bring the range down from HDR to 0-1.
      But the output of the tonemapping function heavily depends on the initial range of the values in the HDR buffer. (You can't expect to set the sun intensity the first time to 10 and the second time to 1000 and excpect the same result if you feed that into the tonemapper.) So i suppose that this also depends on the exposure which i have to implement?
      To check this i plotted the tonemapping curve:
      You can see that the curve goes only up to around to a value of 0.21 (while being fed a value of 1) and then basically flattens out. (which would explain why the image got darker.)
       
      My guestion is: In what range should the values in the HDR buffer be which then get tonemapped? Do i have to bring them down to a range of 0-1 by multiplying with the exposure?
      For example, if i increase the values of the light by 10 (directional light would be 7 and ambient light 3) then i would need to divide HDR values by 10 in order to get a value range of 0-1 which then could be fed into the tonemapping curve. Is that correct?
    • By nOoNEE
      i am reading this book : link
      in the OpenGL Rendering Pipeline section there is a picture like this: link
      but the question is this i dont really understand why it is necessary to turn pixel data in to fragment and then fragment into pixel could please give me a source or a clear Explanation that why it is necessary ? thank you so mu
       
       
    • By Inbar_xz
      I'm using the OPENGL with eclipse+JOGL.
      My goal is to create movement of the camera and the player.
      I create main class, which create some box in 3D and hold 
      an object of PlayerAxis.
      I create PlayerAxis class which hold the axis of the player.
      If we want to move the camera, then in the main class I call to 
      the func "cameraMove"(from PlayerAxis) and it update the player axis.
      That's work good.
      The problem start if I move the camera on 2 axis, 
      for example if I move with the camera right(that's on the y axis)
      and then down(on the x axis) -
      in some point the move front is not to the front anymore..
      In order to move to the front, I do
      player.playerMoving(0, 0, 1);
      And I learn that in order to keep the front move, 
      I need to convert (0, 0, 1) to the player axis, and then add this.
      I think I dont do the convert right.. 
      I will be glad for help!

      Here is part of my PlayerAxis class:
       
      //player coordinate float x[] = new float[3]; float y[] = new float[3]; float z[] = new float[3]; public PlayerAxis(float move_step, float angle_move) { x[0] = 1; y[1] = 1; z[2] = -1; step = move_step; angle = angle_move; setTransMatrix(); } public void cameraMoving(float angle_step, String axis) { float[] new_x = x; float[] new_y = y; float[] new_z = z; float alfa = angle_step * angle; switch(axis) { case "x": new_z = addVectors(multScalar(z, COS(alfa)), multScalar(y, SIN(alfa))); new_y = subVectors(multScalar(y, COS(alfa)), multScalar(z, SIN(alfa))); break; case "y": new_x = addVectors(multScalar(x, COS(alfa)), multScalar(z, SIN(alfa))); new_z = subVectors(multScalar(z, COS(alfa)), multScalar(x, SIN(alfa))); break; case "z": new_x = addVectors(multScalar(x, COS(alfa)), multScalar(y, SIN(alfa))); new_y = subVectors(multScalar(y, COS(alfa)), multScalar(x, SIN(alfa))); } x = new_x; y = new_y; z = new_z; normalization(); } public void playerMoving(float x_move, float y_move, float z_move) { float[] move = new float[3]; move[0] = x_move; move[1] = y_move; move[2] = z_move; setTransMatrix(); float[] trans_move = transVector(move); position[0] = position[0] + step*trans_move[0]; position[1] = position[1] + step*trans_move[1]; position[2] = position[2] + step*trans_move[2]; } public void setTransMatrix() { for (int i = 0; i < 3; i++) { coordiTrans[0][i] = x[i]; coordiTrans[1][i] = y[i]; coordiTrans[2][i] = z[i]; } } public float[] transVector(float[] v) { return multiplyMatrixInVector(coordiTrans, v); }  
      and in the main class i have this:
       
      public void keyPressed(KeyEvent e) { if (e.getKeyCode()== KeyEvent.VK_ESCAPE) { System.exit(0); //player move } else if (e.getKeyCode()== KeyEvent.VK_W) { //front //moveAmount[2] += -0.1f; player.playerMoving(0, 0, 1); } else if (e.getKeyCode()== KeyEvent.VK_S) { //back //moveAmount[2] += 0.1f; player.playerMoving(0, 0, -1); } else if (e.getKeyCode()== KeyEvent.VK_A) { //left //moveAmount[0] += -0.1f; player.playerMoving(-1, 0, 0); } else if (e.getKeyCode()== KeyEvent.VK_D) { //right //moveAmount[0] += 0.1f; player.playerMoving(1, 0, 0); } else if (e.getKeyCode()== KeyEvent.VK_E) { //moveAmount[0] += 0.1f; player.playerMoving(0, 1, 0); } else if (e.getKeyCode()== KeyEvent.VK_Q) { //moveAmount[0] += 0.1f; player.playerMoving(0, -1, 0); //camera move } else if (e.getKeyCode()== KeyEvent.VK_I) { //up player.cameraMoving(1, "x"); } else if (e.getKeyCode()== KeyEvent.VK_K) { //down player.cameraMoving(-1, "x"); } else if (e.getKeyCode()== KeyEvent.VK_L) { //right player.cameraMoving(-1, "y"); } else if (e.getKeyCode()== KeyEvent.VK_J) { //left player.cameraMoving(1, "y"); } else if (e.getKeyCode()== KeyEvent.VK_O) { //right round player.cameraMoving(-1, "z"); } else if (e.getKeyCode()== KeyEvent.VK_U) { //left round player.cameraMoving(1, "z"); } }  
      finallt found it.... i confused with the transformation matrix row and col. thanks anyway!
    • By Lewa
      So, i'm currently trying to implement an SSAO shader from THIS tutorial and i'm running into a few issues here.
      Now, this SSAO method requires view space positions and normals. I'm storing the normals in my deferred renderer in world-space so i had to do a conversion and reconstruct the position from the depth buffer.
      And something there goes horribly wrong (which has probably to do with worldspace to viewspace transformations).
      (here is the full shader source code if someone wants to take a look at it)
      Now, i suspect that the normals are the culprit.
      vec3 normal = ((uNormalViewMatrix*vec4(normalize(texture2D(sNormals, vTexcoord).rgb),1.0)).xyz); "sNormals" is a 2D texture which stores the normals in world space in a RGB FP16 buffer.
      Now i can't use the camera viewspace matrix to transform the normals into viewspace as the cameras position isn't set at (0,0,0), thus skewing the result.
      So what i did is to create a new viewmatrix specifically for this normal without the position at vec3(0,0,0);
      //"camera" is the camera which was used for rendering the normal buffer renderer.setUniform4m(ressources->shaderSSAO->getUniform("uNormalViewMatrix"), glmExt::createViewMatrix(glm::vec3(0,0,0),camera.getForward(),camera.getUp())//parameters are (position,forwardVector,upVector) ); Though i have the feeling this is the wrong approach. Is this right or is there a better/correct way of transforming a world space normal into viewspace?
    • By HawkDeath
      Hi,
      I'm trying mix two textures using own shader system, but I have a problem (I think) with uniforms.
      Code: https://github.com/HawkDeath/shader/tree/test
      To debug I use RenderDocs, but I did not receive good results. In the first attachment is my result, in the second attachment is what should be.
      PS. I base on this tutorial https://learnopengl.com/Getting-started/Textures.


    • By norman784
      I'm having issues loading textures, as I'm clueless on how to handle / load images maybe I missing something, but the past few days I just google a lot to try to find a solution. Well theres two issues I think, one I'm using Kotlin Native (EAP) and OpenGL wrapper / STB image, so I'm not quite sure wheres the issue, if someone with more experience could give me some hints on how to solve this issue?
      The code is here, if I'm not mistaken the workflow is pretty straight forward, stbi_load returns the pixels of the image (as char array or byte array) and you need to pass those pixels directly to glTexImage2D, so a I'm missing something here it seems.
      Regards
    • By Hashbrown
      I've noticed in most post processing tutorials several shaders are used one after another: one for bloom, another for contrast, and so on. For example: 
      postprocessing.quad.bind() // Effect 1 effect1.shader.bind(); postprocessing.texture.bind(); postprocessing.quad.draw(); postprocessing.texture.unbind(); effect1.shader.unbind(); // Effect 2 effect2.shader.bind(); // ...and so on postprocessing.quad.unbind() Is this good practice, how many shaders can I bind and unbind before I hit performance issues? I'm afraid I don't know what the good practices are in open/webGL regarding binding and unbinding resources. 
      I'm guessing binding many shaders at post processing is okay since the scene has already been updated and I'm just working on a quad and texture at that moment. Or is it more optimal to put shader code in chunks and bind less frequently? I'd love to use several shaders at post though. 
      Another example of what I'm doing at the moment:
      1) Loop through GameObjects, bind its phong shader (send color, shadow, spec, normal samplers), unbind all.
      2) At post: bind post processor quad, and loop/bind through different shader effects, and so on ...
      Thanks all! 
    • By phil67rpg
      void collision(int v) { collision_bug_one(0.0f, 10.0f); glutPostRedisplay(); glutTimerFunc(1000, collision, 0); } void coll_sprite() { if (board[0][0] == 1) { collision(0); flag[0][0] = 1; } } void erase_sprite() { if (flag[0][0] == 1) { glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_POLYGON); glVertex3f(0.0f, 10.0f, 0.0f); glVertex3f(0.0f, 9.0f, 0.0f); glVertex3f(1.0f, 9.0f, 0.0f); glVertex3f(1.0f, 10.0f, 0.0f); glEnd(); } } I am using glutTimerFunc to wait a small amount of time to display a collision sprite before I black out the sprite. unfortunately my code only blacks out the said sprite without drawing the collision sprite, I have done a great deal of research on the glutTimerFunc and  animation.
  • Advertisement
  • Popular Now

  • Forum Statistics

    • Total Topics
      631392
    • Total Posts
      2999742
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!