0 votes

Hello i'm working on a part time project implying a MeshInstance displaying a viewport linked to another camera , this part is going well but i need to display only a part of the texture on my mesh and, in order to achieve this, i need two things.

first i need to locate the area i want (red square on picture bellow) second i need to take the corresponding part of the texture and then display it on my mesh.

green triangle is the player looking at my MeshInstance
the yellow one is the second camera providing a viewport texture
https://imagizer.imageshack.com/img923/4710/Y1DXU0.png

here is my actual result (red square was added in paint)

enter image description here
and here is what i want
enter image description here

i achieved this result (picture one) by using this shader but im stuck with the next step

  shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_lambert_wrap,specular_schlick_ggx;
//------------------------------------------------------
uniform vec4 albedo : hint_color;
uniform sampler2D texture_albedo : hint_albedo;
//------------------------------------------------------

uniform float specular;
uniform float metallic;
uniform float roughness : hint_range(0,1);
uniform float point_size : hint_range(0,128);
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
uniform vec3 uv2_scale;
uniform vec3 uv2_offset;


uniform float cutoffx : hint_range(-10,10);
uniform float cutoffy : hint_range(-10,10);

// i trie things

//maybe
varying vec4 vert; 
varying vec2 base_uv;
//----------------

void vertex() {
    base_uv=UV;
    UV=UV*uv1_scale.xy+uv1_offset.xy;
    vert= vec4(VERTEX, 1.0);

    vert = MODELVIEW_MATRIX * vert;

    vert = PROJECTION_MATRIX * vert;

    POSITION = vert;
}

void fragment() {

    vec4 albedo_tex = texture(texture_albedo,UV);
    ALBEDO = albedo.rgb * albedo_tex.rgb;
    METALLIC = metallic;
    ROUGHNESS = roughness;
    SPECULAR = specular;
}
asked Apr 5 in Engine by sataran (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.