Last active
February 8, 2019 15:14
-
-
Save cortical-iv/7e8dd7af5123475816f7a8662b0cd7dd to your computer and use it in GitHub Desktop.
Trying to get luminance_alphamask to work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from direct.showbase.ShowBase import ShowBase | |
from panda3d.core import Texture, CardMaker, TransparencyAttrib | |
import numpy as np | |
#Create texture | |
texSize = 512 | |
frequency = 8 | |
def sin3d(X, freq = 1): | |
return np.sin(X*freq) | |
def sin8bit(X, freq = 1): | |
sin_float = sin3d(X, freq=freq) | |
sin_pos = (sin_float+1)*127.5; #from 0-255 | |
return np.asarray(sin_pos, dtype = np.uint8) | |
x = np.linspace(0, 2*np.pi, texSize) | |
y = np.linspace(0, 2*np.pi, texSize) | |
X, Y = np.meshgrid(x,y) | |
sinTex = sin8bit(X, freq = frequency); | |
#Create mask | |
bandRadius = 30 | |
leftMask = 255*np.ones((texSize,texSize), dtype=np.uint8) | |
leftMask[:, :texSize//2+bandRadius] = 0 | |
#Try creating luminance_alphamask | |
masked_texture = np.dstack((sinTex, leftMask)) #.reshape(sinTex.shape[0],-1) | |
masked_texture.shape | |
class MyApp(ShowBase): | |
def __init__(self): | |
ShowBase.__init__(self) | |
#CREATE TEXTURE | |
self.sinTexture = Texture('masked_sin') | |
self.sinTexture.setup2dTexture(texSize, texSize, Texture.T_unsigned_byte, Texture.F_luminance_alphamask) | |
self.sinTexture.setRamImage(masked_texture) | |
#CREATE SCENEGRAPH | |
cm = CardMaker('card1') | |
cm.setFrameFullscreenQuad() | |
self.card1 = self.aspect2d.attachNewNode(cm.generate()) | |
self.card1.setTransparency(TransparencyAttrib.MAlpha) #enable transparency | |
#SET TEXTURE STAGES | |
self.card1.setTexture(self.sinTexture) | |
if __name__ == '__main__': | |
app = MyApp() | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment