This commit is contained in:
@@ -971,6 +971,110 @@ bool renderer_init(SDL_Window *window_) {
|
||||
wgpuShaderModuleRelease(shader);
|
||||
}
|
||||
|
||||
{ // Tree
|
||||
const char shader_source[] = {
|
||||
#embed "shaders/wgsl/tree.wgsl"
|
||||
};
|
||||
|
||||
WGPUShaderModule shader = wgpuDeviceCreateShaderModule(device, &(WGPUShaderModuleDescriptor){
|
||||
.nextInChain = (WGPUChainedStruct *)&(WGPUShaderSourceWGSL){
|
||||
.chain = { .next = NULL, .sType = WGPUSType_ShaderSourceWGSL },
|
||||
.code = { .data = shader_source, .length = SDL_arraysize(shader_source) },
|
||||
},
|
||||
.label = { .data = "tree shader", .length = WGPU_STRLEN }
|
||||
});
|
||||
|
||||
shaders[R_SHADER_TREE] = wgpuDeviceCreateRenderPipeline(device, &(WGPURenderPipelineDescriptor){
|
||||
.label = { .data = "tree render_pipeline", .length = WGPU_STRLEN },
|
||||
|
||||
.layout = wgpuDeviceCreatePipelineLayout(device, &(WGPUPipelineLayoutDescriptor){
|
||||
.label = { .data = "tree pipeline_layout", .length = WGPU_STRLEN },
|
||||
.bindGroupLayoutCount = 4,
|
||||
.bindGroupLayouts = (WGPUBindGroupLayout[]){
|
||||
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
|
||||
.entryCount = 0,
|
||||
.entries = (WGPUBindGroupLayoutEntry[]){},
|
||||
}),
|
||||
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
|
||||
.entryCount = 2,
|
||||
.entries = (WGPUBindGroupLayoutEntry[]){
|
||||
{ .binding = 0, .visibility = WGPUShaderStage_Vertex, .buffer = { .type = WGPUBufferBindingType_Uniform } },
|
||||
{ .binding = 1, .visibility = WGPUShaderStage_Vertex, .buffer = { .type = WGPUBufferBindingType_Uniform } },
|
||||
},
|
||||
}),
|
||||
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
|
||||
.entryCount = 3,
|
||||
.entries = (WGPUBindGroupLayoutEntry[]){
|
||||
{ .binding = 0, .visibility = WGPUShaderStage_Fragment, .texture = { .sampleType = WGPUTextureSampleType_Float, .viewDimension = WGPUTextureViewDimension_2D } },
|
||||
{ .binding = 1, .visibility = WGPUShaderStage_Fragment, .sampler = { .type = WGPUSamplerBindingType_Filtering } },
|
||||
{ .binding = 2, .visibility = WGPUShaderStage_Fragment, .buffer = { .type = WGPUBufferBindingType_ReadOnlyStorage } },
|
||||
},
|
||||
}),
|
||||
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
|
||||
.entryCount = 1,
|
||||
.entries = (WGPUBindGroupLayoutEntry[]){
|
||||
{ .binding = 0, .visibility = WGPUShaderStage_Fragment, .buffer = { .type = WGPUBufferBindingType_Uniform } },
|
||||
},
|
||||
}),
|
||||
},
|
||||
}),
|
||||
|
||||
.vertex = {
|
||||
.module = shader,
|
||||
.entryPoint = { .data = "main_vertex", .length = WGPU_STRLEN },
|
||||
.constantCount = 0,
|
||||
.constants = NULL,
|
||||
.bufferCount = 1,
|
||||
.buffers = (WGPUVertexBufferLayout[]){
|
||||
{
|
||||
.stepMode = WGPUVertexStepMode_Instance,
|
||||
.arrayStride = 12,
|
||||
.attributeCount = 2,
|
||||
.attributes = (WGPUVertexAttribute[]){
|
||||
{
|
||||
.format = WGPUVertexFormat_Uint32x2,
|
||||
.offset = 0,
|
||||
.shaderLocation = 0,
|
||||
},
|
||||
{
|
||||
.format = WGPUVertexFormat_Uint32,
|
||||
.offset = 8,
|
||||
.shaderLocation = 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
.primitive = {
|
||||
.topology = WGPUPrimitiveTopology_TriangleList,
|
||||
.stripIndexFormat = WGPUIndexFormat_Undefined,
|
||||
.frontFace = WGPUFrontFace_CCW,
|
||||
.cullMode = WGPUCullMode_Back,
|
||||
.unclippedDepth = false,
|
||||
},
|
||||
|
||||
.depthStencil = NULL,
|
||||
|
||||
.multisample = {
|
||||
.count = 4,
|
||||
.mask = ~0u,
|
||||
.alphaToCoverageEnabled = false,
|
||||
},
|
||||
|
||||
.fragment = &(WGPUFragmentState){
|
||||
.module = shader,
|
||||
.entryPoint = { .data = "main_fragment", .length = WGPU_STRLEN },
|
||||
.constantCount = 0,
|
||||
.constants = NULL,
|
||||
.targetCount = 1,
|
||||
.targets = &color_target_state,
|
||||
},
|
||||
});
|
||||
|
||||
wgpuShaderModuleRelease(shader);
|
||||
}
|
||||
|
||||
{ // Grid
|
||||
const char shader_source[] = {
|
||||
#embed "shaders/wgsl/grid.wgsl"
|
||||
|
||||
Reference in New Issue
Block a user