0 votes

Hi, I'm trying to pass a viewport texture to my shader(spatial). I've try things like set resource local to scene, viewport update mode to 'always' but it doesnt help. I know there is a way to do this with code: turn viewport texture to ImageTexture and pass to shader. But it's bad to do this every frame. Question is the thing works fine with a standard SpatialMaterial so what do i have to add to my shader to get it?

Here is the shader code:

shader_type spatial;

uniform sampler2D albedo : hint_albedo;
uniform sampler2D normalmap : hint_normal;

uniform sampler2D heightmap;
uniform vec2 size = vec2(512, 512);
uniform float amplitude = 15.0;

float get_height(vec2 pos) {
    pos -= size/2.0;
    pos /= size;
    return amplitude * texture(heightmap, pos).r;

void vertex() {
    VERTEX.y = get_height(VERTEX.xz);

    TANGENT = normalize(vec3(1.0, get_height(VERTEX.xz + vec2(1.0, 0.0)) - VERTEX.y, 0.0));
    BINORMAL = normalize(vec3(0.0, get_height(VERTEX.xz + vec2(0.0, 1.0)) - VERTEX.y, 1.0));


void fragment() {
    ALBEDO = texture(albedo, UV * 10.0).rgb;
    NORMALMAP = texture(normalmap, UV * 10.0).rgb;
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.