Mipmaps

hello,

is this how I generate mipmaps with panda ?

PT(Texture) myTex;
myTex = new Texture();
myTex->load(*pPNMImage);
myTex->set_magfilter(Texture::FT_linear);
myTex->set_minfilter(Texture::FT_linear_mipmap_linear);
myTex->set_wrap_u(Texture::WM_repeat);
myTex->set_wrap_v(Texture::WM_repeat);
myTex->set_wrap_w(Texture::WM_repeat);
myTex->generate_ram_mipmap_images();

That looks like the right idea, but there’s no need to call generate_ram_mipmap_images() explicitly, unless you want to extract the mipmap images right away. If your goal is just to render the texture with mipmapping, the mipmaps are generated automatically when the texture is rendered.

David

hmm

I am a bit out of ideas then…

I’m porting an openGL water shader over to panda3D.

The difference in texture quality is immense.
see for yourself

The shader is pretty much the same and I use the same textures for both programs.
Yet the panda version has massive flaws in the texture (loads of square artefacts).

Any suggestions why that could be ?

I have other problems with the panda version but for those I might open other threads later on.

:confused:

I don’t know; but it doesn’t look like a mipmapping issue to me.

David

Maybe your light calculation needs normalization somewhere, I had similar square effect when my normals weren’t properly normalized.

I’ve tried to switch over to directX (from openGL) and now I get this.

Known pipe types:
  wdxGraphicsPipe9
(all display modules loaded.)
Loading Skybox/Skybox.egg
PandaNode render S:(CullFaceAttrib RescaleNormalAttrib ShadeModelAttrib)
  PandaNode camera_group
    Camera camera ( PerspectiveLens )
      PerspectiveLens fov = 39.3201 30
  ModelRoot Skybox.egg S:(CullBinAttrib DepthWriteAttrib)
    PandaNode
      GeomNode Left (1 geoms: S:(TextureAttrib)) T:m(pos 0 0 -50)
      GeomNode Up (1 geoms: S:(TextureAttrib)) T:m(pos 0 0 -50)
      GeomNode Front (1 geoms: S:(TextureAttrib)) T:m(pos 0 0 -50)
      GeomNode Right (1 geoms: S:(TextureAttrib)) T:m(pos 0 0 -50)
      GeomNode Back (1 geoms: S:(TextureAttrib)) T:m(pos 0 0 -50)
      GeomNode Down (1 geoms: S:(TextureAttrib)) T:m(pos 0 0 -50)
  PandaNode Ocean S:(ShaderAttrib)
    GeomNode GridNode (1 geoms)
Assertion failed: type != ST_none || !_filename->_shared.empty() at line 24 of c
:\panda3d\panda3d\pandadebug\include\shader.I
:display:gsg:dxgsg9(error): pixel shader cgD3D9LoadProgram failed  at (c:\panda3
d\panda3d\panda\src\dxgsg9\dxShaderContext9.cxx:95), hr=D3DXERR_INVALIDDATA: Inv
alid data
:display:gsg:dxgsg9(error):   CG ERROR: CG ERROR : Unknown error.

any ideas what that means ?

also is it possible that I set the mipmaps myself somehow ? The openGL example I am following is calculating the mipmaps itself and setting more than one while the “notify-level-glgsg debug” tells me that panda only generates 1 mipmap level.

Were you trying to use a GLSL shader in DirectX? Because that’s not possible, you’ll need to use a Cg shader in DirectX.

it’s a Cg shader I’m using

How are you loading the shader in the code?

sorry for the delayed answer - I was ill this weekend.

this is how I load the shader

PT(Shader) oceanShader = Shader::load(Shader::SL_Cg, "Shaders/vpWaterDM.sha", "Shaders/fpWaterDM.sha");
gOceanNodePath.set_shader(oceanShader);

any other idea what this error could mean ?
I’ll try to simplyfy the shader and see if it is shader “content” related.

here some errors I get when trying this in directX (works with openGL) on another machine.

Known pipe types:
  wdxGraphicsPipe9
(all display modules loaded.)
PandaNode render S:(CullFaceAttrib RescaleNormalAttrib ShadeModelAttrib)
  PandaNode camera_group
    Camera camera ( PerspectiveLens )
      PerspectiveLens fov = 39.3201 30
  PandaNode Ocean
    GeomNode GridNode (1 geoms) S:(ShaderAttrib)
Assertion failed: type != ST_none || !_filename->_shared.empty() at line 24 of c
:\panda3d\panda3d\pandadebug\include\shader.I
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "
:gobj(error): Shaders/vpWaterDM.sha: (26) : error C5201: invalid internal functi
on declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/vpWaterDM.sha: "

the code it refers to on line 26 of vpWaterDM.sha

is this

float4 tAB0 = tex2Dbias(tex, t);

In my config.prc

I define

load-display pandadx9
basic-shaders-only #f
notify-level-glgsg debug

sync-video #f

notify-output MyLog.txt

(amongst the other standard options)

if I remove that line of the shader then I go back and get this

Known pipe types:
  wdxGraphicsPipe9
(all display modules loaded.)
PandaNode render S:(CullFaceAttrib RescaleNormalAttrib ShadeModelAttrib)
  PandaNode camera_group
    Camera camera ( PerspectiveLens )
      PerspectiveLens fov = 39.3201 30
  PandaNode Ocean
    GeomNode GridNode (1 geoms) S:(ShaderAttrib)
Assertion failed: type != ST_none || !_filename->_shared.empty() at line 24 of c
:\panda3d\panda3d\pandadebug\include\shader.I
:display:gsg:dxgsg9(error): pixel shader cgD3D9LoadProgram failed  at (c:\panda3
d\panda3d\panda\src\dxgsg9\dxShaderContext9.cxx:95), hr=D3DXERR_INVALIDDATA: Inv
alid data
:display:gsg:dxgsg9(error):   CG ERROR: CG ERROR : Unknown error.

I’ll try more stuff now.

Ok so I have substituted the pixel shader with a really simple one and now I just get this assert notification .

Known pipe types:
  wdxGraphicsPipe9
(all display modules loaded.)
PandaNode render S:(CullFaceAttrib RescaleNormalAttrib ShadeModelAttrib)
  PandaNode camera_group
    Camera camera ( PerspectiveLens )
      PerspectiveLens fov = 39.3201 30
  PandaNode Ocean S:(RenderModeAttrib)
    GeomNode GridNode (1 geoms) S:(ShaderAttrib)
Assertion failed: type != ST_none || !_filename->_shared.empty() at line 24 of c
:\panda3d\panda3d\pandadebug\include\shader.I

and the shader output is like this.

which is what I would expect.

I’ll now see if I can isolate which instructions cause the shader to not work.

You should put the vertex program and fragment program in one file. Or, you could keep them in two separate files, and create another shader that just #includes both the vertex and fragment program.

okay I’ll try that - in the meantime here another finding.

WaterColor = lerp(WaterColor,(diffuseL * 0.4 + 0.5), Foam);

causes the CG_ERROR

ok moving the vertex and pixel shader into one file has fixed the assert.

now there is a couple of issues left to sort out.

  1. putting this line in the pixel shader causes the CG_ERROR :
WaterColor = lerp(WaterColor,(diffuseL * 0.4 + 0.5), Foam);

causes

:display:gsg:dxgsg9(error): pixel shader cgD3D9LoadProgram failed  at (c:\panda3
d\panda3d\panda\src\dxgsg9\dxShaderContext9.cxx:95), hr=D3DXERR_INVALIDDATA: Inv
alid data
:display:gsg:dxgsg9(error):   CG ERROR: CG ERROR : Unknown error.
  1. Following code in the vertex shader, causes the shader to not work and show this in the output
float4 tAB0 = tex2Dbias(tex, t);

causes

:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "
:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "
:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "
:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "
:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "
:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "
:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "
:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "
:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "
:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "
:gobj(error): Shaders/waterShader.sha: (26) : error C5201: invalid internal func
tion declaration for "float4 tex2Dbias(sampler2D, float4)
:gobj(error): Shaders/waterShader.sha: "

I’m not sure. There might be a bug somewhere. I don’t have access to a Windows machine to try it myself, though.

Have you tried the OpenGL renderer? In general, you should get more reliable results there.

yeah the openGL version “works” (with bad results though) but I want to use PIX to debug my shader (and PIX only works with DirectX). I am getting very strange results with panda3D … although I am trying to use the same code + shader. (See picture above of 2 different oceans)

Is there anyone else who would be looking at this DirectX issue ?

It’s kind of a breaker for me :frowning: