Passing a cubemap to a shader
Asked Answered
W

3

0

I have a shader that takes in a cube map. I was trying to pass the cubemap to the shader with this code here, but it still displays the old one.

public override void _Ready()
{
    CubeMap tex = new CubeMap();
    Image SideLeft =   new Image();
    Image SideRight =  new Image();
    Image SideBottom = new Image();
    Image SideTop =    new Image();
    Image SideFront =  new Image();
    Image SideBack =   new Image();

    SideLeft.Create(   100, 100, false, Image.Format.Rgb8);
    SideRight.Create(  100, 100, false, Image.Format.Rgb8);
    SideBottom.Create( 100, 100, false, Image.Format.Rgb8);
    SideTop.Create(    100, 100, false, Image.Format.Rgb8);
    SideFront.Create(  100, 100, false, Image.Format.Rgb8);
    SideBack.Create(   100, 100, false, Image.Format.Rgb8);

    tex.SetSide(Godot.CubeMap.Side.Left,   SideLeft);
    tex.SetSide(Godot.CubeMap.Side.Right,  SideRight);
    tex.SetSide(Godot.CubeMap.Side.Bottom, SideBottom);
    tex.SetSide(Godot.CubeMap.Side.Top,    SideTop);
    tex.SetSide(Godot.CubeMap.Side.Front,  SideFront);
    tex.SetSide(Godot.CubeMap.Side.Back,   SideBack);


    (GetActiveMaterial(0) as ShaderMaterial).SetShaderParam("World", tex);
}
Withdrawal answered 13/6, 2022 at 15:12 Comment(0)
B
0

Might want to try making a unique copy of the material, updating that then assigning it as a replacement. Not sure but I seem to recall someone having a similar issue where that worked for them I think.

Beora answered 13/6, 2022 at 20:38 Comment(0)
M
0

I think samplers in shaders are references. So you can update a texture value in code without reassigning the shader param. In your case, it looks like you are creating a temporary texture and then assigning the address to the texture to the shader, but as soon as that scope exits (on the next line) the texture may be gone. So it is better to create class member (say called cubeTex) and then call SetSide in the update function (without creating a new CubeMap or Image and without reassigning the shader param). At least I think that should work, it's hard to say for sure.

Miles answered 13/6, 2022 at 21:19 Comment(0)
W
0

Miles I attempted this. Nothing changed. I really don't think I expected anything to change though, because the original issue was that it never even changed the non-blank texture I already had on there. Thanks for the attempt though 🙂

Withdrawal answered 14/6, 2022 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.