2023-04-05 19:27:06 +02:00
|
|
|
|
|
|
|
|
class MakeVoxel {
|
|
|
|
|
|
2024-01-17 18:53:31 +01:00
|
|
|
///if arm_voxels
|
2024-02-05 20:57:20 +01:00
|
|
|
static run = (data: shader_context_t) => {
|
2024-03-07 20:37:30 +01:00
|
|
|
let structure: vertex_struct_t = g4_vertex_struct_create();
|
2024-02-10 19:26:53 +01:00
|
|
|
g4_vertex_struct_add(structure, "pos", vertex_data_t.I16_4X_NORM);
|
|
|
|
|
g4_vertex_struct_add(structure, "nor", vertex_data_t.I16_2X_NORM);
|
|
|
|
|
g4_vertex_struct_add(structure, "tex", vertex_data_t.I16_2X_NORM);
|
2023-04-05 19:27:06 +02:00
|
|
|
|
2024-03-07 20:37:30 +01:00
|
|
|
let pipeState: pipeline_t = data._.pipe_state;
|
2024-02-07 21:39:06 +01:00
|
|
|
pipeState.input_layout = [structure];
|
2024-03-07 20:37:30 +01:00
|
|
|
data.vertex_elements = [
|
|
|
|
|
{name: "pos", data: "short4norm"},
|
|
|
|
|
{name: "nor", data: "short2norm"},
|
|
|
|
|
{name: "tex", data: "short2norm"}
|
|
|
|
|
];
|
2023-04-05 19:27:06 +02:00
|
|
|
|
2024-01-17 18:53:31 +01:00
|
|
|
// ///if arm_skin
|
2024-03-07 20:37:30 +01:00
|
|
|
// let is_mesh: bool = Context.raw.object.constructor == mesh_object_t;
|
|
|
|
|
// let skin: bool = is_mesh && cast(Context.raw.object, mesh_object_t).data.geom.bones != null;
|
2023-04-05 19:27:06 +02:00
|
|
|
// if (skin) {
|
2024-02-03 16:07:49 +01:00
|
|
|
// VertexStructure.add(structure, "bone", VertexData.I16_4X_Normalized);
|
|
|
|
|
// VertexStructure.add(structure, "weight", VertexData.I16_4X_Normalized);
|
2023-04-05 19:27:06 +02:00
|
|
|
// data.raw.vertex_elements.push({ name: "bone", data: 'short4norm' });
|
|
|
|
|
// data.raw.vertex_elements.push({ name: "weight", data: 'short4norm' });
|
|
|
|
|
// }
|
2024-01-17 18:53:31 +01:00
|
|
|
// ///end
|
|
|
|
|
|
2024-03-07 20:37:30 +01:00
|
|
|
let ds: f32 = MakeMaterial.get_displace_strength();
|
|
|
|
|
pipeState.vertex_shader = g4_shader_from_source(MakeVoxel.voxel_source(), shader_type_t.VERTEX);
|
2023-04-05 19:27:06 +02:00
|
|
|
|
2024-02-10 19:26:53 +01:00
|
|
|
g4_pipeline_compile(pipeState);
|
2024-02-12 17:56:57 +01:00
|
|
|
data.constants = [{ name: "W", type: "mat4", link: "_world_matrix" }, { name: "N", type: "mat3", link: "_normal_matrix" }];
|
2024-03-01 13:06:16 +01:00
|
|
|
data._.constants = [g4_pipeline_get_const_loc(pipeState, "W"), g4_pipeline_get_const_loc(pipeState, "N")];
|
|
|
|
|
data.texture_units = [{ name: "texpaint_pack" }, { name: "voxels", image_uniform: true }];
|
|
|
|
|
data._.tex_units = [g4_pipeline_get_tex_unit(pipeState, "texpaint_pack"), g4_pipeline_get_tex_unit(pipeState, "voxels")];
|
2024-01-17 18:53:31 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-07 20:37:30 +01:00
|
|
|
static voxel_source = (): string => {
|
2024-01-17 18:53:31 +01:00
|
|
|
///if krom_direct3d11
|
|
|
|
|
return `#define vec3 float3
|
2023-04-05 19:27:06 +02:00
|
|
|
uniform float4x4 W;
|
|
|
|
|
uniform float3x3 N;
|
|
|
|
|
Texture2D<float4> texpaint_pack;
|
|
|
|
|
SamplerState _texpaint_pack_sampler;
|
|
|
|
|
struct SPIRV_Cross_Input { float4 pos : TEXCOORD1; float2 nor : TEXCOORD0; float2 tex : TEXCOORD2; };
|
|
|
|
|
struct SPIRV_Cross_Output { float4 svpos : SV_POSITION; };
|
|
|
|
|
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) {
|
|
|
|
|
SPIRV_Cross_Output stage_output;
|
|
|
|
|
" + MakeMaterial.voxelgiHalfExtents() + "
|
|
|
|
|
stage_output.svpos.xyz = mul(float4(stage_input.pos.xyz, 1.0), W).xyz / voxelgiHalfExtents.xxx;
|
|
|
|
|
float3 wnormal = normalize(mul(float3(stage_input.nor.xy, stage_input.pos.w), N));
|
|
|
|
|
float height = texpaint_pack.SampleLevel(_texpaint_pack_sampler, stage_input.tex, 0.0).a;
|
|
|
|
|
stage_output.svpos.xyz += wnormal * height.xxx * float3(" + ds + "," + ds + "," + ds + ");
|
|
|
|
|
stage_output.svpos.w = 1.0;
|
|
|
|
|
return stage_output;
|
2024-01-17 18:53:31 +01:00
|
|
|
}`;
|
|
|
|
|
///else
|
|
|
|
|
return `#version 450
|
2023-04-05 19:27:06 +02:00
|
|
|
in vec4 pos;
|
|
|
|
|
in vec2 nor;
|
|
|
|
|
in vec2 tex;
|
|
|
|
|
out vec3 voxpositionGeom;
|
|
|
|
|
uniform mat4 W;
|
|
|
|
|
uniform mat3 N;
|
|
|
|
|
uniform sampler2D texpaint_pack;
|
|
|
|
|
void main() {
|
|
|
|
|
" + MakeMaterial.voxelgiHalfExtents() + "
|
|
|
|
|
voxpositionGeom = vec3(W * vec4(pos.xyz, 1.0)) / voxelgiHalfExtents;
|
|
|
|
|
vec3 wnormal = normalize(N * vec3(nor.xy, pos.w));
|
|
|
|
|
float height = textureLod(texpaint_pack, tex, 0.0).a;
|
|
|
|
|
voxpositionGeom += wnormal * vec3(height) * vec3(" + ds + ");
|
2024-01-17 18:53:31 +01:00
|
|
|
}`;
|
|
|
|
|
///end
|
2023-04-05 19:27:06 +02:00
|
|
|
}
|
2024-01-17 18:53:31 +01:00
|
|
|
///end
|
2023-04-05 19:27:06 +02:00
|
|
|
}
|