October 18, 2019, 06:31:43 PM

Author Topic: Is it possible to apply a shader without unloading textures?  (Read 131 times)

Offline Kippykip

  • Jr. Member
  • **
  • Posts: 98
    • Kippykip Forums!
Is it possible to apply a shader without unloading textures?
« on: October 01, 2019, 01:28:04 PM »
Hey everyone! I was wondering if it was possible to apply a shader to a mesh/model without unloading the textures. I haven't really played with shaders much in OpenB3D other than a greyscale filter on a RenderToTexture mesh that's in front of the camera.

For example I ported a PS1 shaky vertex GLSL shader from a Unity demo project, and used ShadeMesh whenever I used LoadAnimMesh it'll either appear just plain white, or glitch into random colours as it seems to collide a bit with Max2D functions. Similar things happen if I use the PixelLight shaders included with the examples.
If someone knows how to use shaders on meshes properly in OpenB3D it would be awesome if you could explain the process. :)
Code: [Select]
Local PSXShader:TShader = LoadShader("", "ps1.vert.glsl", default.frag.glsl)Then use either
Code: [Select]
ShadeMesh(Container.Model, PSXShader)
ShadeEntity(Container.Model, PSXShader)

ps1.vert.glsl
Code: [Select]
varying vec4 vertColor;
void main() // all vertex shaders define a main() function
{
vec4 snapToPixel = gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 vertex = snapToPixel;
vertex.xyz = snapToPixel.xyz/snapToPixel.w;
vertex.x = floor(160*vertex.x)/160;
vertex.y = floor(120*vertex.y)/120;
vertex.xyz*=snapToPixel.w;
gl_Position = vertex;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vertColor = gl_Color;
}

default.frag.glsl
Code: [Select]
// https://github.com/chudooder/entanglement/blob/master/shaders

varying vec4 vertColor;
uniform sampler2D texture0;

void main() {
    gl_FragColor = texture2D(texture0, gl_TexCoord[0].st)*vertColor;
}

Here's a video showing what's happening: